1 package policy
2
3
4
5
6
7
8
9 import (
10 "context"
11 "encoding/json"
12 "github.com/Azure/go-autorest/autorest"
13 "github.com/Azure/go-autorest/autorest/to"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 const fqdn = "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-04-01/policy"
20
21
22 type Assignment struct {
23 autorest.Response `json:"-"`
24
25 *AssignmentProperties `json:"properties,omitempty"`
26
27 ID *string `json:"id,omitempty"`
28
29 Type *string `json:"type,omitempty"`
30
31 Name *string `json:"name,omitempty"`
32 }
33
34
35 func (a Assignment) MarshalJSON() ([]byte, error) {
36 objectMap := make(map[string]interface{})
37 if a.AssignmentProperties != nil {
38 objectMap["properties"] = a.AssignmentProperties
39 }
40 if a.ID != nil {
41 objectMap["id"] = a.ID
42 }
43 if a.Type != nil {
44 objectMap["type"] = a.Type
45 }
46 if a.Name != nil {
47 objectMap["name"] = a.Name
48 }
49 return json.Marshal(objectMap)
50 }
51
52
53 func (a *Assignment) UnmarshalJSON(body []byte) error {
54 var m map[string]*json.RawMessage
55 err := json.Unmarshal(body, &m)
56 if err != nil {
57 return err
58 }
59 for k, v := range m {
60 switch k {
61 case "properties":
62 if v != nil {
63 var assignmentProperties AssignmentProperties
64 err = json.Unmarshal(*v, &assignmentProperties)
65 if err != nil {
66 return err
67 }
68 a.AssignmentProperties = &assignmentProperties
69 }
70 case "id":
71 if v != nil {
72 var ID string
73 err = json.Unmarshal(*v, &ID)
74 if err != nil {
75 return err
76 }
77 a.ID = &ID
78 }
79 case "type":
80 if v != nil {
81 var typeVar string
82 err = json.Unmarshal(*v, &typeVar)
83 if err != nil {
84 return err
85 }
86 a.Type = &typeVar
87 }
88 case "name":
89 if v != nil {
90 var name string
91 err = json.Unmarshal(*v, &name)
92 if err != nil {
93 return err
94 }
95 a.Name = &name
96 }
97 }
98 }
99
100 return nil
101 }
102
103
104 type AssignmentListResult struct {
105 autorest.Response `json:"-"`
106
107 Value *[]Assignment `json:"value,omitempty"`
108
109 NextLink *string `json:"nextLink,omitempty"`
110 }
111
112
113 type AssignmentListResultIterator struct {
114 i int
115 page AssignmentListResultPage
116 }
117
118
119
120 func (iter *AssignmentListResultIterator) NextWithContext(ctx context.Context) (err error) {
121 if tracing.IsEnabled() {
122 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentListResultIterator.NextWithContext")
123 defer func() {
124 sc := -1
125 if iter.Response().Response.Response != nil {
126 sc = iter.Response().Response.Response.StatusCode
127 }
128 tracing.EndSpan(ctx, sc, err)
129 }()
130 }
131 iter.i++
132 if iter.i < len(iter.page.Values()) {
133 return nil
134 }
135 err = iter.page.NextWithContext(ctx)
136 if err != nil {
137 iter.i--
138 return err
139 }
140 iter.i = 0
141 return nil
142 }
143
144
145
146
147 func (iter *AssignmentListResultIterator) Next() error {
148 return iter.NextWithContext(context.Background())
149 }
150
151
152 func (iter AssignmentListResultIterator) NotDone() bool {
153 return iter.page.NotDone() && iter.i < len(iter.page.Values())
154 }
155
156
157 func (iter AssignmentListResultIterator) Response() AssignmentListResult {
158 return iter.page.Response()
159 }
160
161
162
163 func (iter AssignmentListResultIterator) Value() Assignment {
164 if !iter.page.NotDone() {
165 return Assignment{}
166 }
167 return iter.page.Values()[iter.i]
168 }
169
170
171 func NewAssignmentListResultIterator(page AssignmentListResultPage) AssignmentListResultIterator {
172 return AssignmentListResultIterator{page: page}
173 }
174
175
176 func (alr AssignmentListResult) IsEmpty() bool {
177 return alr.Value == nil || len(*alr.Value) == 0
178 }
179
180
181 func (alr AssignmentListResult) hasNextLink() bool {
182 return alr.NextLink != nil && len(*alr.NextLink) != 0
183 }
184
185
186
187 func (alr AssignmentListResult) assignmentListResultPreparer(ctx context.Context) (*http.Request, error) {
188 if !alr.hasNextLink() {
189 return nil, nil
190 }
191 return autorest.Prepare((&http.Request{}).WithContext(ctx),
192 autorest.AsJSON(),
193 autorest.AsGet(),
194 autorest.WithBaseURL(to.String(alr.NextLink)))
195 }
196
197
198 type AssignmentListResultPage struct {
199 fn func(context.Context, AssignmentListResult) (AssignmentListResult, error)
200 alr AssignmentListResult
201 }
202
203
204
205 func (page *AssignmentListResultPage) NextWithContext(ctx context.Context) (err error) {
206 if tracing.IsEnabled() {
207 ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentListResultPage.NextWithContext")
208 defer func() {
209 sc := -1
210 if page.Response().Response.Response != nil {
211 sc = page.Response().Response.Response.StatusCode
212 }
213 tracing.EndSpan(ctx, sc, err)
214 }()
215 }
216 for {
217 next, err := page.fn(ctx, page.alr)
218 if err != nil {
219 return err
220 }
221 page.alr = next
222 if !next.hasNextLink() || !next.IsEmpty() {
223 break
224 }
225 }
226 return nil
227 }
228
229
230
231
232 func (page *AssignmentListResultPage) Next() error {
233 return page.NextWithContext(context.Background())
234 }
235
236
237 func (page AssignmentListResultPage) NotDone() bool {
238 return !page.alr.IsEmpty()
239 }
240
241
242 func (page AssignmentListResultPage) Response() AssignmentListResult {
243 return page.alr
244 }
245
246
247 func (page AssignmentListResultPage) Values() []Assignment {
248 if page.alr.IsEmpty() {
249 return nil
250 }
251 return *page.alr.Value
252 }
253
254
255 func NewAssignmentListResultPage(cur AssignmentListResult, getNextPage func(context.Context, AssignmentListResult) (AssignmentListResult, error)) AssignmentListResultPage {
256 return AssignmentListResultPage{
257 fn: getNextPage,
258 alr: cur,
259 }
260 }
261
262
263 type AssignmentProperties struct {
264
265 DisplayName *string `json:"displayName,omitempty"`
266
267 PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"`
268
269 Scope *string `json:"scope,omitempty"`
270 }
271
272
273 type Definition struct {
274 autorest.Response `json:"-"`
275
276 *DefinitionProperties `json:"properties,omitempty"`
277
278 ID *string `json:"id,omitempty"`
279
280 Name *string `json:"name,omitempty"`
281 }
282
283
284 func (d Definition) MarshalJSON() ([]byte, error) {
285 objectMap := make(map[string]interface{})
286 if d.DefinitionProperties != nil {
287 objectMap["properties"] = d.DefinitionProperties
288 }
289 if d.Name != nil {
290 objectMap["name"] = d.Name
291 }
292 return json.Marshal(objectMap)
293 }
294
295
296 func (d *Definition) UnmarshalJSON(body []byte) error {
297 var m map[string]*json.RawMessage
298 err := json.Unmarshal(body, &m)
299 if err != nil {
300 return err
301 }
302 for k, v := range m {
303 switch k {
304 case "properties":
305 if v != nil {
306 var definitionProperties DefinitionProperties
307 err = json.Unmarshal(*v, &definitionProperties)
308 if err != nil {
309 return err
310 }
311 d.DefinitionProperties = &definitionProperties
312 }
313 case "id":
314 if v != nil {
315 var ID string
316 err = json.Unmarshal(*v, &ID)
317 if err != nil {
318 return err
319 }
320 d.ID = &ID
321 }
322 case "name":
323 if v != nil {
324 var name string
325 err = json.Unmarshal(*v, &name)
326 if err != nil {
327 return err
328 }
329 d.Name = &name
330 }
331 }
332 }
333
334 return nil
335 }
336
337
338 type DefinitionListResult struct {
339 autorest.Response `json:"-"`
340
341 Value *[]Definition `json:"value,omitempty"`
342
343 NextLink *string `json:"nextLink,omitempty"`
344 }
345
346
347 type DefinitionListResultIterator struct {
348 i int
349 page DefinitionListResultPage
350 }
351
352
353
354 func (iter *DefinitionListResultIterator) NextWithContext(ctx context.Context) (err error) {
355 if tracing.IsEnabled() {
356 ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionListResultIterator.NextWithContext")
357 defer func() {
358 sc := -1
359 if iter.Response().Response.Response != nil {
360 sc = iter.Response().Response.Response.StatusCode
361 }
362 tracing.EndSpan(ctx, sc, err)
363 }()
364 }
365 iter.i++
366 if iter.i < len(iter.page.Values()) {
367 return nil
368 }
369 err = iter.page.NextWithContext(ctx)
370 if err != nil {
371 iter.i--
372 return err
373 }
374 iter.i = 0
375 return nil
376 }
377
378
379
380
381 func (iter *DefinitionListResultIterator) Next() error {
382 return iter.NextWithContext(context.Background())
383 }
384
385
386 func (iter DefinitionListResultIterator) NotDone() bool {
387 return iter.page.NotDone() && iter.i < len(iter.page.Values())
388 }
389
390
391 func (iter DefinitionListResultIterator) Response() DefinitionListResult {
392 return iter.page.Response()
393 }
394
395
396
397 func (iter DefinitionListResultIterator) Value() Definition {
398 if !iter.page.NotDone() {
399 return Definition{}
400 }
401 return iter.page.Values()[iter.i]
402 }
403
404
405 func NewDefinitionListResultIterator(page DefinitionListResultPage) DefinitionListResultIterator {
406 return DefinitionListResultIterator{page: page}
407 }
408
409
410 func (dlr DefinitionListResult) IsEmpty() bool {
411 return dlr.Value == nil || len(*dlr.Value) == 0
412 }
413
414
415 func (dlr DefinitionListResult) hasNextLink() bool {
416 return dlr.NextLink != nil && len(*dlr.NextLink) != 0
417 }
418
419
420
421 func (dlr DefinitionListResult) definitionListResultPreparer(ctx context.Context) (*http.Request, error) {
422 if !dlr.hasNextLink() {
423 return nil, nil
424 }
425 return autorest.Prepare((&http.Request{}).WithContext(ctx),
426 autorest.AsJSON(),
427 autorest.AsGet(),
428 autorest.WithBaseURL(to.String(dlr.NextLink)))
429 }
430
431
432 type DefinitionListResultPage struct {
433 fn func(context.Context, DefinitionListResult) (DefinitionListResult, error)
434 dlr DefinitionListResult
435 }
436
437
438
439 func (page *DefinitionListResultPage) NextWithContext(ctx context.Context) (err error) {
440 if tracing.IsEnabled() {
441 ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionListResultPage.NextWithContext")
442 defer func() {
443 sc := -1
444 if page.Response().Response.Response != nil {
445 sc = page.Response().Response.Response.StatusCode
446 }
447 tracing.EndSpan(ctx, sc, err)
448 }()
449 }
450 for {
451 next, err := page.fn(ctx, page.dlr)
452 if err != nil {
453 return err
454 }
455 page.dlr = next
456 if !next.hasNextLink() || !next.IsEmpty() {
457 break
458 }
459 }
460 return nil
461 }
462
463
464
465
466 func (page *DefinitionListResultPage) Next() error {
467 return page.NextWithContext(context.Background())
468 }
469
470
471 func (page DefinitionListResultPage) NotDone() bool {
472 return !page.dlr.IsEmpty()
473 }
474
475
476 func (page DefinitionListResultPage) Response() DefinitionListResult {
477 return page.dlr
478 }
479
480
481 func (page DefinitionListResultPage) Values() []Definition {
482 if page.dlr.IsEmpty() {
483 return nil
484 }
485 return *page.dlr.Value
486 }
487
488
489 func NewDefinitionListResultPage(cur DefinitionListResult, getNextPage func(context.Context, DefinitionListResult) (DefinitionListResult, error)) DefinitionListResultPage {
490 return DefinitionListResultPage{
491 fn: getNextPage,
492 dlr: cur,
493 }
494 }
495
496
497 type DefinitionProperties struct {
498
499 PolicyType Type `json:"policyType,omitempty"`
500
501 DisplayName *string `json:"displayName,omitempty"`
502
503 Description *string `json:"description,omitempty"`
504
505 PolicyRule interface{} `json:"policyRule,omitempty"`
506 }
507
View as plain text