Skip to content

Commit ecc1da7

Browse files
authored
Datasource: add delete datasource by name method (grafana#122)
add delete datasource by name API. [API-doc](https://grafana.com/docs/grafana/v9.0/developers/http_api/data_source/#delete-an-existing-data-source-by-name). Signed-off-by: guykomari <[email protected]> Signed-off-by: guykomari <[email protected]>
1 parent 96f0c5b commit ecc1da7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

datasource.go

+7
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,10 @@ func (c *Client) DeleteDataSource(id int64) error {
132132

133133
return c.request("DELETE", path, nil, nil, nil)
134134
}
135+
136+
// DeleteDataSourceByName deletes the Grafana data source whose NAME it's passed.
137+
func (c *Client) DeleteDataSourceByName(name string) error {
138+
path := fmt.Sprintf("/api/datasources/name/%s", name)
139+
140+
return c.request("DELETE", path, nil, nil, nil)
141+
}

datasource_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,13 @@ func TestDataSourceIDByName(t *testing.T) {
317317
t.Error("Not correctly parsing returned datasources.")
318318
}
319319
}
320+
321+
func TestDeleteDataSourceByName(t *testing.T) {
322+
server, client := gapiTestTools(t, 200, "")
323+
defer server.Close()
324+
325+
err := client.DeleteDataSourceByName("foo")
326+
if err != nil {
327+
t.Fatal(err)
328+
}
329+
}

0 commit comments

Comments
 (0)