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-06-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-06-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-06-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-06-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-06-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-06-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-06-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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696 func (client AssignmentsClient) ListForResource(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (result AssignmentListResultPage, err error) {
697 if tracing.IsEnabled() {
698 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResource")
699 defer func() {
700 sc := -1
701 if result.alr.Response.Response != nil {
702 sc = result.alr.Response.Response.StatusCode
703 }
704 tracing.EndSpan(ctx, sc, err)
705 }()
706 }
707 if err := validation.Validate([]validation.Validation{
708 {TargetValue: resourceGroupName,
709 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
710 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
711 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil {
712 return result, validation.NewError("policy.AssignmentsClient", "ListForResource", err.Error())
713 }
714
715 result.fn = client.listForResourceNextResults
716 req, err := client.ListForResourcePreparer(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter)
717 if err != nil {
718 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", nil, "Failure preparing request")
719 return
720 }
721
722 resp, err := client.ListForResourceSender(req)
723 if err != nil {
724 result.alr.Response = autorest.Response{Response: resp}
725 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", resp, "Failure sending request")
726 return
727 }
728
729 result.alr, err = client.ListForResourceResponder(resp)
730 if err != nil {
731 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResource", resp, "Failure responding to request")
732 return
733 }
734 if result.alr.hasNextLink() && result.alr.IsEmpty() {
735 err = result.NextWithContext(ctx)
736 return
737 }
738
739 return
740 }
741
742
743 func (client AssignmentsClient) ListForResourcePreparer(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (*http.Request, error) {
744 pathParameters := map[string]interface{}{
745 "parentResourcePath": parentResourcePath,
746 "resourceGroupName": autorest.Encode("path", resourceGroupName),
747 "resourceName": autorest.Encode("path", resourceName),
748 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
749 "resourceType": resourceType,
750 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
751 }
752
753 const APIVersion = "2019-06-01"
754 queryParameters := map[string]interface{}{
755 "api-version": APIVersion,
756 }
757 if len(filter) > 0 {
758 queryParameters["$filter"] = autorest.Encode("query", filter)
759 }
760
761 preparer := autorest.CreatePreparer(
762 autorest.AsGet(),
763 autorest.WithBaseURL(client.BaseURI),
764 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
765 autorest.WithQueryParameters(queryParameters))
766 return preparer.Prepare((&http.Request{}).WithContext(ctx))
767 }
768
769
770
771 func (client AssignmentsClient) ListForResourceSender(req *http.Request) (*http.Response, error) {
772 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
773 }
774
775
776
777 func (client AssignmentsClient) ListForResourceResponder(resp *http.Response) (result AssignmentListResult, err error) {
778 err = autorest.Respond(
779 resp,
780 azure.WithErrorUnlessStatusCode(http.StatusOK),
781 autorest.ByUnmarshallingJSON(&result),
782 autorest.ByClosing())
783 result.Response = autorest.Response{Response: resp}
784 return
785 }
786
787
788 func (client AssignmentsClient) listForResourceNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
789 req, err := lastResults.assignmentListResultPreparer(ctx)
790 if err != nil {
791 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", nil, "Failure preparing next results request")
792 }
793 if req == nil {
794 return
795 }
796 resp, err := client.ListForResourceSender(req)
797 if err != nil {
798 result.Response = autorest.Response{Response: resp}
799 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", resp, "Failure sending next results request")
800 }
801 result, err = client.ListForResourceResponder(resp)
802 if err != nil {
803 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceNextResults", resp, "Failure responding to next results request")
804 }
805 return
806 }
807
808
809 func (client AssignmentsClient) ListForResourceComplete(ctx context.Context, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (result AssignmentListResultIterator, err error) {
810 if tracing.IsEnabled() {
811 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResource")
812 defer func() {
813 sc := -1
814 if result.Response().Response.Response != nil {
815 sc = result.page.Response().Response.Response.StatusCode
816 }
817 tracing.EndSpan(ctx, sc, err)
818 }()
819 }
820 result.page, err = client.ListForResource(ctx, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter)
821 return
822 }
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837 func (client AssignmentsClient) ListForResourceGroup(ctx context.Context, resourceGroupName string, filter string) (result AssignmentListResultPage, err error) {
838 if tracing.IsEnabled() {
839 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResourceGroup")
840 defer func() {
841 sc := -1
842 if result.alr.Response.Response != nil {
843 sc = result.alr.Response.Response.StatusCode
844 }
845 tracing.EndSpan(ctx, sc, err)
846 }()
847 }
848 if err := validation.Validate([]validation.Validation{
849 {TargetValue: resourceGroupName,
850 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
851 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
852 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\p{L}\._\(\)\w]+$`, Chain: nil}}}}); err != nil {
853 return result, validation.NewError("policy.AssignmentsClient", "ListForResourceGroup", err.Error())
854 }
855
856 result.fn = client.listForResourceGroupNextResults
857 req, err := client.ListForResourceGroupPreparer(ctx, resourceGroupName, filter)
858 if err != nil {
859 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", nil, "Failure preparing request")
860 return
861 }
862
863 resp, err := client.ListForResourceGroupSender(req)
864 if err != nil {
865 result.alr.Response = autorest.Response{Response: resp}
866 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", resp, "Failure sending request")
867 return
868 }
869
870 result.alr, err = client.ListForResourceGroupResponder(resp)
871 if err != nil {
872 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "ListForResourceGroup", resp, "Failure responding to request")
873 return
874 }
875 if result.alr.hasNextLink() && result.alr.IsEmpty() {
876 err = result.NextWithContext(ctx)
877 return
878 }
879
880 return
881 }
882
883
884 func (client AssignmentsClient) ListForResourceGroupPreparer(ctx context.Context, resourceGroupName string, filter string) (*http.Request, error) {
885 pathParameters := map[string]interface{}{
886 "resourceGroupName": autorest.Encode("path", resourceGroupName),
887 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
888 }
889
890 const APIVersion = "2019-06-01"
891 queryParameters := map[string]interface{}{
892 "api-version": APIVersion,
893 }
894 if len(filter) > 0 {
895 queryParameters["$filter"] = filter
896 }
897
898 preparer := autorest.CreatePreparer(
899 autorest.AsGet(),
900 autorest.WithBaseURL(client.BaseURI),
901 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyAssignments", pathParameters),
902 autorest.WithQueryParameters(queryParameters))
903 return preparer.Prepare((&http.Request{}).WithContext(ctx))
904 }
905
906
907
908 func (client AssignmentsClient) ListForResourceGroupSender(req *http.Request) (*http.Response, error) {
909 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
910 }
911
912
913
914 func (client AssignmentsClient) ListForResourceGroupResponder(resp *http.Response) (result AssignmentListResult, err error) {
915 err = autorest.Respond(
916 resp,
917 azure.WithErrorUnlessStatusCode(http.StatusOK),
918 autorest.ByUnmarshallingJSON(&result),
919 autorest.ByClosing())
920 result.Response = autorest.Response{Response: resp}
921 return
922 }
923
924
925 func (client AssignmentsClient) listForResourceGroupNextResults(ctx context.Context, lastResults AssignmentListResult) (result AssignmentListResult, err error) {
926 req, err := lastResults.assignmentListResultPreparer(ctx)
927 if err != nil {
928 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", nil, "Failure preparing next results request")
929 }
930 if req == nil {
931 return
932 }
933 resp, err := client.ListForResourceGroupSender(req)
934 if err != nil {
935 result.Response = autorest.Response{Response: resp}
936 return result, autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", resp, "Failure sending next results request")
937 }
938 result, err = client.ListForResourceGroupResponder(resp)
939 if err != nil {
940 err = autorest.NewErrorWithError(err, "policy.AssignmentsClient", "listForResourceGroupNextResults", resp, "Failure responding to next results request")
941 }
942 return
943 }
944
945
946 func (client AssignmentsClient) ListForResourceGroupComplete(ctx context.Context, resourceGroupName string, filter string) (result AssignmentListResultIterator, err error) {
947 if tracing.IsEnabled() {
948 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentsClient.ListForResourceGroup")
949 defer func() {
950 sc := -1
951 if result.Response().Response.Response != nil {
952 sc = result.page.Response().Response.Response.StatusCode
953 }
954 tracing.EndSpan(ctx, sc, err)
955 }()
956 }
957 result.page, err = client.ListForResourceGroup(ctx, resourceGroupName, filter)
958 return
959 }
960
View as plain text