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 ExemptionsClient struct {
20 BaseClient
21 }
22
23
24 func NewExemptionsClient() ExemptionsClient {
25 return NewExemptionsClientWithBaseURI(DefaultBaseURI)
26 }
27
28
29
30 func NewExemptionsClientWithBaseURI(baseURI string) ExemptionsClient {
31 return ExemptionsClient{NewWithBaseURI(baseURI)}
32 }
33
34
35
36
37
38
39
40
41
42
43
44
45
46 func (client ExemptionsClient) CreateOrUpdate(ctx context.Context, parameters Exemption, scope string, policyExemptionName string) (result Exemption, err error) {
47 if tracing.IsEnabled() {
48 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.CreateOrUpdate")
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.ExemptionProperties", Name: validation.Null, Rule: true,
60 Chain: []validation.Constraint{{Target: "parameters.ExemptionProperties.PolicyAssignmentID", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
61 return result, validation.NewError("policy.ExemptionsClient", "CreateOrUpdate", err.Error())
62 }
63
64 req, err := client.CreateOrUpdatePreparer(ctx, parameters, scope, policyExemptionName)
65 if err != nil {
66 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "CreateOrUpdate", nil, "Failure preparing request")
67 return
68 }
69
70 resp, err := client.CreateOrUpdateSender(req)
71 if err != nil {
72 result.Response = autorest.Response{Response: resp}
73 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "CreateOrUpdate", resp, "Failure sending request")
74 return
75 }
76
77 result, err = client.CreateOrUpdateResponder(resp)
78 if err != nil {
79 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "CreateOrUpdate", resp, "Failure responding to request")
80 return
81 }
82
83 return
84 }
85
86
87 func (client ExemptionsClient) CreateOrUpdatePreparer(ctx context.Context, parameters Exemption, scope string, policyExemptionName string) (*http.Request, error) {
88 pathParameters := map[string]interface{}{
89 "policyExemptionName": autorest.Encode("path", policyExemptionName),
90 "scope": scope,
91 }
92
93 const APIVersion = "2020-07-01-preview"
94 queryParameters := map[string]interface{}{
95 "api-version": APIVersion,
96 }
97
98 parameters.SystemData = nil
99 preparer := autorest.CreatePreparer(
100 autorest.AsContentType("application/json; charset=utf-8"),
101 autorest.AsPut(),
102 autorest.WithBaseURL(client.BaseURI),
103 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
104 autorest.WithJSON(parameters),
105 autorest.WithQueryParameters(queryParameters))
106 return preparer.Prepare((&http.Request{}).WithContext(ctx))
107 }
108
109
110
111 func (client ExemptionsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
112 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
113 }
114
115
116
117 func (client ExemptionsClient) CreateOrUpdateResponder(resp *http.Response) (result Exemption, err error) {
118 err = autorest.Respond(
119 resp,
120 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
121 autorest.ByUnmarshallingJSON(&result),
122 autorest.ByClosing())
123 result.Response = autorest.Response{Response: resp}
124 return
125 }
126
127
128
129
130
131
132
133
134
135
136
137 func (client ExemptionsClient) Delete(ctx context.Context, scope string, policyExemptionName string) (result autorest.Response, err error) {
138 if tracing.IsEnabled() {
139 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.Delete")
140 defer func() {
141 sc := -1
142 if result.Response != nil {
143 sc = result.Response.StatusCode
144 }
145 tracing.EndSpan(ctx, sc, err)
146 }()
147 }
148 req, err := client.DeletePreparer(ctx, scope, policyExemptionName)
149 if err != nil {
150 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", nil, "Failure preparing request")
151 return
152 }
153
154 resp, err := client.DeleteSender(req)
155 if err != nil {
156 result.Response = resp
157 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", resp, "Failure sending request")
158 return
159 }
160
161 result, err = client.DeleteResponder(resp)
162 if err != nil {
163 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Delete", resp, "Failure responding to request")
164 return
165 }
166
167 return
168 }
169
170
171 func (client ExemptionsClient) DeletePreparer(ctx context.Context, scope string, policyExemptionName string) (*http.Request, error) {
172 pathParameters := map[string]interface{}{
173 "policyExemptionName": autorest.Encode("path", policyExemptionName),
174 "scope": scope,
175 }
176
177 const APIVersion = "2020-07-01-preview"
178 queryParameters := map[string]interface{}{
179 "api-version": APIVersion,
180 }
181
182 preparer := autorest.CreatePreparer(
183 autorest.AsDelete(),
184 autorest.WithBaseURL(client.BaseURI),
185 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
186 autorest.WithQueryParameters(queryParameters))
187 return preparer.Prepare((&http.Request{}).WithContext(ctx))
188 }
189
190
191
192 func (client ExemptionsClient) DeleteSender(req *http.Request) (*http.Response, error) {
193 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
194 }
195
196
197
198 func (client ExemptionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
199 err = autorest.Respond(
200 resp,
201 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
202 autorest.ByClosing())
203 result.Response = resp
204 return
205 }
206
207
208
209
210
211
212
213
214
215 func (client ExemptionsClient) Get(ctx context.Context, scope string, policyExemptionName string) (result Exemption, err error) {
216 if tracing.IsEnabled() {
217 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.Get")
218 defer func() {
219 sc := -1
220 if result.Response.Response != nil {
221 sc = result.Response.Response.StatusCode
222 }
223 tracing.EndSpan(ctx, sc, err)
224 }()
225 }
226 req, err := client.GetPreparer(ctx, scope, policyExemptionName)
227 if err != nil {
228 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", nil, "Failure preparing request")
229 return
230 }
231
232 resp, err := client.GetSender(req)
233 if err != nil {
234 result.Response = autorest.Response{Response: resp}
235 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", resp, "Failure sending request")
236 return
237 }
238
239 result, err = client.GetResponder(resp)
240 if err != nil {
241 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "Get", resp, "Failure responding to request")
242 return
243 }
244
245 return
246 }
247
248
249 func (client ExemptionsClient) GetPreparer(ctx context.Context, scope string, policyExemptionName string) (*http.Request, error) {
250 pathParameters := map[string]interface{}{
251 "policyExemptionName": autorest.Encode("path", policyExemptionName),
252 "scope": scope,
253 }
254
255 const APIVersion = "2020-07-01-preview"
256 queryParameters := map[string]interface{}{
257 "api-version": APIVersion,
258 }
259
260 preparer := autorest.CreatePreparer(
261 autorest.AsGet(),
262 autorest.WithBaseURL(client.BaseURI),
263 autorest.WithPathParameters("/{scope}/providers/Microsoft.Authorization/policyExemptions/{policyExemptionName}", pathParameters),
264 autorest.WithQueryParameters(queryParameters))
265 return preparer.Prepare((&http.Request{}).WithContext(ctx))
266 }
267
268
269
270 func (client ExemptionsClient) GetSender(req *http.Request) (*http.Response, error) {
271 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
272 }
273
274
275
276 func (client ExemptionsClient) GetResponder(resp *http.Response) (result Exemption, err error) {
277 err = autorest.Respond(
278 resp,
279 azure.WithErrorUnlessStatusCode(http.StatusOK),
280 autorest.ByUnmarshallingJSON(&result),
281 autorest.ByClosing())
282 result.Response = autorest.Response{Response: resp}
283 return
284 }
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304 func (client ExemptionsClient) List(ctx context.Context, subscriptionID string, filter string) (result ExemptionListResultPage, err error) {
305 if tracing.IsEnabled() {
306 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.List")
307 defer func() {
308 sc := -1
309 if result.elr.Response.Response != nil {
310 sc = result.elr.Response.Response.StatusCode
311 }
312 tracing.EndSpan(ctx, sc, err)
313 }()
314 }
315 result.fn = client.listNextResults
316 req, err := client.ListPreparer(ctx, subscriptionID, filter)
317 if err != nil {
318 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", nil, "Failure preparing request")
319 return
320 }
321
322 resp, err := client.ListSender(req)
323 if err != nil {
324 result.elr.Response = autorest.Response{Response: resp}
325 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", resp, "Failure sending request")
326 return
327 }
328
329 result.elr, err = client.ListResponder(resp)
330 if err != nil {
331 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "List", resp, "Failure responding to request")
332 return
333 }
334 if result.elr.hasNextLink() && result.elr.IsEmpty() {
335 err = result.NextWithContext(ctx)
336 return
337 }
338
339 return
340 }
341
342
343 func (client ExemptionsClient) ListPreparer(ctx context.Context, subscriptionID string, filter string) (*http.Request, error) {
344 pathParameters := map[string]interface{}{
345 "subscriptionId": autorest.Encode("path", subscriptionID),
346 }
347
348 const APIVersion = "2020-07-01-preview"
349 queryParameters := map[string]interface{}{
350 "api-version": APIVersion,
351 }
352 if len(filter) > 0 {
353 queryParameters["$filter"] = filter
354 }
355
356 preparer := autorest.CreatePreparer(
357 autorest.AsGet(),
358 autorest.WithBaseURL(client.BaseURI),
359 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
360 autorest.WithQueryParameters(queryParameters))
361 return preparer.Prepare((&http.Request{}).WithContext(ctx))
362 }
363
364
365
366 func (client ExemptionsClient) ListSender(req *http.Request) (*http.Response, error) {
367 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
368 }
369
370
371
372 func (client ExemptionsClient) ListResponder(resp *http.Response) (result ExemptionListResult, err error) {
373 err = autorest.Respond(
374 resp,
375 azure.WithErrorUnlessStatusCode(http.StatusOK),
376 autorest.ByUnmarshallingJSON(&result),
377 autorest.ByClosing())
378 result.Response = autorest.Response{Response: resp}
379 return
380 }
381
382
383 func (client ExemptionsClient) listNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
384 req, err := lastResults.exemptionListResultPreparer(ctx)
385 if err != nil {
386 return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", nil, "Failure preparing next results request")
387 }
388 if req == nil {
389 return
390 }
391 resp, err := client.ListSender(req)
392 if err != nil {
393 result.Response = autorest.Response{Response: resp}
394 return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", resp, "Failure sending next results request")
395 }
396 result, err = client.ListResponder(resp)
397 if err != nil {
398 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listNextResults", resp, "Failure responding to next results request")
399 }
400 return
401 }
402
403
404 func (client ExemptionsClient) ListComplete(ctx context.Context, subscriptionID string, filter string) (result ExemptionListResultIterator, err error) {
405 if tracing.IsEnabled() {
406 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.List")
407 defer func() {
408 sc := -1
409 if result.Response().Response.Response != nil {
410 sc = result.page.Response().Response.Response.StatusCode
411 }
412 tracing.EndSpan(ctx, sc, err)
413 }()
414 }
415 result.page, err = client.List(ctx, subscriptionID, filter)
416 return
417 }
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436 func (client ExemptionsClient) ListForManagementGroup(ctx context.Context, managementGroupID string, filter string) (result ExemptionListResultPage, err error) {
437 if tracing.IsEnabled() {
438 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForManagementGroup")
439 defer func() {
440 sc := -1
441 if result.elr.Response.Response != nil {
442 sc = result.elr.Response.Response.StatusCode
443 }
444 tracing.EndSpan(ctx, sc, err)
445 }()
446 }
447 result.fn = client.listForManagementGroupNextResults
448 req, err := client.ListForManagementGroupPreparer(ctx, managementGroupID, filter)
449 if err != nil {
450 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", nil, "Failure preparing request")
451 return
452 }
453
454 resp, err := client.ListForManagementGroupSender(req)
455 if err != nil {
456 result.elr.Response = autorest.Response{Response: resp}
457 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", resp, "Failure sending request")
458 return
459 }
460
461 result.elr, err = client.ListForManagementGroupResponder(resp)
462 if err != nil {
463 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForManagementGroup", resp, "Failure responding to request")
464 return
465 }
466 if result.elr.hasNextLink() && result.elr.IsEmpty() {
467 err = result.NextWithContext(ctx)
468 return
469 }
470
471 return
472 }
473
474
475 func (client ExemptionsClient) ListForManagementGroupPreparer(ctx context.Context, managementGroupID string, filter string) (*http.Request, error) {
476 pathParameters := map[string]interface{}{
477 "managementGroupId": autorest.Encode("path", managementGroupID),
478 }
479
480 const APIVersion = "2020-07-01-preview"
481 queryParameters := map[string]interface{}{
482 "api-version": APIVersion,
483 }
484 if len(filter) > 0 {
485 queryParameters["$filter"] = filter
486 }
487
488 preparer := autorest.CreatePreparer(
489 autorest.AsGet(),
490 autorest.WithBaseURL(client.BaseURI),
491 autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
492 autorest.WithQueryParameters(queryParameters))
493 return preparer.Prepare((&http.Request{}).WithContext(ctx))
494 }
495
496
497
498 func (client ExemptionsClient) ListForManagementGroupSender(req *http.Request) (*http.Response, error) {
499 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
500 }
501
502
503
504 func (client ExemptionsClient) ListForManagementGroupResponder(resp *http.Response) (result ExemptionListResult, err error) {
505 err = autorest.Respond(
506 resp,
507 azure.WithErrorUnlessStatusCode(http.StatusOK),
508 autorest.ByUnmarshallingJSON(&result),
509 autorest.ByClosing())
510 result.Response = autorest.Response{Response: resp}
511 return
512 }
513
514
515 func (client ExemptionsClient) listForManagementGroupNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
516 req, err := lastResults.exemptionListResultPreparer(ctx)
517 if err != nil {
518 return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", nil, "Failure preparing next results request")
519 }
520 if req == nil {
521 return
522 }
523 resp, err := client.ListForManagementGroupSender(req)
524 if err != nil {
525 result.Response = autorest.Response{Response: resp}
526 return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", resp, "Failure sending next results request")
527 }
528 result, err = client.ListForManagementGroupResponder(resp)
529 if err != nil {
530 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForManagementGroupNextResults", resp, "Failure responding to next results request")
531 }
532 return
533 }
534
535
536 func (client ExemptionsClient) ListForManagementGroupComplete(ctx context.Context, managementGroupID string, filter string) (result ExemptionListResultIterator, err error) {
537 if tracing.IsEnabled() {
538 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForManagementGroup")
539 defer func() {
540 sc := -1
541 if result.Response().Response.Response != nil {
542 sc = result.page.Response().Response.Response.StatusCode
543 }
544 tracing.EndSpan(ctx, sc, err)
545 }()
546 }
547 result.page, err = client.ListForManagementGroup(ctx, managementGroupID, filter)
548 return
549 }
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585 func (client ExemptionsClient) ListForResource(ctx context.Context, subscriptionID string, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (result ExemptionListResultPage, err error) {
586 if tracing.IsEnabled() {
587 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResource")
588 defer func() {
589 sc := -1
590 if result.elr.Response.Response != nil {
591 sc = result.elr.Response.Response.StatusCode
592 }
593 tracing.EndSpan(ctx, sc, err)
594 }()
595 }
596 if err := validation.Validate([]validation.Validation{
597 {TargetValue: resourceGroupName,
598 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
599 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
600 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
601 return result, validation.NewError("policy.ExemptionsClient", "ListForResource", err.Error())
602 }
603
604 result.fn = client.listForResourceNextResults
605 req, err := client.ListForResourcePreparer(ctx, subscriptionID, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter)
606 if err != nil {
607 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", nil, "Failure preparing request")
608 return
609 }
610
611 resp, err := client.ListForResourceSender(req)
612 if err != nil {
613 result.elr.Response = autorest.Response{Response: resp}
614 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", resp, "Failure sending request")
615 return
616 }
617
618 result.elr, err = client.ListForResourceResponder(resp)
619 if err != nil {
620 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResource", resp, "Failure responding to request")
621 return
622 }
623 if result.elr.hasNextLink() && result.elr.IsEmpty() {
624 err = result.NextWithContext(ctx)
625 return
626 }
627
628 return
629 }
630
631
632 func (client ExemptionsClient) ListForResourcePreparer(ctx context.Context, subscriptionID string, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (*http.Request, error) {
633 pathParameters := map[string]interface{}{
634 "parentResourcePath": parentResourcePath,
635 "resourceGroupName": autorest.Encode("path", resourceGroupName),
636 "resourceName": autorest.Encode("path", resourceName),
637 "resourceProviderNamespace": autorest.Encode("path", resourceProviderNamespace),
638 "resourceType": resourceType,
639 "subscriptionId": autorest.Encode("path", subscriptionID),
640 }
641
642 const APIVersion = "2020-07-01-preview"
643 queryParameters := map[string]interface{}{
644 "api-version": APIVersion,
645 }
646 if len(filter) > 0 {
647 queryParameters["$filter"] = filter
648 }
649
650 preparer := autorest.CreatePreparer(
651 autorest.AsGet(),
652 autorest.WithBaseURL(client.BaseURI),
653 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
654 autorest.WithQueryParameters(queryParameters))
655 return preparer.Prepare((&http.Request{}).WithContext(ctx))
656 }
657
658
659
660 func (client ExemptionsClient) ListForResourceSender(req *http.Request) (*http.Response, error) {
661 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
662 }
663
664
665
666 func (client ExemptionsClient) ListForResourceResponder(resp *http.Response) (result ExemptionListResult, err error) {
667 err = autorest.Respond(
668 resp,
669 azure.WithErrorUnlessStatusCode(http.StatusOK),
670 autorest.ByUnmarshallingJSON(&result),
671 autorest.ByClosing())
672 result.Response = autorest.Response{Response: resp}
673 return
674 }
675
676
677 func (client ExemptionsClient) listForResourceNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
678 req, err := lastResults.exemptionListResultPreparer(ctx)
679 if err != nil {
680 return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", nil, "Failure preparing next results request")
681 }
682 if req == nil {
683 return
684 }
685 resp, err := client.ListForResourceSender(req)
686 if err != nil {
687 result.Response = autorest.Response{Response: resp}
688 return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", resp, "Failure sending next results request")
689 }
690 result, err = client.ListForResourceResponder(resp)
691 if err != nil {
692 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceNextResults", resp, "Failure responding to next results request")
693 }
694 return
695 }
696
697
698 func (client ExemptionsClient) ListForResourceComplete(ctx context.Context, subscriptionID string, resourceGroupName string, resourceProviderNamespace string, parentResourcePath string, resourceType string, resourceName string, filter string) (result ExemptionListResultIterator, err error) {
699 if tracing.IsEnabled() {
700 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResource")
701 defer func() {
702 sc := -1
703 if result.Response().Response.Response != nil {
704 sc = result.page.Response().Response.Response.StatusCode
705 }
706 tracing.EndSpan(ctx, sc, err)
707 }()
708 }
709 result.page, err = client.ListForResource(ctx, subscriptionID, resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, filter)
710 return
711 }
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732 func (client ExemptionsClient) ListForResourceGroup(ctx context.Context, subscriptionID string, resourceGroupName string, filter string) (result ExemptionListResultPage, err error) {
733 if tracing.IsEnabled() {
734 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResourceGroup")
735 defer func() {
736 sc := -1
737 if result.elr.Response.Response != nil {
738 sc = result.elr.Response.Response.StatusCode
739 }
740 tracing.EndSpan(ctx, sc, err)
741 }()
742 }
743 if err := validation.Validate([]validation.Validation{
744 {TargetValue: resourceGroupName,
745 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
746 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
747 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
748 return result, validation.NewError("policy.ExemptionsClient", "ListForResourceGroup", err.Error())
749 }
750
751 result.fn = client.listForResourceGroupNextResults
752 req, err := client.ListForResourceGroupPreparer(ctx, subscriptionID, resourceGroupName, filter)
753 if err != nil {
754 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResourceGroup", nil, "Failure preparing request")
755 return
756 }
757
758 resp, err := client.ListForResourceGroupSender(req)
759 if err != nil {
760 result.elr.Response = autorest.Response{Response: resp}
761 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResourceGroup", resp, "Failure sending request")
762 return
763 }
764
765 result.elr, err = client.ListForResourceGroupResponder(resp)
766 if err != nil {
767 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "ListForResourceGroup", resp, "Failure responding to request")
768 return
769 }
770 if result.elr.hasNextLink() && result.elr.IsEmpty() {
771 err = result.NextWithContext(ctx)
772 return
773 }
774
775 return
776 }
777
778
779 func (client ExemptionsClient) ListForResourceGroupPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, filter string) (*http.Request, error) {
780 pathParameters := map[string]interface{}{
781 "resourceGroupName": autorest.Encode("path", resourceGroupName),
782 "subscriptionId": autorest.Encode("path", subscriptionID),
783 }
784
785 const APIVersion = "2020-07-01-preview"
786 queryParameters := map[string]interface{}{
787 "api-version": APIVersion,
788 }
789 if len(filter) > 0 {
790 queryParameters["$filter"] = filter
791 }
792
793 preparer := autorest.CreatePreparer(
794 autorest.AsGet(),
795 autorest.WithBaseURL(client.BaseURI),
796 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Authorization/policyExemptions", pathParameters),
797 autorest.WithQueryParameters(queryParameters))
798 return preparer.Prepare((&http.Request{}).WithContext(ctx))
799 }
800
801
802
803 func (client ExemptionsClient) ListForResourceGroupSender(req *http.Request) (*http.Response, error) {
804 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
805 }
806
807
808
809 func (client ExemptionsClient) ListForResourceGroupResponder(resp *http.Response) (result ExemptionListResult, err error) {
810 err = autorest.Respond(
811 resp,
812 azure.WithErrorUnlessStatusCode(http.StatusOK),
813 autorest.ByUnmarshallingJSON(&result),
814 autorest.ByClosing())
815 result.Response = autorest.Response{Response: resp}
816 return
817 }
818
819
820 func (client ExemptionsClient) listForResourceGroupNextResults(ctx context.Context, lastResults ExemptionListResult) (result ExemptionListResult, err error) {
821 req, err := lastResults.exemptionListResultPreparer(ctx)
822 if err != nil {
823 return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceGroupNextResults", nil, "Failure preparing next results request")
824 }
825 if req == nil {
826 return
827 }
828 resp, err := client.ListForResourceGroupSender(req)
829 if err != nil {
830 result.Response = autorest.Response{Response: resp}
831 return result, autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceGroupNextResults", resp, "Failure sending next results request")
832 }
833 result, err = client.ListForResourceGroupResponder(resp)
834 if err != nil {
835 err = autorest.NewErrorWithError(err, "policy.ExemptionsClient", "listForResourceGroupNextResults", resp, "Failure responding to next results request")
836 }
837 return
838 }
839
840
841 func (client ExemptionsClient) ListForResourceGroupComplete(ctx context.Context, subscriptionID string, resourceGroupName string, filter string) (result ExemptionListResultIterator, err error) {
842 if tracing.IsEnabled() {
843 ctx = tracing.StartSpan(ctx, fqdn+"/ExemptionsClient.ListForResourceGroup")
844 defer func() {
845 sc := -1
846 if result.Response().Response.Response != nil {
847 sc = result.page.Response().Response.Response.StatusCode
848 }
849 tracing.EndSpan(ctx, sc, err)
850 }()
851 }
852 result.page, err = client.ListForResourceGroup(ctx, subscriptionID, resourceGroupName, filter)
853 return
854 }
855
View as plain text