diff --git a/datasource.go b/datasource.go index a5b40de..523251a 100644 --- a/datasource.go +++ b/datasource.go @@ -31,19 +31,10 @@ type DataSource struct { } // JSONData is a representation of the datasource `jsonData` property -type JSONData struct { - AssumeRoleArn string `json:"assumeRoleArn,omitempty"` - AuthType string `json:"authType,omitempty"` - CustomMetricsNamespaces string `json:"customMetricsNamespaces,omitempty"` - DefaultRegion string `json:"defaultRegion,omitempty"` - TlsSkipVerify bool `json:"tlsSkipVerify,omitempty"` -} +type JSONData map[string]interface{} // SecureJSONData is a representation of the datasource `secureJsonData` property -type SecureJSONData struct { - AccessKey string `json:"accessKey,omitempty"` - SecretKey string `json:"secretKey,omitempty"` -} +type SecureJSONData map[string]interface{} func (c *Client) NewDataSource(s *DataSource) (int64, error) { data, err := json.Marshal(s) @@ -97,6 +88,33 @@ func (c *Client) UpdateDataSource(s *DataSource) error { return nil } +func (c *Client) DataSources() ([]DataSource, error) { + datasources := make([]DataSource, 0) + + path := fmt.Sprintf("/api/datasources") + req, err := c.newRequest("GET", path, nil, nil) + if err != nil { + return nil, err + } + + resp, err := c.Do(req) + if err != nil { + return datasources, err + } + if resp.StatusCode != 200 { + return datasources, errors.New(resp.Status) + } + + data, err := ioutil.ReadAll(resp.Body) + if err != nil { + return datasources, err + } + + err = json.Unmarshal(data, &datasources) + + return datasources, err +} + func (c *Client) DataSource(id int64) (*DataSource, error) { path := fmt.Sprintf("/api/datasources/%d", id) req, err := c.newRequest("GET", path, nil, nil) diff --git a/datasource_test.go b/datasource_test.go index c2ee1b7..8bb5640 100644 --- a/datasource_test.go +++ b/datasource_test.go @@ -50,15 +50,15 @@ func TestNewDataSource(t *testing.T) { Access: "access", IsDefault: true, JSONData: JSONData{ - AssumeRoleArn: "arn:aws:iam::123:role/some-role", - AuthType: "keys", - CustomMetricsNamespaces: "SomeNamespace", - DefaultRegion: "us-east-1", - TlsSkipVerify: true, + "assumeRoleArn": "arn:aws:iam::123:role/some-role", + "authType": "keys", + "customMetricsNamespaces": "SomeNamespace", + "defaultRegion": "us-east-1", + "tlsSkipVerify": true, }, SecureJSONData: SecureJSONData{ - AccessKey: "123", - SecretKey: "456", + "accessKey": "123", + "secretKey": "456", }, }