forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_api_key.go
44 lines (36 loc) · 1 KB
/
cloud_api_key.go
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
package gapi
import (
"encoding/json"
"fmt"
)
type CreateCloudAPIKeyInput struct {
Name string `json:"name"`
Role string `json:"role"`
}
type ListCloudAPIKeysOutput struct {
Items []*CloudAPIKey
}
type CloudAPIKey struct {
ID int
Name string
Role string
Token string
Expiration string
}
func (c *Client) CreateCloudAPIKey(org string, input *CreateCloudAPIKeyInput) (*CloudAPIKey, error) {
resp := CloudAPIKey{}
data, err := json.Marshal(input)
if err != nil {
return nil, err
}
err = c.request("POST", fmt.Sprintf("/api/orgs/%s/api-keys", org), nil, data, &resp)
return &resp, err
}
func (c *Client) ListCloudAPIKeys(org string) (*ListCloudAPIKeysOutput, error) {
resp := &ListCloudAPIKeysOutput{}
err := c.request("GET", fmt.Sprintf("/api/orgs/%s/api-keys", org), nil, nil, &resp)
return resp, err
}
func (c *Client) DeleteCloudAPIKey(org string, keyName string) error {
return c.request("DELETE", fmt.Sprintf("/api/orgs/%s/api-keys/%s", org, keyName), nil, nil, nil)
}