Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 78f337a

Browse files
aymericDDAymeric
andauthored
feat: add azure datasource fields (#70)
Co-authored-by: Aymeric <aymeric.daurelle@cdiscount.com>
1 parent 5b41341 commit 78f337a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

datasource.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ type JSONData struct {
178178
DefaultBucket string `json:"defaultBucket,omitempty"`
179179
Organization string `json:"organization,omitempty"`
180180
Version string `json:"version,omitempty"`
181+
182+
// Used by Azure Monitor
183+
AzureLogAnalyticsSameAs bool `json:"azureLogAnalyticsSameAs,omitempty"`
184+
ClientID string `json:"clientId,omitempty"`
185+
CloudName string `json:"cloudName,omitempty"`
186+
LogAnalyticsClientID string `json:"logAnalyticsClientId,omitempty"`
187+
LogAnalyticsDefaultWorkspace string `json:"logAnalyticsDefaultWorkspace,omitempty"`
188+
LogAnalyticsTenantID string `json:"logAnalyticsTenantId,omitempty"`
189+
SubscriptionID string `json:"subscriptionId,omitempty"`
190+
TenantID string `json:"tenantId,omitempty"`
181191
}
182192

183193
// Required to avoid recursion during (un)marshal
@@ -257,6 +267,9 @@ type SecureJSONData struct {
257267

258268
// Used by Sentry
259269
AuthToken string `json:"authToken,omitempty"`
270+
271+
// Used by Azure Monitor
272+
ClientSecret string `json:"clientSecret,omitempty"`
260273
}
261274

262275
// Required to avoid recursion during unmarshal

datasource_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,40 @@ func TestNewOpenTSDBDataSource(t *testing.T) {
198198
t.Error("datasource creation response should return the created datasource ID")
199199
}
200200
}
201+
202+
func TestNewAzureDataSource(t *testing.T) {
203+
server, client := gapiTestTools(t, 200, createdDataSourceJSON)
204+
defer server.Close()
205+
206+
ds := &DataSource{
207+
Name: "foo_azure",
208+
Type: "grafana-azure-monitor-datasource",
209+
URL: "http://some-url.com",
210+
Access: "access",
211+
IsDefault: true,
212+
JSONData: JSONData{
213+
AzureLogAnalyticsSameAs: true,
214+
ClientID: "lorem-ipsum",
215+
CloudName: "azuremonitor",
216+
LogAnalyticsClientID: "lorem-ipsum",
217+
LogAnalyticsDefaultWorkspace: "lorem-ipsum",
218+
LogAnalyticsTenantID: "lorem-ipsum",
219+
SubscriptionID: "lorem-ipsum",
220+
TenantID: "lorem-ipsum",
221+
},
222+
SecureJSONData: SecureJSONData{
223+
ClientSecret: "alksdjaslkdjkslajdkj.asdlkjaksdjlkajsdlkjsaldj==",
224+
},
225+
}
226+
227+
created, err := client.NewDataSource(ds)
228+
if err != nil {
229+
t.Fatal(err)
230+
}
231+
232+
t.Log(pretty.PrettyFormat(created))
233+
234+
if created != 1 {
235+
t.Error("datasource creation response should return the created datasource ID")
236+
}
237+
}

0 commit comments

Comments
 (0)