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