/
definitions_client.go
656 lines (623 loc) · 32.6 KB
/
definitions_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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
//go:build go1.18
// +build go1.18
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
package armpolicy
import (
"context"
"errors"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"net/http"
"net/url"
"strconv"
"strings"
)
// DefinitionsClient contains the methods for the PolicyDefinitions group.
// Don't use this type directly, use NewDefinitionsClient() instead.
type DefinitionsClient struct {
internal *arm.Client
subscriptionID string
}
// NewDefinitionsClient creates a new instance of DefinitionsClient with the specified values.
// - subscriptionID - The ID of the target subscription.
// - credential - used to authorize requests. Usually a credential from azidentity.
// - options - pass nil to accept the default values.
func NewDefinitionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*DefinitionsClient, error) {
cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
if err != nil {
return nil, err
}
client := &DefinitionsClient{
subscriptionID: subscriptionID,
internal: cl,
}
return client, nil
}
// CreateOrUpdate - This operation creates or updates a policy definition in the given subscription with the given name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2021-06-01
// - policyDefinitionName - The name of the policy definition to create.
// - parameters - The policy definition properties.
// - options - DefinitionsClientCreateOrUpdateOptions contains the optional parameters for the DefinitionsClient.CreateOrUpdate
// method.
func (client *DefinitionsClient) CreateOrUpdate(ctx context.Context, policyDefinitionName string, parameters Definition, options *DefinitionsClientCreateOrUpdateOptions) (DefinitionsClientCreateOrUpdateResponse, error) {
var err error
const operationName = "DefinitionsClient.CreateOrUpdate"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.createOrUpdateCreateRequest(ctx, policyDefinitionName, parameters, options)
if err != nil {
return DefinitionsClientCreateOrUpdateResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return DefinitionsClientCreateOrUpdateResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusCreated) {
err = runtime.NewResponseError(httpResp)
return DefinitionsClientCreateOrUpdateResponse{}, err
}
resp, err := client.createOrUpdateHandleResponse(httpResp)
return resp, err
}
// createOrUpdateCreateRequest creates the CreateOrUpdate request.
func (client *DefinitionsClient) createOrUpdateCreateRequest(ctx context.Context, policyDefinitionName string, parameters Definition, options *DefinitionsClientCreateOrUpdateOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"
if policyDefinitionName == "" {
return nil, errors.New("parameter policyDefinitionName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{policyDefinitionName}", url.PathEscape(policyDefinitionName))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
if err := runtime.MarshalAsJSON(req, parameters); err != nil {
return nil, err
}
return req, nil
}
// createOrUpdateHandleResponse handles the CreateOrUpdate response.
func (client *DefinitionsClient) createOrUpdateHandleResponse(resp *http.Response) (DefinitionsClientCreateOrUpdateResponse, error) {
result := DefinitionsClientCreateOrUpdateResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.Definition); err != nil {
return DefinitionsClientCreateOrUpdateResponse{}, err
}
return result, nil
}
// CreateOrUpdateAtManagementGroup - This operation creates or updates a policy definition in the given management group with
// the given name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2021-06-01
// - policyDefinitionName - The name of the policy definition to create.
// - managementGroupID - The ID of the management group.
// - parameters - The policy definition properties.
// - options - DefinitionsClientCreateOrUpdateAtManagementGroupOptions contains the optional parameters for the DefinitionsClient.CreateOrUpdateAtManagementGroup
// method.
func (client *DefinitionsClient) CreateOrUpdateAtManagementGroup(ctx context.Context, policyDefinitionName string, managementGroupID string, parameters Definition, options *DefinitionsClientCreateOrUpdateAtManagementGroupOptions) (DefinitionsClientCreateOrUpdateAtManagementGroupResponse, error) {
var err error
const operationName = "DefinitionsClient.CreateOrUpdateAtManagementGroup"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.createOrUpdateAtManagementGroupCreateRequest(ctx, policyDefinitionName, managementGroupID, parameters, options)
if err != nil {
return DefinitionsClientCreateOrUpdateAtManagementGroupResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return DefinitionsClientCreateOrUpdateAtManagementGroupResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusCreated) {
err = runtime.NewResponseError(httpResp)
return DefinitionsClientCreateOrUpdateAtManagementGroupResponse{}, err
}
resp, err := client.createOrUpdateAtManagementGroupHandleResponse(httpResp)
return resp, err
}
// createOrUpdateAtManagementGroupCreateRequest creates the CreateOrUpdateAtManagementGroup request.
func (client *DefinitionsClient) createOrUpdateAtManagementGroupCreateRequest(ctx context.Context, policyDefinitionName string, managementGroupID string, parameters Definition, options *DefinitionsClientCreateOrUpdateAtManagementGroupOptions) (*policy.Request, error) {
urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"
if policyDefinitionName == "" {
return nil, errors.New("parameter policyDefinitionName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{policyDefinitionName}", url.PathEscape(policyDefinitionName))
if managementGroupID == "" {
return nil, errors.New("parameter managementGroupID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID))
req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
if err := runtime.MarshalAsJSON(req, parameters); err != nil {
return nil, err
}
return req, nil
}
// createOrUpdateAtManagementGroupHandleResponse handles the CreateOrUpdateAtManagementGroup response.
func (client *DefinitionsClient) createOrUpdateAtManagementGroupHandleResponse(resp *http.Response) (DefinitionsClientCreateOrUpdateAtManagementGroupResponse, error) {
result := DefinitionsClientCreateOrUpdateAtManagementGroupResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.Definition); err != nil {
return DefinitionsClientCreateOrUpdateAtManagementGroupResponse{}, err
}
return result, nil
}
// Delete - This operation deletes the policy definition in the given subscription with the given name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2021-06-01
// - policyDefinitionName - The name of the policy definition to delete.
// - options - DefinitionsClientDeleteOptions contains the optional parameters for the DefinitionsClient.Delete method.
func (client *DefinitionsClient) Delete(ctx context.Context, policyDefinitionName string, options *DefinitionsClientDeleteOptions) (DefinitionsClientDeleteResponse, error) {
var err error
const operationName = "DefinitionsClient.Delete"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.deleteCreateRequest(ctx, policyDefinitionName, options)
if err != nil {
return DefinitionsClientDeleteResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return DefinitionsClientDeleteResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) {
err = runtime.NewResponseError(httpResp)
return DefinitionsClientDeleteResponse{}, err
}
return DefinitionsClientDeleteResponse{}, nil
}
// deleteCreateRequest creates the Delete request.
func (client *DefinitionsClient) deleteCreateRequest(ctx context.Context, policyDefinitionName string, options *DefinitionsClientDeleteOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"
if policyDefinitionName == "" {
return nil, errors.New("parameter policyDefinitionName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{policyDefinitionName}", url.PathEscape(policyDefinitionName))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// DeleteAtManagementGroup - This operation deletes the policy definition in the given management group with the given name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2021-06-01
// - policyDefinitionName - The name of the policy definition to delete.
// - managementGroupID - The ID of the management group.
// - options - DefinitionsClientDeleteAtManagementGroupOptions contains the optional parameters for the DefinitionsClient.DeleteAtManagementGroup
// method.
func (client *DefinitionsClient) DeleteAtManagementGroup(ctx context.Context, policyDefinitionName string, managementGroupID string, options *DefinitionsClientDeleteAtManagementGroupOptions) (DefinitionsClientDeleteAtManagementGroupResponse, error) {
var err error
const operationName = "DefinitionsClient.DeleteAtManagementGroup"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.deleteAtManagementGroupCreateRequest(ctx, policyDefinitionName, managementGroupID, options)
if err != nil {
return DefinitionsClientDeleteAtManagementGroupResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return DefinitionsClientDeleteAtManagementGroupResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusNoContent) {
err = runtime.NewResponseError(httpResp)
return DefinitionsClientDeleteAtManagementGroupResponse{}, err
}
return DefinitionsClientDeleteAtManagementGroupResponse{}, nil
}
// deleteAtManagementGroupCreateRequest creates the DeleteAtManagementGroup request.
func (client *DefinitionsClient) deleteAtManagementGroupCreateRequest(ctx context.Context, policyDefinitionName string, managementGroupID string, options *DefinitionsClientDeleteAtManagementGroupOptions) (*policy.Request, error) {
urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"
if policyDefinitionName == "" {
return nil, errors.New("parameter policyDefinitionName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{policyDefinitionName}", url.PathEscape(policyDefinitionName))
if managementGroupID == "" {
return nil, errors.New("parameter managementGroupID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID))
req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// Get - This operation retrieves the policy definition in the given subscription with the given name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2021-06-01
// - policyDefinitionName - The name of the policy definition to get.
// - options - DefinitionsClientGetOptions contains the optional parameters for the DefinitionsClient.Get method.
func (client *DefinitionsClient) Get(ctx context.Context, policyDefinitionName string, options *DefinitionsClientGetOptions) (DefinitionsClientGetResponse, error) {
var err error
const operationName = "DefinitionsClient.Get"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.getCreateRequest(ctx, policyDefinitionName, options)
if err != nil {
return DefinitionsClientGetResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return DefinitionsClientGetResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return DefinitionsClientGetResponse{}, err
}
resp, err := client.getHandleResponse(httpResp)
return resp, err
}
// getCreateRequest creates the Get request.
func (client *DefinitionsClient) getCreateRequest(ctx context.Context, policyDefinitionName string, options *DefinitionsClientGetOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"
if policyDefinitionName == "" {
return nil, errors.New("parameter policyDefinitionName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{policyDefinitionName}", url.PathEscape(policyDefinitionName))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// getHandleResponse handles the Get response.
func (client *DefinitionsClient) getHandleResponse(resp *http.Response) (DefinitionsClientGetResponse, error) {
result := DefinitionsClientGetResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.Definition); err != nil {
return DefinitionsClientGetResponse{}, err
}
return result, nil
}
// GetAtManagementGroup - This operation retrieves the policy definition in the given management group with the given name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2021-06-01
// - policyDefinitionName - The name of the policy definition to get.
// - managementGroupID - The ID of the management group.
// - options - DefinitionsClientGetAtManagementGroupOptions contains the optional parameters for the DefinitionsClient.GetAtManagementGroup
// method.
func (client *DefinitionsClient) GetAtManagementGroup(ctx context.Context, policyDefinitionName string, managementGroupID string, options *DefinitionsClientGetAtManagementGroupOptions) (DefinitionsClientGetAtManagementGroupResponse, error) {
var err error
const operationName = "DefinitionsClient.GetAtManagementGroup"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.getAtManagementGroupCreateRequest(ctx, policyDefinitionName, managementGroupID, options)
if err != nil {
return DefinitionsClientGetAtManagementGroupResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return DefinitionsClientGetAtManagementGroupResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return DefinitionsClientGetAtManagementGroupResponse{}, err
}
resp, err := client.getAtManagementGroupHandleResponse(httpResp)
return resp, err
}
// getAtManagementGroupCreateRequest creates the GetAtManagementGroup request.
func (client *DefinitionsClient) getAtManagementGroupCreateRequest(ctx context.Context, policyDefinitionName string, managementGroupID string, options *DefinitionsClientGetAtManagementGroupOptions) (*policy.Request, error) {
urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"
if policyDefinitionName == "" {
return nil, errors.New("parameter policyDefinitionName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{policyDefinitionName}", url.PathEscape(policyDefinitionName))
if managementGroupID == "" {
return nil, errors.New("parameter managementGroupID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// getAtManagementGroupHandleResponse handles the GetAtManagementGroup response.
func (client *DefinitionsClient) getAtManagementGroupHandleResponse(resp *http.Response) (DefinitionsClientGetAtManagementGroupResponse, error) {
result := DefinitionsClientGetAtManagementGroupResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.Definition); err != nil {
return DefinitionsClientGetAtManagementGroupResponse{}, err
}
return result, nil
}
// GetBuiltIn - This operation retrieves the built-in policy definition with the given name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2021-06-01
// - policyDefinitionName - The name of the built-in policy definition to get.
// - options - DefinitionsClientGetBuiltInOptions contains the optional parameters for the DefinitionsClient.GetBuiltIn method.
func (client *DefinitionsClient) GetBuiltIn(ctx context.Context, policyDefinitionName string, options *DefinitionsClientGetBuiltInOptions) (DefinitionsClientGetBuiltInResponse, error) {
var err error
const operationName = "DefinitionsClient.GetBuiltIn"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.getBuiltInCreateRequest(ctx, policyDefinitionName, options)
if err != nil {
return DefinitionsClientGetBuiltInResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return DefinitionsClientGetBuiltInResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return DefinitionsClientGetBuiltInResponse{}, err
}
resp, err := client.getBuiltInHandleResponse(httpResp)
return resp, err
}
// getBuiltInCreateRequest creates the GetBuiltIn request.
func (client *DefinitionsClient) getBuiltInCreateRequest(ctx context.Context, policyDefinitionName string, options *DefinitionsClientGetBuiltInOptions) (*policy.Request, error) {
urlPath := "/providers/Microsoft.Authorization/policyDefinitions/{policyDefinitionName}"
if policyDefinitionName == "" {
return nil, errors.New("parameter policyDefinitionName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{policyDefinitionName}", url.PathEscape(policyDefinitionName))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// getBuiltInHandleResponse handles the GetBuiltIn response.
func (client *DefinitionsClient) getBuiltInHandleResponse(resp *http.Response) (DefinitionsClientGetBuiltInResponse, error) {
result := DefinitionsClientGetBuiltInResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.Definition); err != nil {
return DefinitionsClientGetBuiltInResponse{}, err
}
return result, nil
}
// NewListPager - This operation retrieves a list of all the policy definitions in a given subscription that match the optional
// given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq {value}' or
// 'category eq '{value}”. If $filter is not provided, the unfiltered list includes all policy definitions associated with
// the subscription, including those that apply directly or from management groups
// that contain the given subscription. If $filter=atExactScope() is provided, the returned list only includes all policy
// definitions that at the given subscription. If $filter='policyType -eq {value}'
// is provided, the returned list only includes all policy definitions whose type match the {value}. Possible policyType values
// are NotSpecified, BuiltIn, Custom, and Static. If $filter='category -eq
// {value}' is provided, the returned list only includes all policy definitions whose category match the {value}.
//
// Generated from API version 2021-06-01
// - options - DefinitionsClientListOptions contains the optional parameters for the DefinitionsClient.NewListPager method.
func (client *DefinitionsClient) NewListPager(options *DefinitionsClientListOptions) *runtime.Pager[DefinitionsClientListResponse] {
return runtime.NewPager(runtime.PagingHandler[DefinitionsClientListResponse]{
More: func(page DefinitionsClientListResponse) bool {
return page.NextLink != nil && len(*page.NextLink) > 0
},
Fetcher: func(ctx context.Context, page *DefinitionsClientListResponse) (DefinitionsClientListResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DefinitionsClient.NewListPager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.listCreateRequest(ctx, options)
}, nil)
if err != nil {
return DefinitionsClientListResponse{}, err
}
return client.listHandleResponse(resp)
},
Tracer: client.internal.Tracer(),
})
}
// listCreateRequest creates the List request.
func (client *DefinitionsClient) listCreateRequest(ctx context.Context, options *DefinitionsClientListOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyDefinitions"
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
if options != nil && options.Top != nil {
reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10))
}
req.Raw().URL.RawQuery = reqQP.Encode()
unencodedParams := []string{req.Raw().URL.RawQuery}
if options != nil && options.Filter != nil {
unencodedParams = append(unencodedParams, "$filter="+*options.Filter)
}
req.Raw().URL.RawQuery = strings.Join(unencodedParams, "&")
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// listHandleResponse handles the List response.
func (client *DefinitionsClient) listHandleResponse(resp *http.Response) (DefinitionsClientListResponse, error) {
result := DefinitionsClientListResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.DefinitionListResult); err != nil {
return DefinitionsClientListResponse{}, err
}
return result, nil
}
// NewListBuiltInPager - This operation retrieves a list of all the built-in policy definitions that match the optional given
// $filter. If $filter='policyType -eq {value}' is provided, the returned list only includes all
// built-in policy definitions whose type match the {value}. Possible policyType values are NotSpecified, BuiltIn, Custom,
// and Static. If $filter='category -eq {value}' is provided, the returned list
// only includes all built-in policy definitions whose category match the {value}.
//
// Generated from API version 2021-06-01
// - options - DefinitionsClientListBuiltInOptions contains the optional parameters for the DefinitionsClient.NewListBuiltInPager
// method.
func (client *DefinitionsClient) NewListBuiltInPager(options *DefinitionsClientListBuiltInOptions) *runtime.Pager[DefinitionsClientListBuiltInResponse] {
return runtime.NewPager(runtime.PagingHandler[DefinitionsClientListBuiltInResponse]{
More: func(page DefinitionsClientListBuiltInResponse) bool {
return page.NextLink != nil && len(*page.NextLink) > 0
},
Fetcher: func(ctx context.Context, page *DefinitionsClientListBuiltInResponse) (DefinitionsClientListBuiltInResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DefinitionsClient.NewListBuiltInPager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.listBuiltInCreateRequest(ctx, options)
}, nil)
if err != nil {
return DefinitionsClientListBuiltInResponse{}, err
}
return client.listBuiltInHandleResponse(resp)
},
Tracer: client.internal.Tracer(),
})
}
// listBuiltInCreateRequest creates the ListBuiltIn request.
func (client *DefinitionsClient) listBuiltInCreateRequest(ctx context.Context, options *DefinitionsClientListBuiltInOptions) (*policy.Request, error) {
urlPath := "/providers/Microsoft.Authorization/policyDefinitions"
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
if options != nil && options.Top != nil {
reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10))
}
req.Raw().URL.RawQuery = reqQP.Encode()
unencodedParams := []string{req.Raw().URL.RawQuery}
if options != nil && options.Filter != nil {
unencodedParams = append(unencodedParams, "$filter="+*options.Filter)
}
req.Raw().URL.RawQuery = strings.Join(unencodedParams, "&")
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// listBuiltInHandleResponse handles the ListBuiltIn response.
func (client *DefinitionsClient) listBuiltInHandleResponse(resp *http.Response) (DefinitionsClientListBuiltInResponse, error) {
result := DefinitionsClientListBuiltInResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.DefinitionListResult); err != nil {
return DefinitionsClientListBuiltInResponse{}, err
}
return result, nil
}
// NewListByManagementGroupPager - This operation retrieves a list of all the policy definitions in a given management group
// that match the optional given $filter. Valid values for $filter are: 'atExactScope()', 'policyType -eq
// {value}' or 'category eq '{value}”. If $filter is not provided, the unfiltered list includes all policy definitions associated
// with the management group, including those that apply directly or from
// management groups that contain the given management group. If $filter=atExactScope() is provided, the returned list only
// includes all policy definitions that at the given management group. If
// $filter='policyType -eq {value}' is provided, the returned list only includes all policy definitions whose type match the
// {value}. Possible policyType values are NotSpecified, BuiltIn, Custom, and
// Static. If $filter='category -eq {value}' is provided, the returned list only includes all policy definitions whose category
// match the {value}.
//
// Generated from API version 2021-06-01
// - managementGroupID - The ID of the management group.
// - options - DefinitionsClientListByManagementGroupOptions contains the optional parameters for the DefinitionsClient.NewListByManagementGroupPager
// method.
func (client *DefinitionsClient) NewListByManagementGroupPager(managementGroupID string, options *DefinitionsClientListByManagementGroupOptions) *runtime.Pager[DefinitionsClientListByManagementGroupResponse] {
return runtime.NewPager(runtime.PagingHandler[DefinitionsClientListByManagementGroupResponse]{
More: func(page DefinitionsClientListByManagementGroupResponse) bool {
return page.NextLink != nil && len(*page.NextLink) > 0
},
Fetcher: func(ctx context.Context, page *DefinitionsClientListByManagementGroupResponse) (DefinitionsClientListByManagementGroupResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "DefinitionsClient.NewListByManagementGroupPager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.listByManagementGroupCreateRequest(ctx, managementGroupID, options)
}, nil)
if err != nil {
return DefinitionsClientListByManagementGroupResponse{}, err
}
return client.listByManagementGroupHandleResponse(resp)
},
Tracer: client.internal.Tracer(),
})
}
// listByManagementGroupCreateRequest creates the ListByManagementGroup request.
func (client *DefinitionsClient) listByManagementGroupCreateRequest(ctx context.Context, managementGroupID string, options *DefinitionsClientListByManagementGroupOptions) (*policy.Request, error) {
urlPath := "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyDefinitions"
if managementGroupID == "" {
return nil, errors.New("parameter managementGroupID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{managementGroupId}", url.PathEscape(managementGroupID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2021-06-01")
if options != nil && options.Top != nil {
reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10))
}
req.Raw().URL.RawQuery = reqQP.Encode()
unencodedParams := []string{req.Raw().URL.RawQuery}
if options != nil && options.Filter != nil {
unencodedParams = append(unencodedParams, "$filter="+*options.Filter)
}
req.Raw().URL.RawQuery = strings.Join(unencodedParams, "&")
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// listByManagementGroupHandleResponse handles the ListByManagementGroup response.
func (client *DefinitionsClient) listByManagementGroupHandleResponse(resp *http.Response) (DefinitionsClientListByManagementGroupResponse, error) {
result := DefinitionsClientListByManagementGroupResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.DefinitionListResult); err != nil {
return DefinitionsClientListByManagementGroupResponse{}, err
}
return result, nil
}