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

Commit e23a0e0

Browse files
authored
Add AWS SigV4 auth support (#25)
1 parent d2fbe45 commit e23a0e0

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

datasource.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ type JSONData struct {
8585
ClientEmail string `json:"clientEmail,omitempty"`
8686
DefaultProject string `json:"defaultProject,omitempty"`
8787
TokenURI string `json:"tokenUri,omitempty"`
88+
89+
// Used by Prometheus and Elasticsearch
90+
SigV4AssumeRoleArn string `json:"sigV4AssumeRoleArn,omitempty"`
91+
SigV4Auth bool `json:"sigV4Auth,omitempty"`
92+
SigV4AuthType string `json:"sigV4AuthType,omitempty"`
93+
SigV4ExternalID string `json:"sigV4ExternalID,omitempty"`
94+
SigV4Profile string `json:"sigV4Profile,omitempty"`
95+
SigV4Region string `json:"sigV4Region,omitempty"`
8896
}
8997

9098
// SecureJSONData is a representation of the datasource `secureJsonData` property
@@ -102,6 +110,10 @@ type SecureJSONData struct {
102110

103111
// Used by Stackdriver
104112
PrivateKey string `json:"privateKey,omitempty"`
113+
114+
// Used by Prometheus and Elasticsearch
115+
SigV4AccessKey string `json:"sigV4AccessKey,omitempty"`
116+
SigV4SecretKey string `json:"sigV4SecretKey,omitempty"`
105117
}
106118

107119
// NewDataSource creates a new Grafana data source.

datasource_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,40 @@ func TestNewPrometheusDataSource(t *testing.T) {
7474
}
7575
}
7676

77+
func TestNewPrometheusSigV4DataSource(t *testing.T) {
78+
server, client := gapiTestTools(t, 200, createdDataSourceJSON)
79+
defer server.Close()
80+
81+
ds := &DataSource{
82+
Name: "sigv4_prometheus",
83+
Type: "prometheus",
84+
URL: "http://some-url.com",
85+
Access: "access",
86+
IsDefault: true,
87+
JSONData: JSONData{
88+
HTTPMethod: "POST",
89+
SigV4Auth: true,
90+
SigV4AuthType: "keys",
91+
SigV4Region: "us-east-1",
92+
},
93+
SecureJSONData: SecureJSONData{
94+
SigV4AccessKey: "123",
95+
SigV4SecretKey: "456",
96+
},
97+
}
98+
99+
created, err := client.NewDataSource(ds)
100+
if err != nil {
101+
t.Fatal(err)
102+
}
103+
104+
t.Log(pretty.PrettyFormat(created))
105+
106+
if created != 1 {
107+
t.Error("datasource creation response should return the created datasource ID")
108+
}
109+
}
110+
77111
func TestNewElasticsearchDataSource(t *testing.T) {
78112
server, client := gapiTestTools(t, 200, createdDataSourceJSON)
79113
defer server.Close()

0 commit comments

Comments
 (0)