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