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 = "2020-09-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 preparer := autorest.CreatePreparer(
94 autorest.AsContentType("application/json; charset=utf-8"),
95 autorest.AsPut(),
96 autorest.WithBaseURL(client.BaseURI),
97 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
98 autorest.WithJSON(parameters),
99 autorest.WithQueryParameters(queryParameters))
100 return preparer.Prepare((&http.Request{}).WithContext(ctx))
101 }
102
103
104
105 func (client AssignmentsClient) CreateSender(req *http.Request) (*http.Response, error) {
106 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
107 }
108
109
110
111 func (client AssignmentsClient) CreateResponder(resp *http.Response) (result Assignment, err error) {
112 err = autorest.Respond(
113 resp,
114 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
115 autorest.ByUnmarshallingJSON(&result),
116 autorest.ByClosing())
117 result.Response = autorest.Response{Response: resp}
118 return
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133 func (client AssignmentsClient) CreateByID(ctx context.Context, policyAssignmentID string, parameters Assignment) (result Assignment, err error) {
134 if tracing.IsEnabled() {
135 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.CreateByID")
136 defer func() {
137 sc := -1
138 if result.Response.Response != nil {
139 sc = result.Response.Response.StatusCode
140 }
141 tracing.EndSpan(ctx, sc, err)
142 }()
143 }
144 req, err := client.CreateByIDPreparer(ctx, policyAssignmentID, parameters)
145 if err != nil {
146 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", nil, "Failure preparing request")
147 return
148 }
149
150 resp, err := client.CreateByIDSender(req)
151 if err != nil {
152 result.Response = autorest.Response{Response: resp}
153 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", resp, "Failure sending request")
154 return
155 }
156
157 result, err = client.CreateByIDResponder(resp)
158 if err != nil {
159 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "CreateByID", resp, "Failure responding to request")
160 return
161 }
162
163 return
164 }
165
166
167 func (client AssignmentsClient) CreateByIDPreparer(ctx context.Context, policyAssignmentID string, parameters Assignment) (*http.Request, error) {
168 pathParameters := map[string]interface{}{
169 "policyAssignmentId": policyAssignmentID,
170 }
171
172 const APIVersion = "2020-09-01"
173 queryParameters := map[string]interface{}{
174 "api-version": APIVersion,
175 }
176
177 parameters.ID = nil
178 parameters.Type = nil
179 parameters.Name = nil
180 preparer := autorest.CreatePreparer(
181 autorest.AsContentType("application/json; charset=utf-8"),
182 autorest.AsPut(),
183 autorest.WithBaseURL(client.BaseURI),
184 autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
185 autorest.WithJSON(parameters),
186 autorest.WithQueryParameters(queryParameters))
187 return preparer.Prepare((&http.Request{}).WithContext(ctx))
188 }
189
190
191
192 func (client AssignmentsClient) CreateByIDSender(req *http.Request) (*http.Response, error) {
193 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
194 }
195
196
197
198 func (client AssignmentsClient) CreateByIDResponder(resp *http.Response) (result Assignment, err error) {
199 err = autorest.Respond(
200 resp,
201 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
202 autorest.ByUnmarshallingJSON(&result),
203 autorest.ByClosing())
204 result.Response = autorest.Response{Response: resp}
205 return
206 }
207
208
209
210
211
212
213
214
215
216
217
218 func (client AssignmentsClient) Delete(ctx context.Context, scope string, policyAssignmentName string) (result Assignment, err error) {
219 if tracing.IsEnabled() {
220 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Delete")
221 defer func() {
222 sc := -1
223 if result.Response.Response != nil {
224 sc = result.Response.Response.StatusCode
225 }
226 tracing.EndSpan(ctx, sc, err)
227 }()
228 }
229 req, err := client.DeletePreparer(ctx, scope, policyAssignmentName)
230 if err != nil {
231 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", nil, "Failure preparing request")
232 return
233 }
234
235 resp, err := client.DeleteSender(req)
236 if err != nil {
237 result.Response = autorest.Response{Response: resp}
238 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", resp, "Failure sending request")
239 return
240 }
241
242 result, err = client.DeleteResponder(resp)
243 if err != nil {
244 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Delete", resp, "Failure responding to request")
245 return
246 }
247
248 return
249 }
250
251
252 func (client AssignmentsClient) DeletePreparer(ctx context.Context, scope string, policyAssignmentName string) (*http.Request, error) {
253 pathParameters := map[string]interface{}{
254 "policyAssignmentName": autorest.Encode("path", policyAssignmentName),
255 "scope": scope,
256 }
257
258 const APIVersion = "2020-09-01"
259 queryParameters := map[string]interface{}{
260 "api-version": APIVersion,
261 }
262
263 preparer := autorest.CreatePreparer(
264 autorest.AsDelete(),
265 autorest.WithBaseURL(client.BaseURI),
266 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
267 autorest.WithQueryParameters(queryParameters))
268 return preparer.Prepare((&http.Request{}).WithContext(ctx))
269 }
270
271
272
273 func (client AssignmentsClient) DeleteSender(req *http.Request) (*http.Response, error) {
274 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
275 }
276
277
278
279 func (client AssignmentsClient) DeleteResponder(resp *http.Response) (result Assignment, err error) {
280 err = autorest.Respond(
281 resp,
282 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
283 autorest.ByUnmarshallingJSON(&result),
284 autorest.ByClosing())
285 result.Response = autorest.Response{Response: resp}
286 return
287 }
288
289
290
291
292
293
294
295
296
297
298
299 func (client AssignmentsClient) DeleteByID(ctx context.Context, policyAssignmentID string) (result Assignment, err error) {
300 if tracing.IsEnabled() {
301 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.DeleteByID")
302 defer func() {
303 sc := -1
304 if result.Response.Response != nil {
305 sc = result.Response.Response.StatusCode
306 }
307 tracing.EndSpan(ctx, sc, err)
308 }()
309 }
310 req, err := client.DeleteByIDPreparer(ctx, policyAssignmentID)
311 if err != nil {
312 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", nil, "Failure preparing request")
313 return
314 }
315
316 resp, err := client.DeleteByIDSender(req)
317 if err != nil {
318 result.Response = autorest.Response{Response: resp}
319 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", resp, "Failure sending request")
320 return
321 }
322
323 result, err = client.DeleteByIDResponder(resp)
324 if err != nil {
325 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "DeleteByID", resp, "Failure responding to request")
326 return
327 }
328
329 return
330 }
331
332
333 func (client AssignmentsClient) DeleteByIDPreparer(ctx context.Context, policyAssignmentID string) (*http.Request, error) {
334 pathParameters := map[string]interface{}{
335 "policyAssignmentId": policyAssignmentID,
336 }
337
338 const APIVersion = "2020-09-01"
339 queryParameters := map[string]interface{}{
340 "api-version": APIVersion,
341 }
342
343 preparer := autorest.CreatePreparer(
344 autorest.AsDelete(),
345 autorest.WithBaseURL(client.BaseURI),
346 autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
347 autorest.WithQueryParameters(queryParameters))
348 return preparer.Prepare((&http.Request{}).WithContext(ctx))
349 }
350
351
352
353 func (client AssignmentsClient) DeleteByIDSender(req *http.Request) (*http.Response, error) {
354 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
355 }
356
357
358
359 func (client AssignmentsClient) DeleteByIDResponder(resp *http.Response) (result Assignment, err error) {
360 err = autorest.Respond(
361 resp,
362 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
363 autorest.ByUnmarshallingJSON(&result),
364 autorest.ByClosing())
365 result.Response = autorest.Response{Response: resp}
366 return
367 }
368
369
370
371
372
373
374
375
376
377 func (client AssignmentsClient) Get(ctx context.Context, scope string, policyAssignmentName string) (result Assignment, err error) {
378 if tracing.IsEnabled() {
379 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.Get")
380 defer func() {
381 sc := -1
382 if result.Response.Response != nil {
383 sc = result.Response.Response.StatusCode
384 }
385 tracing.EndSpan(ctx, sc, err)
386 }()
387 }
388 req, err := client.GetPreparer(ctx, scope, policyAssignmentName)
389 if err != nil {
390 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", nil, "Failure preparing request")
391 return
392 }
393
394 resp, err := client.GetSender(req)
395 if err != nil {
396 result.Response = autorest.Response{Response: resp}
397 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", resp, "Failure sending request")
398 return
399 }
400
401 result, err = client.GetResponder(resp)
402 if err != nil {
403 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "Get", resp, "Failure responding to request")
404 return
405 }
406
407 return
408 }
409
410
411 func (client AssignmentsClient) GetPreparer(ctx context.Context, scope string, policyAssignmentName string) (*http.Request, error) {
412 pathParameters := map[string]interface{}{
413 "policyAssignmentName": autorest.Encode("path", policyAssignmentName),
414 "scope": scope,
415 }
416
417 const APIVersion = "2020-09-01"
418 queryParameters := map[string]interface{}{
419 "api-version": APIVersion,
420 }
421
422 preparer := autorest.CreatePreparer(
423 autorest.AsGet(),
424 autorest.WithBaseURL(client.BaseURI),
425 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}", pathParameters),
426 autorest.WithQueryParameters(queryParameters))
427 return preparer.Prepare((&http.Request{}).WithContext(ctx))
428 }
429
430
431
432 func (client AssignmentsClient) GetSender(req *http.Request) (*http.Response, error) {
433 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
434 }
435
436
437
438 func (client AssignmentsClient) GetResponder(resp *http.Response) (result Assignment, err error) {
439 err = autorest.Respond(
440 resp,
441 azure.WithErrorUnlessStatusCode(http.StatusOK),
442 autorest.ByUnmarshallingJSON(&result),
443 autorest.ByClosing())
444 result.Response = autorest.Response{Response: resp}
445 return
446 }
447
448
449
450
451
452
453
454
455
456
457 func (client AssignmentsClient) GetByID(ctx context.Context, policyAssignmentID string) (result Assignment, err error) {
458 if tracing.IsEnabled() {
459 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.GetByID")
460 defer func() {
461 sc := -1
462 if result.Response.Response != nil {
463 sc = result.Response.Response.StatusCode
464 }
465 tracing.EndSpan(ctx, sc, err)
466 }()
467 }
468 req, err := client.GetByIDPreparer(ctx, policyAssignmentID)
469 if err != nil {
470 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", nil, "Failure preparing request")
471 return
472 }
473
474 resp, err := client.GetByIDSender(req)
475 if err != nil {
476 result.Response = autorest.Response{Response: resp}
477 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", resp, "Failure sending request")
478 return
479 }
480
481 result, err = client.GetByIDResponder(resp)
482 if err != nil {
483 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "GetByID", resp, "Failure responding to request")
484 return
485 }
486
487 return
488 }
489
490
491 func (client AssignmentsClient) GetByIDPreparer(ctx context.Context, policyAssignmentID string) (*http.Request, error) {
492 pathParameters := map[string]interface{}{
493 "policyAssignmentId": policyAssignmentID,
494 }
495
496 const APIVersion = "2020-09-01"
497 queryParameters := map[string]interface{}{
498 "api-version": APIVersion,
499 }
500
501 preparer := autorest.CreatePreparer(
502 autorest.AsGet(),
503 autorest.WithBaseURL(client.BaseURI),
504 autorest.WithPathParameters("/{policyAssignmentId}", pathParameters),
505 autorest.WithQueryParameters(queryParameters))
506 return preparer.Prepare((&http.Request{}).WithContext(ctx))
507 }
508
509
510
511 func (client AssignmentsClient) GetByIDSender(req *http.Request) (*http.Response, error) {
512 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
513 }
514
515
516
517 func (client AssignmentsClient) GetByIDResponder(resp *http.Response) (result Assignment, err error) {
518 err = autorest.Respond(
519 resp,
520 azure.WithErrorUnlessStatusCode(http.StatusOK),
521 autorest.ByUnmarshallingJSON(&result),
522 autorest.ByClosing())
523 result.Response = autorest.Response{Response: resp}
524 return
525 }
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546 func (client AssignmentsClient) List(ctx context.Context, filter string, top *int32) (result AssignmentListResultPage, err error) {
547 if tracing.IsEnabled() {
548 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.List")
549 defer func() {
550 sc := -1
551 if result.alr.Response.Response != nil {
552 sc = result.alr.Response.Response.StatusCode
553 }
554 tracing.EndSpan(ctx, sc, err)
555 }()
556 }
557 if err := validation.Validate([]validation.Validation{
558 {TargetValue: top,
559 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
560 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
561 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
562 }}}}}); err != nil {
563 return result, validation.NewError("policy.AssignmentsClient", "List", err.Error())
564 }
565
566 result.fn = client.listNextResults
567 req, err := client.ListPreparer(ctx, filter, top)
568 if err != nil {
569 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", nil, "Failure preparing request")
570 return
571 }
572
573 resp, err := client.ListSender(req)
574 if err != nil {
575 result.alr.Response = autorest.Response{Response: resp}
576 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", resp, "Failure sending request")
577 return
578 }
579
580 result.alr, err = client.ListResponder(resp)
581 if err != nil {
582 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "List", resp, "Failure responding to request")
583 return
584 }
585 if result.alr.hasNextLink() && result.alr.IsEmpty() {
586 err = result.NextWithContext(ctx)
587 return
588 }
589
590 return
591 }
592
593
594 func (client AssignmentsClient) ListPreparer(ctx context.Context, filter string, top *int32) (*http.Request, error) {
595 pathParameters := map[string]interface{}{
596 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
597 }
598
599 const APIVersion = "2020-09-01"
600 queryParameters := map[string]interface{}{
601 "api-version": APIVersion,
602 }
603 if len(filter) > 0 {
604 queryParameters["$filter"] = filter
605 }
606 if top != nil {
607 queryParameters["$top"] = autorest.Encode("query", *top)
608 }
609
610 preparer := autorest.CreatePreparer(
611 autorest.AsGet(),
612 autorest.WithBaseURL(client.BaseURI),
613 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
614 autorest.WithQueryParameters(queryParameters))
615 return preparer.Prepare((&http.Request{}).WithContext(ctx))
616 }
617
618
619
620 func (client AssignmentsClient) ListSender(req *http.Request) (*http.Response, error) {
621 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
622 }
623
624
625
626 func (client AssignmentsClient) ListResponder(resp *http.Response) (result AssignmentListResult, err error) {
627 err = autorest.Respond(
628 resp,
629 azure.WithErrorUnlessStatusCode(http.StatusOK),
630 autorest.ByUnmarshallingJSON(&result),
631 autorest.ByClosing())
632 result.Response = autorest.Response{Response: resp}
633 return
634 }
635
636
637 func (client AssignmentsClient) listNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
638 req, err := lastResults.assignmentListResultPreparer(ctx)
639 if err != nil {
640 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", nil, "Failure preparing next results request")
641 }
642 if req == nil {
643 return
644 }
645 resp, err := client.ListSender(req)
646 if err != nil {
647 result.Response = autorest.Response{Response: resp}
648 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", resp, "Failure sending next results request")
649 }
650 result, err = client.ListResponder(resp)
651 if err != nil {
652 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listNextResults", resp, "Failure responding to next results request")
653 }
654 return
655 }
656
657
658 func (client AssignmentsClient) ListComplete(ctx context.Context, filter string, top *int32) (result AssignmentListResultIterator, err error) {
659 if tracing.IsEnabled() {
660 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.List")
661 defer func() {
662 sc := -1
663 if result.Response().Response.Response != nil {
664 sc = result.page.Response().Response.Response.StatusCode
665 }
666 tracing.EndSpan(ctx, sc, err)
667 }()
668 }
669 result.page, err = client.List(ctx, filter, top)
670 return
671 }
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690 func (client AssignmentsClient) ListForManagementGroup(ctx context.Context, managementGroupID string, filter string, top *int32) (result AssignmentListResultPage, err error) {
691 if tracing.IsEnabled() {
692 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForManagementGroup")
693 defer func() {
694 sc := -1
695 if result.alr.Response.Response != nil {
696 sc = result.alr.Response.Response.StatusCode
697 }
698 tracing.EndSpan(ctx, sc, err)
699 }()
700 }
701 if err := validation.Validate([]validation.Validation{
702 {TargetValue: top,
703 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
704 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
705 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
706 }}}}}); err != nil {
707 return result, validation.NewError("policy.AssignmentsClient", "ListForManagementGroup", err.Error())
708 }
709
710 result.fn = client.listForManagementGroupNextResults
711 req, err := client.ListForManagementGroupPreparer(ctx, managementGroupID, filter, top)
712 if err != nil {
713 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", nil, "Failure preparing request")
714 return
715 }
716
717 resp, err := client.ListForManagementGroupSender(req)
718 if err != nil {
719 result.alr.Response = autorest.Response{Response: resp}
720 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", resp, "Failure sending request")
721 return
722 }
723
724 result.alr, err = client.ListForManagementGroupResponder(resp)
725 if err != nil {
726 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForManagementGroup", resp, "Failure responding to request")
727 return
728 }
729 if result.alr.hasNextLink() && result.alr.IsEmpty() {
730 err = result.NextWithContext(ctx)
731 return
732 }
733
734 return
735 }
736
737
738 func (client AssignmentsClient) ListForManagementGroupPreparer(ctx context.Context, managementGroupID string, filter string, top *int32) (*http.Request, error) {
739 pathParameters := map[string]interface{}{
740 "managementGroupId": autorest.Encode("path", managementGroupID),
741 }
742
743 const APIVersion = "2020-09-01"
744 queryParameters := map[string]interface{}{
745 "api-version": APIVersion,
746 }
747 if len(filter) > 0 {
748 queryParameters["$filter"] = filter
749 }
750 if top != nil {
751 queryParameters["$top"] = autorest.Encode("query", *top)
752 }
753
754 preparer := autorest.CreatePreparer(
755 autorest.AsGet(),
756 autorest.WithBaseURL(client.BaseURI),
757 autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
758 autorest.WithQueryParameters(queryParameters))
759 return preparer.Prepare((&http.Request{}).WithContext(ctx))
760 }
761
762
763
764 func (client AssignmentsClient) ListForManagementGroupSender(req *http.Request) (*http.Response, error) {
765 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
766 }
767
768
769
770 func (client AssignmentsClient) ListForManagementGroupResponder(resp *http.Response) (result AssignmentListResult, err error) {
771 err = autorest.Respond(
772 resp,
773 azure.WithErrorUnlessStatusCode(http.StatusOK),
774 autorest.ByUnmarshallingJSON(&result),
775 autorest.ByClosing())
776 result.Response = autorest.Response{Response: resp}
777 return
778 }
779
780
781 func (client AssignmentsClient) listForManagementGroupNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
782 req, err := lastResults.assignmentListResultPreparer(ctx)
783 if err != nil {
784 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", nil, "Failure preparing next results request")
785 }
786 if req == nil {
787 return
788 }
789 resp, err := client.ListForManagementGroupSender(req)
790 if err != nil {
791 result.Response = autorest.Response{Response: resp}
792 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", resp, "Failure sending next results request")
793 }
794 result, err = client.ListForManagementGroupResponder(resp)
795 if err != nil {
796 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForManagementGroupNextResults", resp, "Failure responding to next results request")
797 }
798 return
799 }
800
801
802 func (client AssignmentsClient) ListForManagementGroupComplete(ctx context.Context, managementGroupID string, filter string, top *int32) (result AssignmentListResultIterator, err error) {
803 if tracing.IsEnabled() {
804 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForManagementGroup")
805 defer func() {
806 sc := -1
807 if result.Response().Response.Response != nil {
808 sc = result.page.Response().Response.Response.StatusCode
809 }
810 tracing.EndSpan(ctx, sc, err)
811 }()
812 }
813 result.page, err = client.ListForManagementGroup(ctx, managementGroupID, filter, top)
814 return
815 }
816
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 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) {
853 if tracing.IsEnabled() {
854 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResource")
855 defer func() {
856 sc := -1
857 if result.alr.Response.Response != nil {
858 sc = result.alr.Response.Response.StatusCode
859 }
860 tracing.EndSpan(ctx, sc, err)
861 }()
862 }
863 if err := validation.Validate([]validation.Validation{
864 {TargetValue: resourceGroupName,
865 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
866 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
867 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}},
868 {TargetValue: top,
869 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
870 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
871 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
872 }}}}}); err != nil {
873 return result, validation.NewError("policy.AssignmentsClient", "ListForResource", err.Error())
874 }
875
876 result.fn = client.listForResourceNextResults
877 req, err := client.ListForResourcePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter, top)
878 if err != nil {
879 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", nil, "Failure preparing request")
880 return
881 }
882
883 resp, err := client.ListForResourceSender(req)
884 if err != nil {
885 result.alr.Response = autorest.Response{Response: resp}
886 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", resp, "Failure sending request")
887 return
888 }
889
890 result.alr, err = client.ListForResourceResponder(resp)
891 if err != nil {
892 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", resp, "Failure responding to request")
893 return
894 }
895 if result.alr.hasNextLink() && result.alr.IsEmpty() {
896 err = result.NextWithContext(ctx)
897 return
898 }
899
900 return
901 }
902
903
904 func (client AssignmentsClient) ListForResourcePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string, top *int32) (*http.Request, error) {
905 pathParameters := map[string]interface{}{
906 "parentResourcePath": parentResourcePath,
907 "resourceGroupName": autorest.Encode("path", resourceGroupName),
908 "resourceName": autorest.Encode("path", resourceName),
909 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
910 "resourceType": resourceType,
911 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
912 }
913
914 const APIVersion = "2020-09-01"
915 queryParameters := map[string]interface{}{
916 "api-version": APIVersion,
917 }
918 if len(filter) > 0 {
919 queryParameters["$filter"] = filter
920 }
921 if top != nil {
922 queryParameters["$top"] = autorest.Encode("query", *top)
923 }
924
925 preparer := autorest.CreatePreparer(
926 autorest.AsGet(),
927 autorest.WithBaseURL(client.BaseURI),
928 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
929 autorest.WithQueryParameters(queryParameters))
930 return preparer.Prepare((&http.Request{}).WithContext(ctx))
931 }
932
933
934
935 func (client AssignmentsClient) ListForResourceSender(req *http.Request) (*http.Response, error) {
936 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
937 }
938
939
940
941 func (client AssignmentsClient) ListForResourceResponder(resp *http.Response) (result AssignmentListResult, err error) {
942 err = autorest.Respond(
943 resp,
944 azure.WithErrorUnlessStatusCode(http.StatusOK),
945 autorest.ByUnmarshallingJSON(&result),
946 autorest.ByClosing())
947 result.Response = autorest.Response{Response: resp}
948 return
949 }
950
951
952 func (client AssignmentsClient) listForResourceNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
953 req, err := lastResults.assignmentListResultPreparer(ctx)
954 if err != nil {
955 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", nil, "Failure preparing next results request")
956 }
957 if req == nil {
958 return
959 }
960 resp, err := client.ListForResourceSender(req)
961 if err != nil {
962 result.Response = autorest.Response{Response: resp}
963 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", resp, "Failure sending next results request")
964 }
965 result, err = client.ListForResourceResponder(resp)
966 if err != nil {
967 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", resp, "Failure responding to next results request")
968 }
969 return
970 }
971
972
973 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) {
974 if tracing.IsEnabled() {
975 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResource")
976 defer func() {
977 sc := -1
978 if result.Response().Response.Response != nil {
979 sc = result.page.Response().Response.Response.StatusCode
980 }
981 tracing.EndSpan(ctx, sc, err)
982 }()
983 }
984 result.page, err = client.ListForResource(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter, top)
985 return
986 }
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008 func (client AssignmentsClient) ListForResourceGroup(ctx context.Context, resourceGroupName string, filter string, top *int32) (result AssignmentListResultPage, err error) {
1009 if tracing.IsEnabled() {
1010 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResourceGroup")
1011 defer func() {
1012 sc := -1
1013 if result.alr.Response.Response != nil {
1014 sc = result.alr.Response.Response.StatusCode
1015 }
1016 tracing.EndSpan(ctx, sc, err)
1017 }()
1018 }
1019 if err := validation.Validate([]validation.Validation{
1020 {TargetValue: resourceGroupName,
1021 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
1022 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
1023 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}},
1024 {TargetValue: top,
1025 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
1026 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
1027 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
1028 }}}}}); err != nil {
1029 return result, validation.NewError("policy.AssignmentsClient", "ListForResourceGroup", err.Error())
1030 }
1031
1032 result.fn = client.listForResourceGroupNextResults
1033 req, err := client.ListForResourceGroupPreparer(ctx, resourceGroupName, filter, top)
1034 if err != nil {
1035 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", nil, "Failure preparing request")
1036 return
1037 }
1038
1039 resp, err := client.ListForResourceGroupSender(req)
1040 if err != nil {
1041 result.alr.Response = autorest.Response{Response: resp}
1042 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", resp, "Failure sending request")
1043 return
1044 }
1045
1046 result.alr, err = client.ListForResourceGroupResponder(resp)
1047 if err != nil {
1048 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", resp, "Failure responding to request")
1049 return
1050 }
1051 if result.alr.hasNextLink() && result.alr.IsEmpty() {
1052 err = result.NextWithContext(ctx)
1053 return
1054 }
1055
1056 return
1057 }
1058
1059
1060 func (client AssignmentsClient) ListForResourceGroupPreparer(ctx context.Context, resourceGroupName string, filter string, top *int32) (*http.Request, error) {
1061 pathParameters := map[string]interface{}{
1062 "resourceGroupName": autorest.Encode("path", resourceGroupName),
1063 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
1064 }
1065
1066 const APIVersion = "2020-09-01"
1067 queryParameters := map[string]interface{}{
1068 "api-version": APIVersion,
1069 }
1070 if len(filter) > 0 {
1071 queryParameters["$filter"] = filter
1072 }
1073 if top != nil {
1074 queryParameters["$top"] = autorest.Encode("query", *top)
1075 }
1076
1077 preparer := autorest.CreatePreparer(
1078 autorest.AsGet(),
1079 autorest.WithBaseURL(client.BaseURI),
1080 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
1081 autorest.WithQueryParameters(queryParameters))
1082 return preparer.Prepare((&http.Request{}).WithContext(ctx))
1083 }
1084
1085
1086
1087 func (client AssignmentsClient) ListForResourceGroupSender(req *http.Request) (*http.Response, error) {
1088 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
1089 }
1090
1091
1092
1093 func (client AssignmentsClient) ListForResourceGroupResponder(resp *http.Response) (result AssignmentListResult, err error) {
1094 err = autorest.Respond(
1095 resp,
1096 azure.WithErrorUnlessStatusCode(http.StatusOK),
1097 autorest.ByUnmarshallingJSON(&result),
1098 autorest.ByClosing())
1099 result.Response = autorest.Response{Response: resp}
1100 return
1101 }
1102
1103
1104 func (client AssignmentsClient) listForResourceGroupNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
1105 req, err := lastResults.assignmentListResultPreparer(ctx)
1106 if err != nil {
1107 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", nil, "Failure preparing next results request")
1108 }
1109 if req == nil {
1110 return
1111 }
1112 resp, err := client.ListForResourceGroupSender(req)
1113 if err != nil {
1114 result.Response = autorest.Response{Response: resp}
1115 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", resp, "Failure sending next results request")
1116 }
1117 result, err = client.ListForResourceGroupResponder(resp)
1118 if err != nil {
1119 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", resp, "Failure responding to next results request")
1120 }
1121 return
1122 }
1123
1124
1125 func (client AssignmentsClient) ListForResourceGroupComplete(ctx context.Context, resourceGroupName string, filter string, top *int32) (result AssignmentListResultIterator, err error) {
1126 if tracing.IsEnabled() {
1127 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResourceGroup")
1128 defer func() {
1129 sc := -1
1130 if result.Response().Response.Response != nil {
1131 sc = result.page.Response().Response.Response.StatusCode
1132 }
1133 tracing.EndSpan(ctx, sc, err)
1134 }()
1135 }
1136 result.page, err = client.ListForResourceGroup(ctx, resourceGroupName, filter, top)
1137 return
1138 }
1139
View as plain text