forked from ionos-enterprise/ionos-enterprise-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usermanagment.go
339 lines (301 loc) · 10.5 KB
/
usermanagment.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
package profitbricks
import (
"net/http"
)
// Groups object
type Groups struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Group `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// Group object
type Group struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Properties GroupProperties `json:"properties,omitempty"`
Entities *GroupEntities `json:"entities,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// GroupProperties object
type GroupProperties struct {
Name string `json:"name,omitempty"`
CreateDataCenter *bool `json:"createDataCenter,omitempty"`
CreateSnapshot *bool `json:"createSnapshot,omitempty"`
ReserveIP *bool `json:"reserveIp,omitempty"`
AccessActivityLog *bool `json:"accessActivityLog,omitempty"`
CreateBackupUnit *bool `json:"createBackupUnit,omitempty"`
CreateInternetAccess *bool `json:"createInternetAccess,omitempty"`
CreateK8sCluster *bool `json:"createK8sCluster,omitempty"`
CreatePcc *bool `json:"createPcc,omitempty"`
S3Privilege *bool `json:"s3Privilege,omitempty"`
}
// GroupEntities object
type GroupEntities struct {
Users Users `json:"users,omitempty"`
Resources Resources `json:"resources,omitempty"`
}
// Users object
type Users struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []User `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// User object
type User struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Properties *UserProperties `json:"properties,omitempty"`
Entities *UserEntities `json:"entities,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// UserProperties object
type UserProperties struct {
Firstname string `json:"firstname,omitempty"`
Lastname string `json:"lastname,omitempty"`
Email string `json:"email,omitempty"`
Password string `json:"password,omitempty"`
Administrator bool `json:"administrator,omitempty"`
ForceSecAuth bool `json:"forceSecAuth,omitempty"`
SecAuthActive bool `json:"secAuthActive,omitempty"`
Active *bool `json:"active,omitempty"`
S3CanonicalUserID string `json:"s3CanonicalUserId,omitempty"`
}
// UserEntities object
type UserEntities struct {
Groups Groups `json:"groups,omitempty"`
Owns Owns `json:"owns,omitempty"`
}
// Resources object
type Resources struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Resource `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// Resource object
type Resource struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Entities *ResourceEntities `json:"entities,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// ResourceEntities object
type ResourceEntities struct {
Groups Groups `json:"groups,omitempty"`
}
// Owns object
type Owns struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Entity `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// Entity object
type Entity struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// Shares object
type Shares struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Items []Share `json:"items,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// Share object
type Share struct {
ID string `json:"id,omitempty"`
PBType string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
Properties ShareProperties `json:"properties,omitempty"`
Response string `json:"Response,omitempty"`
Headers *http.Header `json:"headers,omitempty"`
StatusCode int `json:"statuscode,omitempty"`
}
// ShareProperties object
type ShareProperties struct {
EditPrivilege *bool `json:"editPrivilege,omitempty"`
SharePrivilege *bool `json:"sharePrivilege,omitempty"`
}
//ListGroups lists all groups
func (c *Client) ListGroups() (*Groups, error) {
url := groupsPath()
ret := &Groups{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//GetGroup gets a group
func (c *Client) GetGroup(groupid string) (*Group, error) {
url := groupPath(groupid)
ret := &Group{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//CreateGroup creates a group
func (c *Client) CreateGroup(grp Group) (*Group, error) {
url := groupsPath()
ret := &Group{}
err := c.Post(url, grp, ret, http.StatusAccepted)
return ret, err
}
//UpdateGroup updates a group
func (c *Client) UpdateGroup(groupid string, obj Group) (*Group, error) {
url := groupPath(groupid)
ret := &Group{}
err := c.Put(url, obj, ret, http.StatusAccepted)
return ret, err
}
//DeleteGroup deletes a group
func (c *Client) DeleteGroup(groupid string) (*http.Header, error) {
url := groupPath(groupid)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
}
//ListShares lists all shares
func (c *Client) ListShares(grpid string) (*Shares, error) {
url := sharesPath(grpid)
ret := &Shares{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
// GetShare gets a share
func (c *Client) GetShare(groupid string, resourceid string) (*Share, error) {
url := sharePath(groupid, resourceid)
ret := &Share{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
// AddShare adds a share
func (c *Client) AddShare(groupid string, resourceid string, share Share) (*Share, error) {
url := sharePath(groupid, resourceid)
ret := &Share{}
err := c.Post(url, share, ret, http.StatusAccepted)
return ret, err
}
// UpdateShare updates a share
func (c *Client) UpdateShare(groupid string, resourceid string, obj Share) (*Share, error) {
url := sharePath(groupid, resourceid)
ret := &Share{}
err := c.Put(url, obj, ret, http.StatusAccepted)
return ret, err
}
// DeleteShare deletes a share
func (c *Client) DeleteShare(groupid string, resourceid string) (*http.Header, error) {
url := sharePath(groupid, resourceid)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
}
//ListGroupUsers lists Users in a group
func (c *Client) ListGroupUsers(groupid string) (*Users, error) {
url := groupUsersPath(groupid)
ret := &Users{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
// AddUserToGroup adds a user to a group
func (c *Client) AddUserToGroup(groupid string, userid string) (*User, error) {
var usr User
usr.ID = userid
url := groupUsersPath(groupid)
ret := &User{}
err := c.Post(url, usr, ret, http.StatusAccepted)
return ret, err
}
// DeleteUserFromGroup removes a user from a group
func (c *Client) DeleteUserFromGroup(groupid string, userid string) (*http.Header, error) {
url := groupUserPath(groupid, userid)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
}
//ListUsers lists all users
func (c *Client) ListUsers() (*Users, error) {
url := usersPath()
ret := &Users{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
// GetUser gets a user
func (c *Client) GetUser(usrid string) (*User, error) {
url := userPath(usrid)
ret := &User{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//CreateUser creates a user
func (c *Client) CreateUser(usr User) (*User, error) {
url := usersPath()
ret := &User{}
err := c.Post(url, usr, ret, http.StatusAccepted)
return ret, err
}
//UpdateUser updates user information
func (c *Client) UpdateUser(userid string, obj User) (*User, error) {
url := userPath(userid)
ret := &User{}
err := c.Put(url, obj, ret, http.StatusAccepted)
return ret, err
}
//DeleteUser deletes the specified user
func (c *Client) DeleteUser(userid string) (*http.Header, error) {
url := userPath(userid)
ret := &http.Header{}
err := c.Delete(url, ret, http.StatusAccepted)
return ret, err
}
//ListResources lists all resources
func (c *Client) ListResources() (*Resources, error) {
url := resourcesPath()
ret := &Resources{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//GetResourceByType gets a resource by type
func (c *Client) GetResourceByType(resourcetype string, resourceid string) (*Resource, error) {
url := resourcePath(resourcetype, resourceid)
ret := &Resource{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}
//ListResourcesByType list resources by type
func (c *Client) ListResourcesByType(resourcetype string) (*Resources, error) {
url := resourcesTypePath(resourcetype)
ret := &Resources{}
err := c.Get(url, ret, http.StatusOK)
return ret, err
}