1 package policy
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type AssignmentsClient struct {
20 BaseClient
21 }
22
23
24 func NewAssignmentsClient(subscriptionID string) AssignmentsClient {
25 return NewAssignmentsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewAssignmentsClientWithBaseURI(baseURI string, subscriptionID string) AssignmentsClient {
31 return AssignmentsClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40
41
42
43
44
45 func (client AssignmentsClient) Create(ctx context.Context, scope string, policyAssignmentName string, parameters Assignment) (result Assignment, err error) {
46 if tracing.IsEnabled() {
47 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Create")
48 defer func() {
49 sc := -1
50 if result.Response.Response != nil {
51 sc = result.Response.Response.StatusCode
52 }
53 tracing.EndSpan(ctx, sc, err)
54 }()
55 }
56 req, err := client.CreatePreparer(ctx, scope, policyAssignmentName, parameters)
57 if err != nil {
58 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Create", nil, "Failure preparing request")
59 return
60 }
61
62 resp, err := client.CreateSender(req)
63 if err != nil {
64 result.Response = autorest.Response{Response: resp}
65 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Create", resp, "Failure sending request")
66 return
67 }
68
69 result, err = client.CreateResponder(resp)
70 if err != nil {
71 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Create", resp, "Failure responding to request")
72 return
73 }
74
75 return
76 }
77
78
79 func (client AssignmentsClient) CreatePreparer(ctx context.Context, scope string, policyAssignmentName string, parameters Assignment) (*http.Request, error) {
80 pathParameters := map[string]interface{}{
81 "policyAssignmentName": autorest.Encode("path", policyAssignmentName),
82 "scope": scope,
83 }
84
85 const APIVersion = "2021-06-01"
86 queryParameters := map[string]interface{}{
87 "api-version": APIVersion,
88 }
89
90 parameters.ID = nil
91 parameters.Type = nil
92 parameters.Name = nil
93 parameters.SystemData = nil
94 preparer := autorest.CreatePreparer(
95 autorest.AsContentType("application/json; charset=utf-8"),
96 autorest.AsPut(),
97 autorest.WithBaseURL(client.BaseURI),
98 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
99 autorest.WithJSON(parameters),
100 autorest.WithQueryParameters(queryParameters))
101 return preparer.Prepare((&http.Request{}).WithContext(ctx))
102 }
103
104
105
106 func (client AssignmentsClient) CreateSender(req *http.Request) (*http.Response, error) {
107 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
108 }
109
110
111
112 func (client AssignmentsClient) CreateResponder(resp *http.Response) (result Assignment, err error) {
113 err = autorest.Respond(
114 resp,
115 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
116 autorest.ByUnmarshallingJSON(&result),
117 autorest.ByClosing())
118 result.Response = autorest.Response{Response: resp}
119 return
120 }
121
122
123
124
125
126
127
128
129
130
131
132
133
134 func (client AssignmentsClient) CreateByID(ctx context.Context, policyAssignmentID string, parameters Assignment) (result Assignment, err error) {
135 if tracing.IsEnabled() {
136 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.CreateByID")
137 defer func() {
138 sc := -1
139 if result.Response.Response != nil {
140 sc = result.Response.Response.StatusCode
141 }
142 tracing.EndSpan(ctx, sc, err)
143 }()
144 }
145 req, err := client.CreateByIDPreparer(ctx, policyAssignmentID, parameters)
146 if err != nil {
147 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", nil, "Failure preparing request")
148 return
149 }
150
151 resp, err := client.CreateByIDSender(req)
152 if err != nil {
153 result.Response = autorest.Response{Response: resp}
154 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", resp, "Failure sending request")
155 return
156 }
157
158 result, err = client.CreateByIDResponder(resp)
159 if err != nil {
160 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", resp, "Failure responding to request")
161 return
162 }
163
164 return
165 }
166
167
168 func (client AssignmentsClient) CreateByIDPreparer(ctx context.Context, policyAssignmentID string, parameters Assignment) (*http.Request, error) {
169 pathParameters := map[string]interface{}{
170 "policyAssignmentId": policyAssignmentID,
171 }
172
173 const APIVersion = "2021-06-01"
174 queryParameters := map[string]interface{}{
175 "api-version": APIVersion,
176 }
177
178 parameters.ID = nil
179 parameters.Type = nil
180 parameters.Name = nil
181 parameters.SystemData = nil
182 preparer := autorest.CreatePreparer(
183 autorest.AsContentType("application/json; charset=utf-8"),
184 autorest.AsPut(),
185 autorest.WithBaseURL(client.BaseURI),
186 autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
187 autorest.WithJSON(parameters),
188 autorest.WithQueryParameters(queryParameters))
189 return preparer.Prepare((&http.Request{}).WithContext(ctx))
190 }
191
192
193
194 func (client AssignmentsClient) CreateByIDSender(req *http.Request) (*http.Response, error) {
195 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
196 }
197
198
199
200 func (client AssignmentsClient) CreateByIDResponder(resp *http.Response) (result Assignment, err error) {
201 err = autorest.Respond(
202 resp,
203 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
204 autorest.ByUnmarshallingJSON(&result),
205 autorest.ByClosing())
206 result.Response = autorest.Response{Response: resp}
207 return
208 }
209
210
211
212
213
214
215
216
217
218
219
220 func (client AssignmentsClient) Delete(ctx context.Context, scope string, policyAssignmentName string) (result Assignment, err error) {
221 if tracing.IsEnabled() {
222 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Delete")
223 defer func() {
224 sc := -1
225 if result.Response.Response != nil {
226 sc = result.Response.Response.StatusCode
227 }
228 tracing.EndSpan(ctx, sc, err)
229 }()
230 }
231 req, err := client.DeletePreparer(ctx, scope, policyAssignmentName)
232 if err != nil {
233 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", nil, "Failure preparing request")
234 return
235 }
236
237 resp, err := client.DeleteSender(req)
238 if err != nil {
239 result.Response = autorest.Response{Response: resp}
240 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", resp, "Failure sending request")
241 return
242 }
243
244 result, err = client.DeleteResponder(resp)
245 if err != nil {
246 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", resp, "Failure responding to request")
247 return
248 }
249
250 return
251 }
252
253
254 func (client AssignmentsClient) DeletePreparer(ctx context.Context, scope string, policyAssignmentName string) (*http.Request, error) {
255 pathParameters := map[string]interface{}{
256 "policyAssignmentName": autorest.Encode("path", policyAssignmentName),
257 "scope": scope,
258 }
259
260 const APIVersion = "2021-06-01"
261 queryParameters := map[string]interface{}{
262 "api-version": APIVersion,
263 }
264
265 preparer := autorest.CreatePreparer(
266 autorest.AsDelete(),
267 autorest.WithBaseURL(client.BaseURI),
268 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
269 autorest.WithQueryParameters(queryParameters))
270 return preparer.Prepare((&http.Request{}).WithContext(ctx))
271 }
272
273
274
275 func (client AssignmentsClient) DeleteSender(req *http.Request) (*http.Response, error) {
276 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
277 }
278
279
280
281 func (client AssignmentsClient) DeleteResponder(resp *http.Response) (result Assignment, err error) {
282 err = autorest.Respond(
283 resp,
284 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
285 autorest.ByUnmarshallingJSON(&result),
286 autorest.ByClosing())
287 result.Response = autorest.Response{Response: resp}
288 return
289 }
290
291
292
293
294
295
296
297
298
299
300
301 func (client AssignmentsClient) DeleteByID(ctx context.Context, policyAssignmentID string) (result Assignment, err error) {
302 if tracing.IsEnabled() {
303 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.DeleteByID")
304 defer func() {
305 sc := -1
306 if result.Response.Response != nil {
307 sc = result.Response.Response.StatusCode
308 }
309 tracing.EndSpan(ctx, sc, err)
310 }()
311 }
312 req, err := client.DeleteByIDPreparer(ctx, policyAssignmentID)
313 if err != nil {
314 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", nil, "Failure preparing request")
315 return
316 }
317
318 resp, err := client.DeleteByIDSender(req)
319 if err != nil {
320 result.Response = autorest.Response{Response: resp}
321 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", resp, "Failure sending request")
322 return
323 }
324
325 result, err = client.DeleteByIDResponder(resp)
326 if err != nil {
327 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", resp, "Failure responding to request")
328 return
329 }
330
331 return
332 }
333
334
335 func (client AssignmentsClient) DeleteByIDPreparer(ctx context.Context, policyAssignmentID string) (*http.Request, error) {
336 pathParameters := map[string]interface{}{
337 "policyAssignmentId": policyAssignmentID,
338 }
339
340 const APIVersion = "2021-06-01"
341 queryParameters := map[string]interface{}{
342 "api-version": APIVersion,
343 }
344
345 preparer := autorest.CreatePreparer(
346 autorest.AsDelete(),
347 autorest.WithBaseURL(client.BaseURI),
348 autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
349 autorest.WithQueryParameters(queryParameters))
350 return preparer.Prepare((&http.Request{}).WithContext(ctx))
351 }
352
353
354
355 func (client AssignmentsClient) DeleteByIDSender(req *http.Request) (*http.Response, error) {
356 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
357 }
358
359
360
361 func (client AssignmentsClient) DeleteByIDResponder(resp *http.Response) (result Assignment, err error) {
362 err = autorest.Respond(
363 resp,
364 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
365 autorest.ByUnmarshallingJSON(&result),
366 autorest.ByClosing())
367 result.Response = autorest.Response{Response: resp}
368 return
369 }
370
371
372
373
374
375
376
377
378
379 func (client AssignmentsClient) Get(ctx context.Context, scope string, policyAssignmentName string) (result Assignment, err error) {
380 if tracing.IsEnabled() {
381 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Get")
382 defer func() {
383 sc := -1
384 if result.Response.Response != nil {
385 sc = result.Response.Response.StatusCode
386 }
387 tracing.EndSpan(ctx, sc, err)
388 }()
389 }
390 req, err := client.GetPreparer(ctx, scope, policyAssignmentName)
391 if err != nil {
392 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", nil, "Failure preparing request")
393 return
394 }
395
396 resp, err := client.GetSender(req)
397 if err != nil {
398 result.Response = autorest.Response{Response: resp}
399 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", resp, "Failure sending request")
400 return
401 }
402
403 result, err = client.GetResponder(resp)
404 if err != nil {
405 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", resp, "Failure responding to request")
406 return
407 }
408
409 return
410 }
411
412
413 func (client AssignmentsClient) GetPreparer(ctx context.Context, scope string, policyAssignmentName string) (*http.Request, error) {
414 pathParameters := map[string]interface{}{
415 "policyAssignmentName": autorest.Encode("path", policyAssignmentName),
416 "scope": scope,
417 }
418
419 const APIVersion = "2021-06-01"
420 queryParameters := map[string]interface{}{
421 "api-version": APIVersion,
422 }
423
424 preparer := autorest.CreatePreparer(
425 autorest.AsGet(),
426 autorest.WithBaseURL(client.BaseURI),
427 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
428 autorest.WithQueryParameters(queryParameters))
429 return preparer.Prepare((&http.Request{}).WithContext(ctx))
430 }
431
432
433
434 func (client AssignmentsClient) GetSender(req *http.Request) (*http.Response, error) {
435 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
436 }
437
438
439
440 func (client AssignmentsClient) GetResponder(resp *http.Response) (result Assignment, err error) {
441 err = autorest.Respond(
442 resp,
443 azure.WithErrorUnlessStatusCode(http.StatusOK),
444 autorest.ByUnmarshallingJSON(&result),
445 autorest.ByClosing())
446 result.Response = autorest.Response{Response: resp}
447 return
448 }
449
450
451
452
453
454
455
456
457
458
459 func (client AssignmentsClient) GetByID(ctx context.Context, policyAssignmentID string) (result Assignment, err error) {
460 if tracing.IsEnabled() {
461 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.GetByID")
462 defer func() {
463 sc := -1
464 if result.Response.Response != nil {
465 sc = result.Response.Response.StatusCode
466 }
467 tracing.EndSpan(ctx, sc, err)
468 }()
469 }
470 req, err := client.GetByIDPreparer(ctx, policyAssignmentID)
471 if err != nil {
472 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", nil, "Failure preparing request")
473 return
474 }
475
476 resp, err := client.GetByIDSender(req)
477 if err != nil {
478 result.Response = autorest.Response{Response: resp}
479 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", resp, "Failure sending request")
480 return
481 }
482
483 result, err = client.GetByIDResponder(resp)
484 if err != nil {
485 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", resp, "Failure responding to request")
486 return
487 }
488
489 return
490 }
491
492
493 func (client AssignmentsClient) GetByIDPreparer(ctx context.Context, policyAssignmentID string) (*http.Request, error) {
494 pathParameters := map[string]interface{}{
495 "policyAssignmentId": policyAssignmentID,
496 }
497
498 const APIVersion = "2021-06-01"
499 queryParameters := map[string]interface{}{
500 "api-version": APIVersion,
501 }
502
503 preparer := autorest.CreatePreparer(
504 autorest.AsGet(),
505 autorest.WithBaseURL(client.BaseURI),
506 autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
507 autorest.WithQueryParameters(queryParameters))
508 return preparer.Prepare((&http.Request{}).WithContext(ctx))
509 }
510
511
512
513 func (client AssignmentsClient) GetByIDSender(req *http.Request) (*http.Response, error) {
514 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
515 }
516
517
518
519 func (client AssignmentsClient) GetByIDResponder(resp *http.Response) (result Assignment, err error) {
520 err = autorest.Respond(
521 resp,
522 azure.WithErrorUnlessStatusCode(http.StatusOK),
523 autorest.ByUnmarshallingJSON(&result),
524 autorest.ByClosing())
525 result.Response = autorest.Response{Response: resp}
526 return
527 }
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548 func (client AssignmentsClient) List(ctx context.Context, filter string, top *int32) (result AssignmentListResultPage, err error) {
549 if tracing.IsEnabled() {
550 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.List")
551 defer func() {
552 sc := -1
553 if result.alr.Response.Response != nil {
554 sc = result.alr.Response.Response.StatusCode
555 }
556 tracing.EndSpan(ctx, sc, err)
557 }()
558 }
559 if err := validation.Validate([]validation.Validation{
560 {TargetValue: top,
561 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
562 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
563 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
564 }}}}}); err != nil {
565 return result, validation.NewError("policy.AssignmentsClient", "List", err.Error())
566 }
567
568 result.fn = client.listNextResults
569 req, err := client.ListPreparer(ctx, filter, top)
570 if err != nil {
571 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", nil, "Failure preparing request")
572 return
573 }
574
575 resp, err := client.ListSender(req)
576 if err != nil {
577 result.alr.Response = autorest.Response{Response: resp}
578 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", resp, "Failure sending request")
579 return
580 }
581
582 result.alr, err = client.ListResponder(resp)
583 if err != nil {
584 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", resp, "Failure responding to request")
585 return
586 }
587 if result.alr.hasNextLink() && result.alr.IsEmpty() {
588 err = result.NextWithContext(ctx)
589 return
590 }
591
592 return
593 }
594
595
596 func (client AssignmentsClient) ListPreparer(ctx context.Context, filter string, top *int32) (*http.Request, error) {
597 pathParameters := map[string]interface{}{
598 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
599 }
600
601 const APIVersion = "2021-06-01"
602 queryParameters := map[string]interface{}{
603 "api-version": APIVersion,
604 }
605 if len(filter) > 0 {
606 queryParameters["$filter"] = filter
607 }
608 if top != nil {
609 queryParameters["$top"] = autorest.Encode("query", *top)
610 }
611
612 preparer := autorest.CreatePreparer(
613 autorest.AsGet(),
614 autorest.WithBaseURL(client.BaseURI),
615 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
616 autorest.WithQueryParameters(queryParameters))
617 return preparer.Prepare((&http.Request{}).WithContext(ctx))
618 }
619
620
621
622 func (client AssignmentsClient) ListSender(req *http.Request) (*http.Response, error) {
623 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
624 }
625
626
627
628 func (client AssignmentsClient) ListResponder(resp *http.Response) (result AssignmentListResult, err error) {
629 err = autorest.Respond(
630 resp,
631 azure.WithErrorUnlessStatusCode(http.StatusOK),
632 autorest.ByUnmarshallingJSON(&result),
633 autorest.ByClosing())
634 result.Response = autorest.Response{Response: resp}
635 return
636 }
637
638
639 func (client AssignmentsClient) listNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
640 req, err := lastResults.assignmentListResultPreparer(ctx)
641 if err != nil {
642 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", nil, "Failure preparing next results request")
643 }
644 if req == nil {
645 return
646 }
647 resp, err := client.ListSender(req)
648 if err != nil {
649 result.Response = autorest.Response{Response: resp}
650 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", resp, "Failure sending next results request")
651 }
652 result, err = client.ListResponder(resp)
653 if err != nil {
654 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", resp, "Failure responding to next results request")
655 }
656 return
657 }
658
659
660 func (client AssignmentsClient) ListComplete(ctx context.Context, filter string, top *int32) (result AssignmentListResultIterator, err error) {
661 if tracing.IsEnabled() {
662 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.List")
663 defer func() {
664 sc := -1
665 if result.Response().Response.Response != nil {
666 sc = result.page.Response().Response.Response.StatusCode
667 }
668 tracing.EndSpan(ctx, sc, err)
669 }()
670 }
671 result.page, err = client.List(ctx, filter, top)
672 return
673 }
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692 func (client AssignmentsClient) ListForManagementGroup(ctx context.Context, managementGroupID string, filter string, top *int32) (result AssignmentListResultPage, err error) {
693 if tracing.IsEnabled() {
694 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForManagementGroup")
695 defer func() {
696 sc := -1
697 if result.alr.Response.Response != nil {
698 sc = result.alr.Response.Response.StatusCode
699 }
700 tracing.EndSpan(ctx, sc, err)
701 }()
702 }
703 if err := validation.Validate([]validation.Validation{
704 {TargetValue: top,
705 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
706 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
707 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
708 }}}}}); err != nil {
709 return result, validation.NewError("policy.AssignmentsClient", "ListForManagementGroup", err.Error())
710 }
711
712 result.fn = client.listForManagementGroupNextResults
713 req, err := client.ListForManagementGroupPreparer(ctx, managementGroupID, filter, top)
714 if err != nil {
715 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", nil, "Failure preparing request")
716 return
717 }
718
719 resp, err := client.ListForManagementGroupSender(req)
720 if err != nil {
721 result.alr.Response = autorest.Response{Response: resp}
722 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", resp, "Failure sending request")
723 return
724 }
725
726 result.alr, err = client.ListForManagementGroupResponder(resp)
727 if err != nil {
728 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", resp, "Failure responding to request")
729 return
730 }
731 if result.alr.hasNextLink() && result.alr.IsEmpty() {
732 err = result.NextWithContext(ctx)
733 return
734 }
735
736 return
737 }
738
739
740 func (client AssignmentsClient) ListForManagementGroupPreparer(ctx context.Context, managementGroupID string, filter string, top *int32) (*http.Request, error) {
741 pathParameters := map[string]interface{}{
742 "managementGroupId": autorest.Encode("path", managementGroupID),
743 }
744
745 const APIVersion = "2021-06-01"
746 queryParameters := map[string]interface{}{
747 "api-version": APIVersion,
748 }
749 if len(filter) > 0 {
750 queryParameters["$filter"] = filter
751 }
752 if top != nil {
753 queryParameters["$top"] = autorest.Encode("query", *top)
754 }
755
756 preparer := autorest.CreatePreparer(
757 autorest.AsGet(),
758 autorest.WithBaseURL(client.BaseURI),
759 autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
760 autorest.WithQueryParameters(queryParameters))
761 return preparer.Prepare((&http.Request{}).WithContext(ctx))
762 }
763
764
765
766 func (client AssignmentsClient) ListForManagementGroupSender(req *http.Request) (*http.Response, error) {
767 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
768 }
769
770
771
772 func (client AssignmentsClient) ListForManagementGroupResponder(resp *http.Response) (result AssignmentListResult, err error) {
773 err = autorest.Respond(
774 resp,
775 azure.WithErrorUnlessStatusCode(http.StatusOK),
776 autorest.ByUnmarshallingJSON(&result),
777 autorest.ByClosing())
778 result.Response = autorest.Response{Response: resp}
779 return
780 }
781
782
783 func (client AssignmentsClient) listForManagementGroupNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
784 req, err := lastResults.assignmentListResultPreparer(ctx)
785 if err != nil {
786 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", nil, "Failure preparing next results request")
787 }
788 if req == nil {
789 return
790 }
791 resp, err := client.ListForManagementGroupSender(req)
792 if err != nil {
793 result.Response = autorest.Response{Response: resp}
794 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", resp, "Failure sending next results request")
795 }
796 result, err = client.ListForManagementGroupResponder(resp)
797 if err != nil {
798 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", resp, "Failure responding to next results request")
799 }
800 return
801 }
802
803
804 func (client AssignmentsClient) ListForManagementGroupComplete(ctx context.Context, managementGroupID string, filter string, top *int32) (result AssignmentListResultIterator, err error) {
805 if tracing.IsEnabled() {
806 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForManagementGroup")
807 defer func() {
808 sc := -1
809 if result.Response().Response.Response != nil {
810 sc = result.page.Response().Response.Response.StatusCode
811 }
812 tracing.EndSpan(ctx, sc, err)
813 }()
814 }
815 result.page, err = client.ListForManagementGroup(ctx, managementGroupID, filter, top)
816 return
817 }
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854 func (client AssignmentsClient) ListForResource(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string, top *int32) (result AssignmentListResultPage, err error) {
855 if tracing.IsEnabled() {
856 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResource")
857 defer func() {
858 sc := -1
859 if result.alr.Response.Response != nil {
860 sc = result.alr.Response.Response.StatusCode
861 }
862 tracing.EndSpan(ctx, sc, err)
863 }()
864 }
865 if err := validation.Validate([]validation.Validation{
866 {TargetValue: resourceGroupName,
867 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
868 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
869 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}},
870 {TargetValue: top,
871 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
872 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
873 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
874 }}}}}); err != nil {
875 return result, validation.NewError("policy.AssignmentsClient", "ListForResource", err.Error())
876 }
877
878 result.fn = client.listForResourceNextResults
879 req, err := client.ListForResourcePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter, top)
880 if err != nil {
881 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", nil, "Failure preparing request")
882 return
883 }
884
885 resp, err := client.ListForResourceSender(req)
886 if err != nil {
887 result.alr.Response = autorest.Response{Response: resp}
888 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", resp, "Failure sending request")
889 return
890 }
891
892 result.alr, err = client.ListForResourceResponder(resp)
893 if err != nil {
894 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", resp, "Failure responding to request")
895 return
896 }
897 if result.alr.hasNextLink() && result.alr.IsEmpty() {
898 err = result.NextWithContext(ctx)
899 return
900 }
901
902 return
903 }
904
905
906 func (client AssignmentsClient) ListForResourcePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string, top *int32) (*http.Request, error) {
907 pathParameters := map[string]interface{}{
908 "parentResourcePath": parentResourcePath,
909 "resourceGroupName": autorest.Encode("path", resourceGroupName),
910 "resourceName": autorest.Encode("path", resourceName),
911 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
912 "resourceType": resourceType,
913 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
914 }
915
916 const APIVersion = "2021-06-01"
917 queryParameters := map[string]interface{}{
918 "api-version": APIVersion,
919 }
920 if len(filter) > 0 {
921 queryParameters["$filter"] = filter
922 }
923 if top != nil {
924 queryParameters["$top"] = autorest.Encode("query", *top)
925 }
926
927 preparer := autorest.CreatePreparer(
928 autorest.AsGet(),
929 autorest.WithBaseURL(client.BaseURI),
930 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
931 autorest.WithQueryParameters(queryParameters))
932 return preparer.Prepare((&http.Request{}).WithContext(ctx))
933 }
934
935
936
937 func (client AssignmentsClient) ListForResourceSender(req *http.Request) (*http.Response, error) {
938 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
939 }
940
941
942
943 func (client AssignmentsClient) ListForResourceResponder(resp *http.Response) (result AssignmentListResult, err error) {
944 err = autorest.Respond(
945 resp,
946 azure.WithErrorUnlessStatusCode(http.StatusOK),
947 autorest.ByUnmarshallingJSON(&result),
948 autorest.ByClosing())
949 result.Response = autorest.Response{Response: resp}
950 return
951 }
952
953
954 func (client AssignmentsClient) listForResourceNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
955 req, err := lastResults.assignmentListResultPreparer(ctx)
956 if err != nil {
957 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", nil, "Failure preparing next results request")
958 }
959 if req == nil {
960 return
961 }
962 resp, err := client.ListForResourceSender(req)
963 if err != nil {
964 result.Response = autorest.Response{Response: resp}
965 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", resp, "Failure sending next results request")
966 }
967 result, err = client.ListForResourceResponder(resp)
968 if err != nil {
969 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", resp, "Failure responding to next results request")
970 }
971 return
972 }
973
974
975 func (client AssignmentsClient) ListForResourceComplete(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string, top *int32) (result AssignmentListResultIterator, err error) {
976 if tracing.IsEnabled() {
977 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResource")
978 defer func() {
979 sc := -1
980 if result.Response().Response.Response != nil {
981 sc = result.page.Response().Response.Response.StatusCode
982 }
983 tracing.EndSpan(ctx, sc, err)
984 }()
985 }
986 result.page, err = client.ListForResource(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter, top)
987 return
988 }
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010 func (client AssignmentsClient) ListForResourceGroup(ctx context.Context, resourceGroupName string, filter string, top *int32) (result AssignmentListResultPage, err error) {
1011 if tracing.IsEnabled() {
1012 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResourceGroup")
1013 defer func() {
1014 sc := -1
1015 if result.alr.Response.Response != nil {
1016 sc = result.alr.Response.Response.StatusCode
1017 }
1018 tracing.EndSpan(ctx, sc, err)
1019 }()
1020 }
1021 if err := validation.Validate([]validation.Validation{
1022 {TargetValue: resourceGroupName,
1023 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
1024 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
1025 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}},
1026 {TargetValue: top,
1027 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
1028 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
1029 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
1030 }}}}}); err != nil {
1031 return result, validation.NewError("policy.AssignmentsClient", "ListForResourceGroup", err.Error())
1032 }
1033
1034 result.fn = client.listForResourceGroupNextResults
1035 req, err := client.ListForResourceGroupPreparer(ctx, resourceGroupName, filter, top)
1036 if err != nil {
1037 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", nil, "Failure preparing request")
1038 return
1039 }
1040
1041 resp, err := client.ListForResourceGroupSender(req)
1042 if err != nil {
1043 result.alr.Response = autorest.Response{Response: resp}
1044 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", resp, "Failure sending request")
1045 return
1046 }
1047
1048 result.alr, err = client.ListForResourceGroupResponder(resp)
1049 if err != nil {
1050 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", resp, "Failure responding to request")
1051 return
1052 }
1053 if result.alr.hasNextLink() && result.alr.IsEmpty() {
1054 err = result.NextWithContext(ctx)
1055 return
1056 }
1057
1058 return
1059 }
1060
1061
1062 func (client AssignmentsClient) ListForResourceGroupPreparer(ctx context.Context, resourceGroupName string, filter string, top *int32) (*http.Request, error) {
1063 pathParameters := map[string]interface{}{
1064 "resourceGroupName": autorest.Encode("path", resourceGroupName),
1065 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
1066 }
1067
1068 const APIVersion = "2021-06-01"
1069 queryParameters := map[string]interface{}{
1070 "api-version": APIVersion,
1071 }
1072 if len(filter) > 0 {
1073 queryParameters["$filter"] = filter
1074 }
1075 if top != nil {
1076 queryParameters["$top"] = autorest.Encode("query", *top)
1077 }
1078
1079 preparer := autorest.CreatePreparer(
1080 autorest.AsGet(),
1081 autorest.WithBaseURL(client.BaseURI),
1082 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
1083 autorest.WithQueryParameters(queryParameters))
1084 return preparer.Prepare((&http.Request{}).WithContext(ctx))
1085 }
1086
1087
1088
1089 func (client AssignmentsClient) ListForResourceGroupSender(req *http.Request) (*http.Response, error) {
1090 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
1091 }
1092
1093
1094
1095 func (client AssignmentsClient) ListForResourceGroupResponder(resp *http.Response) (result AssignmentListResult, err error) {
1096 err = autorest.Respond(
1097 resp,
1098 azure.WithErrorUnlessStatusCode(http.StatusOK),
1099 autorest.ByUnmarshallingJSON(&result),
1100 autorest.ByClosing())
1101 result.Response = autorest.Response{Response: resp}
1102 return
1103 }
1104
1105
1106 func (client AssignmentsClient) listForResourceGroupNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
1107 req, err := lastResults.assignmentListResultPreparer(ctx)
1108 if err != nil {
1109 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", nil, "Failure preparing next results request")
1110 }
1111 if req == nil {
1112 return
1113 }
1114 resp, err := client.ListForResourceGroupSender(req)
1115 if err != nil {
1116 result.Response = autorest.Response{Response: resp}
1117 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", resp, "Failure sending next results request")
1118 }
1119 result, err = client.ListForResourceGroupResponder(resp)
1120 if err != nil {
1121 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", resp, "Failure responding to next results request")
1122 }
1123 return
1124 }
1125
1126
1127 func (client AssignmentsClient) ListForResourceGroupComplete(ctx context.Context, resourceGroupName string, filter string, top *int32) (result AssignmentListResultIterator, err error) {
1128 if tracing.IsEnabled() {
1129 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResourceGroup")
1130 defer func() {
1131 sc := -1
1132 if result.Response().Response.Response != nil {
1133 sc = result.page.Response().Response.Response.StatusCode
1134 }
1135 tracing.EndSpan(ctx, sc, err)
1136 }()
1137 }
1138 result.page, err = client.ListForResourceGroup(ctx, resourceGroupName, filter, top)
1139 return
1140 }
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153 func (client AssignmentsClient) Update(ctx context.Context, scope string, policyAssignmentName string, parameters AssignmentUpdate) (result Assignment, err error) {
1154 if tracing.IsEnabled() {
1155 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Update")
1156 defer func() {
1157 sc := -1
1158 if result.Response.Response != nil {
1159 sc = result.Response.Response.StatusCode
1160 }
1161 tracing.EndSpan(ctx, sc, err)
1162 }()
1163 }
1164 req, err := client.UpdatePreparer(ctx, scope, policyAssignmentName, parameters)
1165 if err != nil {
1166 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Update", nil, "Failure preparing request")
1167 return
1168 }
1169
1170 resp, err := client.UpdateSender(req)
1171 if err != nil {
1172 result.Response = autorest.Response{Response: resp}
1173 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Update", resp, "Failure sending request")
1174 return
1175 }
1176
1177 result, err = client.UpdateResponder(resp)
1178 if err != nil {
1179 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Update", resp, "Failure responding to request")
1180 return
1181 }
1182
1183 return
1184 }
1185
1186
1187 func (client AssignmentsClient) UpdatePreparer(ctx context.Context, scope string, policyAssignmentName string, parameters AssignmentUpdate) (*http.Request, error) {
1188 pathParameters := map[string]interface{}{
1189 "policyAssignmentName": autorest.Encode("path", policyAssignmentName),
1190 "scope": scope,
1191 }
1192
1193 const APIVersion = "2021-06-01"
1194 queryParameters := map[string]interface{}{
1195 "api-version": APIVersion,
1196 }
1197
1198 preparer := autorest.CreatePreparer(
1199 autorest.AsContentType("application/json; charset=utf-8"),
1200 autorest.AsPatch(),
1201 autorest.WithBaseURL(client.BaseURI),
1202 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
1203 autorest.WithJSON(parameters),
1204 autorest.WithQueryParameters(queryParameters))
1205 return preparer.Prepare((&http.Request{}).WithContext(ctx))
1206 }
1207
1208
1209
1210 func (client AssignmentsClient) UpdateSender(req *http.Request) (*http.Response, error) {
1211 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
1212 }
1213
1214
1215
1216 func (client AssignmentsClient) UpdateResponder(resp *http.Response) (result Assignment, err error) {
1217 err = autorest.Respond(
1218 resp,
1219 azure.WithErrorUnlessStatusCode(http.StatusOK),
1220 autorest.ByUnmarshallingJSON(&result),
1221 autorest.ByClosing())
1222 result.Response = autorest.Response{Response: resp}
1223 return
1224 }
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238 func (client AssignmentsClient) UpdateByID(ctx context.Context, policyAssignmentID string, parameters AssignmentUpdate) (result Assignment, err error) {
1239 if tracing.IsEnabled() {
1240 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.UpdateByID")
1241 defer func() {
1242 sc := -1
1243 if result.Response.Response != nil {
1244 sc = result.Response.Response.StatusCode
1245 }
1246 tracing.EndSpan(ctx, sc, err)
1247 }()
1248 }
1249 req, err := client.UpdateByIDPreparer(ctx, policyAssignmentID, parameters)
1250 if err != nil {
1251 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "UpdateByID", nil, "Failure preparing request")
1252 return
1253 }
1254
1255 resp, err := client.UpdateByIDSender(req)
1256 if err != nil {
1257 result.Response = autorest.Response{Response: resp}
1258 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "UpdateByID", resp, "Failure sending request")
1259 return
1260 }
1261
1262 result, err = client.UpdateByIDResponder(resp)
1263 if err != nil {
1264 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "UpdateByID", resp, "Failure responding to request")
1265 return
1266 }
1267
1268 return
1269 }
1270
1271
1272 func (client AssignmentsClient) UpdateByIDPreparer(ctx context.Context, policyAssignmentID string, parameters AssignmentUpdate) (*http.Request, error) {
1273 pathParameters := map[string]interface{}{
1274 "policyAssignmentId": policyAssignmentID,
1275 }
1276
1277 const APIVersion = "2021-06-01"
1278 queryParameters := map[string]interface{}{
1279 "api-version": APIVersion,
1280 }
1281
1282 preparer := autorest.CreatePreparer(
1283 autorest.AsContentType("application/json; charset=utf-8"),
1284 autorest.AsPatch(),
1285 autorest.WithBaseURL(client.BaseURI),
1286 autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
1287 autorest.WithJSON(parameters),
1288 autorest.WithQueryParameters(queryParameters))
1289 return preparer.Prepare((&http.Request{}).WithContext(ctx))
1290 }
1291
1292
1293
1294 func (client AssignmentsClient) UpdateByIDSender(req *http.Request) (*http.Response, error) {
1295 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
1296 }
1297
1298
1299
1300 func (client AssignmentsClient) UpdateByIDResponder(resp *http.Response) (result Assignment, err error) {
1301 err = autorest.Respond(
1302 resp,
1303 azure.WithErrorUnlessStatusCode(http.StatusOK),
1304 autorest.ByUnmarshallingJSON(&result),
1305 autorest.ByClosing())
1306 result.Response = autorest.Response{Response: resp}
1307 return
1308 }
1309
View as plain text