This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
cloud_access_policy.go
102 lines (81 loc) · 2.85 KB
/
cloud_access_policy.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
92
93
94
95
96
97
98
99
100
101
102
package gapi
import (
"encoding/json"
"fmt"
"net/url"
"time"
)
type CloudAccessPolicyLabelPolicy struct {
Selector string `json:"selector"`
}
type CloudAccessPolicyRealm struct {
Type string `json:"type"`
Identifier string `json:"identifier"`
LabelPolicies []CloudAccessPolicyLabelPolicy `json:"labelPolicies"`
}
type CreateCloudAccessPolicyInput struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Scopes []string `json:"scopes"`
Realms []CloudAccessPolicyRealm `json:"realms"`
}
type UpdateCloudAccessPolicyInput struct {
DisplayName string `json:"displayName"`
Scopes []string `json:"scopes"`
Realms []CloudAccessPolicyRealm `json:"realms"`
}
type CloudAccessPolicy struct {
Name string `json:"name"`
DisplayName string `json:"displayName"`
Scopes []string `json:"scopes"`
Realms []CloudAccessPolicyRealm `json:"realms"`
// The following fields are not part of the input, but are returned by the API.
ID string `json:"id"`
OrgID string `json:"orgId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type CloudAccessPolicyItems struct {
Items []*CloudAccessPolicy `json:"items"`
}
func (c *Client) CloudAccessPolicies(region string) (CloudAccessPolicyItems, error) {
policies := CloudAccessPolicyItems{}
err := c.request("GET", "/api/v1/accesspolicies", url.Values{
"region": []string{region},
}, nil, &policies)
return policies, err
}
func (c *Client) CloudAccessPolicyByID(region, id string) (CloudAccessPolicy, error) {
policy := CloudAccessPolicy{}
err := c.request("GET", fmt.Sprintf("/api/v1/accesspolicies/%s", id), url.Values{
"region": []string{region},
}, nil, &policy)
return policy, err
}
func (c *Client) CreateCloudAccessPolicy(region string, input CreateCloudAccessPolicyInput) (CloudAccessPolicy, error) {
result := CloudAccessPolicy{}
data, err := json.Marshal(input)
if err != nil {
return result, err
}
err = c.request("POST", "/api/v1/accesspolicies", url.Values{
"region": []string{region},
}, data, &result)
return result, err
}
func (c *Client) UpdateCloudAccessPolicy(region, id string, input UpdateCloudAccessPolicyInput) (CloudAccessPolicy, error) {
result := CloudAccessPolicy{}
data, err := json.Marshal(input)
if err != nil {
return result, err
}
err = c.request("POST", fmt.Sprintf("/api/v1/accesspolicies/%s", id), url.Values{
"region": []string{region},
}, data, &result)
return result, err
}
func (c *Client) DeleteCloudAccessPolicy(region, id string) error {
return c.request("DELETE", fmt.Sprintf("/api/v1/accesspolicies/%s", id), url.Values{
"region": []string{region},
}, nil, nil)
}