-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
381 lines (340 loc) · 16.2 KB
/
client.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
// --------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------------------------
// Generated file, DO NOT EDIT
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
// --------------------------------------------------------------------------------------------
package security
import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/url"
"strconv"
"github.com/artbegolli/go-ado/azuredevops"
"github.com/google/uuid"
)
type Client interface {
// Evaluates whether the caller has the specified permissions on the specified set of security tokens.
HasPermissions(context.Context, HasPermissionsArgs) (*[]bool, error)
// Evaluates multiple permissions for the calling user. Note: This method does not aggregate the results, nor does it short-circuit if one of the permissions evaluates to false.
HasPermissionsBatch(context.Context, HasPermissionsBatchArgs) (*PermissionEvaluationBatch, error)
// Return a list of access control lists for the specified security namespace and token. All ACLs in the security namespace will be retrieved if no optional parameters are provided.
QueryAccessControlLists(context.Context, QueryAccessControlListsArgs) (*[]AccessControlList, error)
// List all security namespaces or just the specified namespace.
QuerySecurityNamespaces(context.Context, QuerySecurityNamespacesArgs) (*[]SecurityNamespaceDescription, error)
// Remove the specified ACEs from the ACL belonging to the specified token.
RemoveAccessControlEntries(context.Context, RemoveAccessControlEntriesArgs) (*bool, error)
// Remove access control lists under the specfied security namespace.
RemoveAccessControlLists(context.Context, RemoveAccessControlListsArgs) (*bool, error)
// Removes the specified permissions on a security token for a user or group.
RemovePermission(context.Context, RemovePermissionArgs) (*AccessControlEntry, error)
// Add or update ACEs in the ACL for the provided token. The request body contains the target token, a list of [ACEs](https://docs.microsoft.com/en-us/rest/api/azure/devops/security/access%20control%20entries/set%20access%20control%20entries?#accesscontrolentry) and a optional merge parameter. In the case of a collision (by identity descriptor) with an existing ACE in the ACL, the "merge" parameter determines the behavior. If set, the existing ACE has its allow and deny merged with the incoming ACE's allow and deny. If unset, the existing ACE is displaced.
SetAccessControlEntries(context.Context, SetAccessControlEntriesArgs) (*[]AccessControlEntry, error)
// Create or update one or more access control lists. All data that currently exists for the ACLs supplied will be overwritten.
SetAccessControlLists(context.Context, SetAccessControlListsArgs) error
}
type ClientImpl struct {
Client azuredevops.Client
}
func NewClient(ctx context.Context, connection *azuredevops.Connection) Client {
client := connection.GetClientByUrl(connection.BaseUrl)
return &ClientImpl{
Client: *client,
}
}
// Evaluates whether the caller has the specified permissions on the specified set of security tokens.
func (client *ClientImpl) HasPermissions(ctx context.Context, args HasPermissionsArgs) (*[]bool, error) {
routeValues := make(map[string]string)
if args.SecurityNamespaceId == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.SecurityNamespaceId"}
}
routeValues["securityNamespaceId"] = (*args.SecurityNamespaceId).String()
if args.Permissions != nil {
routeValues["permissions"] = strconv.Itoa(*args.Permissions)
}
queryParams := url.Values{}
if args.Tokens != nil {
queryParams.Add("tokens", *args.Tokens)
}
if args.AlwaysAllowAdministrators != nil {
queryParams.Add("alwaysAllowAdministrators", strconv.FormatBool(*args.AlwaysAllowAdministrators))
}
if args.Delimiter != nil {
queryParams.Add("delimiter", *args.Delimiter)
}
locationId, _ := uuid.Parse("dd3b8bd6-c7fc-4cbd-929a-933d9c011c9d")
resp, err := client.Client.Send(ctx, http.MethodGet, locationId, "5.1", routeValues, queryParams, nil, "", "application/json", nil)
if err != nil {
return nil, err
}
var responseValue []bool
err = client.Client.UnmarshalCollectionBody(resp, &responseValue)
return &responseValue, err
}
// Arguments for the HasPermissions function
type HasPermissionsArgs struct {
// (required) Security namespace identifier.
SecurityNamespaceId *uuid.UUID
// (optional) Permissions to evaluate.
Permissions *int
// (optional) One or more security tokens to evaluate.
Tokens *string
// (optional) If true and if the caller is an administrator, always return true.
AlwaysAllowAdministrators *bool
// (optional) Optional security token separator. Defaults to ",".
Delimiter *string
}
// Evaluates multiple permissions for the calling user. Note: This method does not aggregate the results, nor does it short-circuit if one of the permissions evaluates to false.
func (client *ClientImpl) HasPermissionsBatch(ctx context.Context, args HasPermissionsBatchArgs) (*PermissionEvaluationBatch, error) {
if args.EvalBatch == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.EvalBatch"}
}
body, marshalErr := json.Marshal(*args.EvalBatch)
if marshalErr != nil {
return nil, marshalErr
}
locationId, _ := uuid.Parse("cf1faa59-1b63-4448-bf04-13d981a46f5d")
resp, err := client.Client.Send(ctx, http.MethodPost, locationId, "5.1", nil, nil, bytes.NewReader(body), "application/json", "application/json", nil)
if err != nil {
return nil, err
}
var responseValue PermissionEvaluationBatch
err = client.Client.UnmarshalBody(resp, &responseValue)
return &responseValue, err
}
// Arguments for the HasPermissionsBatch function
type HasPermissionsBatchArgs struct {
// (required) The set of evaluation requests.
EvalBatch *PermissionEvaluationBatch
}
// Return a list of access control lists for the specified security namespace and token. All ACLs in the security namespace will be retrieved if no optional parameters are provided.
func (client *ClientImpl) QueryAccessControlLists(ctx context.Context, args QueryAccessControlListsArgs) (*[]AccessControlList, error) {
routeValues := make(map[string]string)
if args.SecurityNamespaceId == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.SecurityNamespaceId"}
}
routeValues["securityNamespaceId"] = (*args.SecurityNamespaceId).String()
queryParams := url.Values{}
if args.Token != nil {
queryParams.Add("token", *args.Token)
}
if args.Descriptors != nil {
queryParams.Add("descriptors", *args.Descriptors)
}
if args.IncludeExtendedInfo != nil {
queryParams.Add("includeExtendedInfo", strconv.FormatBool(*args.IncludeExtendedInfo))
}
if args.Recurse != nil {
queryParams.Add("recurse", strconv.FormatBool(*args.Recurse))
}
locationId, _ := uuid.Parse("18a2ad18-7571-46ae-bec7-0c7da1495885")
resp, err := client.Client.Send(ctx, http.MethodGet, locationId, "5.1", routeValues, queryParams, nil, "", "application/json", nil)
if err != nil {
return nil, err
}
var responseValue []AccessControlList
err = client.Client.UnmarshalCollectionBody(resp, &responseValue)
return &responseValue, err
}
// Arguments for the QueryAccessControlLists function
type QueryAccessControlListsArgs struct {
// (required) Security namespace identifier.
SecurityNamespaceId *uuid.UUID
// (optional) Security token
Token *string
// (optional) An optional filter string containing a list of identity descriptors separated by ',' whose ACEs should be retrieved. If this is left null, entire ACLs will be returned.
Descriptors *string
// (optional) If true, populate the extended information properties for the access control entries contained in the returned lists.
IncludeExtendedInfo *bool
// (optional) If true and this is a hierarchical namespace, return child ACLs of the specified token.
Recurse *bool
}
// List all security namespaces or just the specified namespace.
func (client *ClientImpl) QuerySecurityNamespaces(ctx context.Context, args QuerySecurityNamespacesArgs) (*[]SecurityNamespaceDescription, error) {
routeValues := make(map[string]string)
if args.SecurityNamespaceId != nil {
routeValues["securityNamespaceId"] = (*args.SecurityNamespaceId).String()
}
queryParams := url.Values{}
if args.LocalOnly != nil {
queryParams.Add("localOnly", strconv.FormatBool(*args.LocalOnly))
}
locationId, _ := uuid.Parse("ce7b9f95-fde9-4be8-a86d-83b366f0b87a")
resp, err := client.Client.Send(ctx, http.MethodGet, locationId, "5.1", routeValues, queryParams, nil, "", "application/json", nil)
if err != nil {
return nil, err
}
var responseValue []SecurityNamespaceDescription
err = client.Client.UnmarshalCollectionBody(resp, &responseValue)
return &responseValue, err
}
// Arguments for the QuerySecurityNamespaces function
type QuerySecurityNamespacesArgs struct {
// (optional) Security namespace identifier.
SecurityNamespaceId *uuid.UUID
// (optional) If true, retrieve only local security namespaces.
LocalOnly *bool
}
// Remove the specified ACEs from the ACL belonging to the specified token.
func (client *ClientImpl) RemoveAccessControlEntries(ctx context.Context, args RemoveAccessControlEntriesArgs) (*bool, error) {
routeValues := make(map[string]string)
if args.SecurityNamespaceId == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.SecurityNamespaceId"}
}
routeValues["securityNamespaceId"] = (*args.SecurityNamespaceId).String()
queryParams := url.Values{}
if args.Token != nil {
queryParams.Add("token", *args.Token)
}
if args.Descriptors != nil {
queryParams.Add("descriptors", *args.Descriptors)
}
locationId, _ := uuid.Parse("ac08c8ff-4323-4b08-af90-bcd018d380ce")
resp, err := client.Client.Send(ctx, http.MethodDelete, locationId, "5.1", routeValues, queryParams, nil, "", "application/json", nil)
if err != nil {
return nil, err
}
var responseValue bool
err = client.Client.UnmarshalBody(resp, &responseValue)
return &responseValue, err
}
// Arguments for the RemoveAccessControlEntries function
type RemoveAccessControlEntriesArgs struct {
// (required) Security namespace identifier.
SecurityNamespaceId *uuid.UUID
// (optional) The token whose ACL should be modified.
Token *string
// (optional) String containing a list of identity descriptors separated by ',' whose entries should be removed.
Descriptors *string
}
// Remove access control lists under the specfied security namespace.
func (client *ClientImpl) RemoveAccessControlLists(ctx context.Context, args RemoveAccessControlListsArgs) (*bool, error) {
routeValues := make(map[string]string)
if args.SecurityNamespaceId == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.SecurityNamespaceId"}
}
routeValues["securityNamespaceId"] = (*args.SecurityNamespaceId).String()
queryParams := url.Values{}
if args.Tokens != nil {
queryParams.Add("tokens", *args.Tokens)
}
if args.Recurse != nil {
queryParams.Add("recurse", strconv.FormatBool(*args.Recurse))
}
locationId, _ := uuid.Parse("18a2ad18-7571-46ae-bec7-0c7da1495885")
resp, err := client.Client.Send(ctx, http.MethodDelete, locationId, "5.1", routeValues, queryParams, nil, "", "application/json", nil)
if err != nil {
return nil, err
}
var responseValue bool
err = client.Client.UnmarshalBody(resp, &responseValue)
return &responseValue, err
}
// Arguments for the RemoveAccessControlLists function
type RemoveAccessControlListsArgs struct {
// (required) Security namespace identifier.
SecurityNamespaceId *uuid.UUID
// (optional) One or more comma-separated security tokens
Tokens *string
// (optional) If true and this is a hierarchical namespace, also remove child ACLs of the specified tokens.
Recurse *bool
}
// Removes the specified permissions on a security token for a user or group.
func (client *ClientImpl) RemovePermission(ctx context.Context, args RemovePermissionArgs) (*AccessControlEntry, error) {
routeValues := make(map[string]string)
if args.SecurityNamespaceId == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.SecurityNamespaceId"}
}
routeValues["securityNamespaceId"] = (*args.SecurityNamespaceId).String()
if args.Permissions != nil {
routeValues["permissions"] = strconv.Itoa(*args.Permissions)
}
queryParams := url.Values{}
if args.Descriptor == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "descriptor"}
}
queryParams.Add("descriptor", *args.Descriptor)
if args.Token != nil {
queryParams.Add("token", *args.Token)
}
locationId, _ := uuid.Parse("dd3b8bd6-c7fc-4cbd-929a-933d9c011c9d")
resp, err := client.Client.Send(ctx, http.MethodDelete, locationId, "5.1", routeValues, queryParams, nil, "", "application/json", nil)
if err != nil {
return nil, err
}
var responseValue AccessControlEntry
err = client.Client.UnmarshalBody(resp, &responseValue)
return &responseValue, err
}
// Arguments for the RemovePermission function
type RemovePermissionArgs struct {
// (required) Security namespace identifier.
SecurityNamespaceId *uuid.UUID
// (required) Identity descriptor of the user to remove permissions for.
Descriptor *string
// (optional) Permissions to remove.
Permissions *int
// (optional) Security token to remove permissions for.
Token *string
}
// Add or update ACEs in the ACL for the provided token. The request body contains the target token, a list of [ACEs](https://docs.microsoft.com/en-us/rest/api/azure/devops/security/access%20control%20entries/set%20access%20control%20entries?#accesscontrolentry) and a optional merge parameter. In the case of a collision (by identity descriptor) with an existing ACE in the ACL, the "merge" parameter determines the behavior. If set, the existing ACE has its allow and deny merged with the incoming ACE's allow and deny. If unset, the existing ACE is displaced.
func (client *ClientImpl) SetAccessControlEntries(ctx context.Context, args SetAccessControlEntriesArgs) (*[]AccessControlEntry, error) {
if args.Container == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.Container"}
}
routeValues := make(map[string]string)
if args.SecurityNamespaceId == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.SecurityNamespaceId"}
}
routeValues["securityNamespaceId"] = (*args.SecurityNamespaceId).String()
body, marshalErr := json.Marshal(args.Container)
if marshalErr != nil {
return nil, marshalErr
}
locationId, _ := uuid.Parse("ac08c8ff-4323-4b08-af90-bcd018d380ce")
resp, err := client.Client.Send(ctx, http.MethodPost, locationId, "5.1", routeValues, nil, bytes.NewReader(body), "application/json", "application/json", nil)
if err != nil {
return nil, err
}
var responseValue []AccessControlEntry
err = client.Client.UnmarshalCollectionBody(resp, &responseValue)
return &responseValue, err
}
// Arguments for the SetAccessControlEntries function
type SetAccessControlEntriesArgs struct {
// (required)
Container interface{}
// (required) Security namespace identifier.
SecurityNamespaceId *uuid.UUID
}
// Create or update one or more access control lists. All data that currently exists for the ACLs supplied will be overwritten.
func (client *ClientImpl) SetAccessControlLists(ctx context.Context, args SetAccessControlListsArgs) error {
if args.AccessControlLists == nil {
return &azuredevops.ArgumentNilError{ArgumentName: "args.AccessControlLists"}
}
routeValues := make(map[string]string)
if args.SecurityNamespaceId == nil {
return &azuredevops.ArgumentNilError{ArgumentName: "args.SecurityNamespaceId"}
}
routeValues["securityNamespaceId"] = (*args.SecurityNamespaceId).String()
body, marshalErr := json.Marshal(*args.AccessControlLists)
if marshalErr != nil {
return marshalErr
}
locationId, _ := uuid.Parse("18a2ad18-7571-46ae-bec7-0c7da1495885")
_, err := client.Client.Send(ctx, http.MethodPost, locationId, "5.1", routeValues, nil, bytes.NewReader(body), "application/json", "application/json", nil)
if err != nil {
return err
}
return nil
}
// Arguments for the SetAccessControlLists function
type SetAccessControlListsArgs struct {
// (required) A list of ACLs to create or update.
AccessControlLists *azuredevops.VssJsonCollectionWrapper
// (required) Security namespace identifier.
SecurityNamespaceId *uuid.UUID
}