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