forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloud_access_policy_token.go
91 lines (72 loc) · 2.51 KB
/
cloud_access_policy_token.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package gapi
import (
"encoding/json"
"fmt"
"net/url"
"time"
)
type CreateCloudAccessPolicyTokenInput struct {
AccessPolicyID string `json:"accessPolicyId"`
Name string `json:"name"`
DisplayName string `json:"displayName,omitempty"`
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
}
type UpdateCloudAccessPolicyTokenInput struct {
DisplayName string `json:"displayName"`
}
type CloudAccessPolicyToken struct {
ID string `json:"id"`
AccessPolicyID string `json:"accessPolicyId"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
ExpiresAt *time.Time `json:"expiresAt"`
FirstUsedAt time.Time `json:"firstUsedAt"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt *time.Time `json:"updatedAt"`
Token string `json:"token,omitempty"` // Only returned when creating a token.
}
type CloudAccessPolicyTokenItems struct {
Items []*CloudAccessPolicyToken `json:"items"`
}
func (c *Client) CloudAccessPolicyTokens(region, accessPolicyID string) (CloudAccessPolicyTokenItems, error) {
tokens := CloudAccessPolicyTokenItems{}
err := c.request("GET", "/api/v1/tokens", url.Values{
"region": []string{region},
"accessPolicyId": []string{accessPolicyID},
}, nil, &tokens)
return tokens, err
}
func (c *Client) CloudAccessPolicyTokenByID(region, id string) (CloudAccessPolicyToken, error) {
token := CloudAccessPolicyToken{}
err := c.request("GET", fmt.Sprintf("/api/v1/tokens/%s", id), url.Values{
"region": []string{region},
}, nil, &token)
return token, err
}
func (c *Client) CreateCloudAccessPolicyToken(region string, input CreateCloudAccessPolicyTokenInput) (CloudAccessPolicyToken, error) {
token := CloudAccessPolicyToken{}
data, err := json.Marshal(input)
if err != nil {
return token, err
}
err = c.request("POST", "/api/v1/tokens", url.Values{
"region": []string{region},
}, data, &token)
return token, err
}
func (c *Client) UpdateCloudAccessPolicyToken(region, id string, input UpdateCloudAccessPolicyTokenInput) (CloudAccessPolicyToken, error) {
token := CloudAccessPolicyToken{}
data, err := json.Marshal(input)
if err != nil {
return token, err
}
err = c.request("POST", fmt.Sprintf("/api/v1/tokens/%s", id), url.Values{
"region": []string{region},
}, data, &token)
return token, err
}
func (c *Client) DeleteCloudAccessPolicyToken(region, id string) error {
return c.request("DELETE", fmt.Sprintf("/api/v1/tokens/%s", id), url.Values{
"region": []string{region},
}, nil, nil)
}