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