-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataSource.go
More file actions
64 lines (53 loc) · 1.3 KB
/
dataSource.go
File metadata and controls
64 lines (53 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"log"
"github.com/dghubble/sling"
)
type createDataSourceReq struct {
Name string `json:"name"`
Type string `json:"type"`
Access string `json:"access"`
JSONData jsonData `json:"jsonData"`
SecureJSONData secureJSONData `json:"secureJsonData"`
}
type jsonData struct {
AuthType string `json:"authType"`
DefaultRegion string `json:"defaultRegion"`
}
type secureJSONData struct {
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
}
type createDataSourceResp struct {
ID int `json:"id"`
Message string `json:"message"`
Name string `json:"name"`
}
func createDataSource(slingClient *sling.Sling, accessKey string, secretKey string) error {
path := "/api/datasources"
body := &createDataSourceReq{
Name: "CloudWatch",
Type: "cloudwatch",
Access: "proxy",
JSONData: jsonData{
AuthType: "keys",
DefaultRegion: "us-west-1",
},
SecureJSONData: secureJSONData{
AccessKey: accessKey,
SecretKey: secretKey,
},
}
var data createDataSourceResp
var err2 error
_, err := slingClient.New().Post(path).BodyJSON(body).Receive(&data, err2)
if err == nil {
err = err2
}
if err != nil {
log.Print(err)
return err
}
log.Print(data.Message)
return nil
}