-
Notifications
You must be signed in to change notification settings - Fork 133
/
types_iam.go
110 lines (92 loc) · 2.6 KB
/
types_iam.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
103
104
105
106
107
108
109
110
package ovh
type IamReferenceAction struct {
Action string `json:"action"`
Categories []string `json:"categories"`
Description string `json:"description"`
ResourceType string `json:"resourceType"`
}
func (a *IamReferenceAction) ToMap() map[string]any {
out := make(map[string]any, 4)
out["action"] = a.Action
out["categories"] = a.Categories
out["description"] = a.Description
out["resource_type"] = a.ResourceType
return out
}
type IamPolicy struct {
Id string `json:"id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Identities []string `json:"identities"`
Resources []IamResource `json:"resources"`
Permissions IamPermissions `json:"permissions"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
Owner string `json:"owner,omitempty"`
}
func (p IamPolicy) ToMap() map[string]any {
out := make(map[string]any, 0)
out["name"] = p.Name
out["owner"] = p.Owner
out["created_at"] = p.CreatedAt
out["identities"] = p.Identities
var resources []string
for _, r := range p.Resources {
resources = append(resources, r.URN)
}
out["resources"] = resources
// inline allow and except
allow, except := p.Permissions.ToLists()
if len(allow) != 0 {
out["allow"] = allow
}
if len(except) != 0 {
out["except"] = except
}
if p.Description != "" {
out["description"] = p.Description
}
if p.ReadOnly {
out["read_only"] = p.ReadOnly
}
if p.UpdatedAt != "" {
out["updated_at"] = p.UpdatedAt
}
return out
}
type IamResource struct {
URN string `json:"urn,omitempty"`
Group *IamPolicyResourceGroup `json:"group,omitempty"`
Resource *IamResourceDetails `json:"resource,omitempty"`
}
type IamPolicyResourceGroup struct {
Id string `json:"id"`
Name string `json:"name"`
ReadOnly bool `json:"readOnly"`
}
type IamResourceDetails struct {
Id string `json:"id"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
Owner string `json:"owner"`
Type string `json:"type"`
}
type IamPermissions struct {
Allow []IamAction `json:"allow"`
Except []IamAction `json:"except"`
}
func (p IamPermissions) ToLists() ([]string, []string) {
var allow []string
var except []string
for _, r := range p.Allow {
allow = append(allow, r.Action)
}
for _, r := range p.Except {
except = append(except, r.Action)
}
return allow, except
}
type IamAction struct {
Action string `json:"action"`
}