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