-
Notifications
You must be signed in to change notification settings - Fork 4
/
identity.go
148 lines (123 loc) · 4.98 KB
/
identity.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package cpln
import (
"fmt"
)
// Identity - Identity
type Identity struct {
Base
Aws *AwsIdentity `json:"aws,omitempty"`
AwsReplace *AwsIdentity `json:"$replace/aws,omitempty"`
Gcp *GcpIdentity `json:"gcp,omitempty"`
GcpReplace *GcpIdentity `json:"$replace/gcp,omitempty"`
Azure *AzureIdentity `json:"azure,omitempty"`
AzureReplace *AzureIdentity `json:"$replace/azure,omitempty"`
Ngs *NgsIdentity `json:"ngs,omitempty"`
NgsReplace *NgsIdentity `json:"$replace/ngs,omitempty"`
NetworkResources *[]NetworkResource `json:"networkResources,omitempty"`
NativeNetworkResources *[]NativeNetworkResource `json:"nativeNetworkResources,omitempty"`
Status *IdentityStatus `json:"status,omitempty"`
Drop *[]string `json:"$drop,omitempty"`
}
type IdentityStatus struct {
ObjectName *string `json:"objectName,omitempty"`
}
// NetworkResource - NetworkResource
type NetworkResource struct {
Name *string `json:"name,omitempty"`
AgentLink *string `json:"agentLink,omitempty"`
IPs *[]string `json:"IPs,omitempty"`
FQDN *string `json:"FQDN,omitempty"`
ResolverIP *string `json:"resolverIP,omitempty"`
Ports *[]int `json:"ports,omitempty"`
}
// NativeNetowrkResource - NativeNetowrkResource
type NativeNetworkResource struct {
Name *string `json:"name,omitempty"`
FQDN *string `json:"FQDN,omitempty"`
Ports *[]int `json:"ports,omitempty"`
AWSPrivateLink *AWSPrivateLink `json:"awsPrivateLink,omitempty"`
GCPServiceConnect *GCPServiceConnect `json:"gcpServiceConnect,omitempty"`
}
// AWSPrivateLink - AWSPrivateLink
type AWSPrivateLink struct {
EndpointServiceName *string `json:"endpointServiceName,omitempty"`
}
// GCPServiceConnect - GCPServiceConnect
type GCPServiceConnect struct {
TargetService *string `json:"targetService,omitempty"`
}
// AwsIdentity - AwsIdentity
type AwsIdentity struct {
CloudAccountLink *string `json:"cloudAccountLink,omitempty"`
PolicyRefs *[]string `json:"policyRefs,omitempty"`
// TrustPolicy *AwsPolicyDocument `json:"trustPolicy,omitempty"`
RoleName *string `json:"roleName,omitempty"`
}
// // AwsPolicyDocument - AwsPolicyDocument
// type AwsPolicyDocument struct {
// Version *string `json:"version,omitempty"`
// Statement *[]string `json:"statement,omitempty"`
// }
type GcpBinding struct {
Resource *string `json:"resource,omitempty"`
Roles *[]string `json:"roles,omitempty"`
}
type GcpIdentity struct {
CloudAccountLink *string `json:"cloudAccountLink,omitempty"`
Scopes *[]string `json:"scopes,omitempty"`
ServiceAccount *string `json:"serviceAccount,omitempty"`
Bindings *[]GcpBinding `json:"bindings,omitempty"`
}
type AzureRoleAssignment struct {
Scope *string `json:"scope,omitempty"`
Roles *[]string `json:"roles,omitempty"`
}
type AzureIdentity struct {
CloudAccountLink *string `json:"cloudAccountLink,omitempty"`
RoleAssignments *[]AzureRoleAssignment `json:"roleAssignments,omitempty"`
}
type NgsPerm struct {
Allow *[]string `json:"allow,omitempty"`
Deny *[]string `json:"deny,omitempty"`
}
type NgsResp struct {
Max *int `json:"max,omitempty"`
TTL *string `json:"ttl,omitempty"`
}
type NgsIdentity struct {
CloudAccountLink *string `json:"cloudAccountLink,omitempty"`
Pub *NgsPerm `json:"pub,omitempty"`
Sub *NgsPerm `json:"sub,omitempty"`
Resp *NgsResp `json:"resp,omitempty"`
Subs *int `json:"subs,omitempty"`
Data *int `json:"data,omitempty"`
Payload *int `json:"payload,omitempty"`
}
// GetIdentity - Get Identity by name
func (c *Client) GetIdentity(name, gvcName string) (*Identity, int, error) {
identity, code, err := c.GetResource(fmt.Sprintf("gvc/%s/identity/%s", gvcName, name), new(Identity))
if err != nil {
return nil, code, err
}
return identity.(*Identity), code, err
}
// CreateIdentity - Create an Identity
func (c *Client) CreateIdentity(identity Identity, gvcName string) (*Identity, int, error) {
code, err := c.CreateResource(fmt.Sprintf("gvc/%s/identity", gvcName), *identity.Name, identity)
if err != nil {
return nil, code, err
}
return c.GetIdentity(*identity.Name, gvcName)
}
// UpdateIdentity - Update an Identity
func (c *Client) UpdateIdentity(identity Identity, gvcName string) (*Identity, int, error) {
code, err := c.UpdateResource(fmt.Sprintf("gvc/%s/identity/%s", gvcName, *identity.Name), identity)
if err != nil {
return nil, code, err
}
return c.GetIdentity(*identity.Name, gvcName)
}
// DeleteIdentity - Delete Identity by name
func (c *Client) DeleteIdentity(name, gvcName string) error {
return c.DeleteResource(fmt.Sprintf("gvc/%s/identity/%s", gvcName, name))
}