1package managementgroups
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"encoding/json"
12	"github.com/Azure/go-autorest/autorest"
13	"github.com/Azure/go-autorest/autorest/date"
14	"github.com/Azure/go-autorest/autorest/to"
15	"github.com/Azure/go-autorest/tracing"
16	"net/http"
17)
18
19// The package's fully qualified name.
20const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2017-11-01-preview/managementgroups"
21
22// ChildInfo the child information of a management group.
23type ChildInfo struct {
24	// ChildType - Possible values include: 'ChildTypeManagementGroup', 'ChildTypeSubscription'
25	ChildType ChildType `json:"childType,omitempty"`
26	// ChildID - The fully qualified ID for the child resource (management group or subscription).  For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000
27	ChildID *string `json:"childId,omitempty"`
28	// DisplayName - The friendly name of the child resource.
29	DisplayName *string `json:"displayName,omitempty"`
30	// Children - The list of children.
31	Children *[]ChildInfo `json:"children,omitempty"`
32}
33
34// CreateManagementGroupRequest management group creation parameters.
35type CreateManagementGroupRequest struct {
36	// DisplayName - The friendly name of the management group.
37	DisplayName *string `json:"displayName,omitempty"`
38	// ParentID - (Optional) The fully qualified ID for the parent management group.  For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000
39	ParentID *string `json:"parentId,omitempty"`
40}
41
42// Details the details of a management group.
43type Details struct {
44	// Version - The version number of the object.
45	Version *float64 `json:"version,omitempty"`
46	// UpdatedTime - The date and time when this object was last updated.
47	UpdatedTime *date.Time `json:"updatedTime,omitempty"`
48	// UpdatedBy - The identity of the principal or process that updated the object.
49	UpdatedBy *string          `json:"updatedBy,omitempty"`
50	Parent    *ParentGroupInfo `json:"parent,omitempty"`
51}
52
53// ErrorDetails the details of the error.
54type ErrorDetails struct {
55	// Code - One of a server-defined set of error codes.
56	Code *string `json:"code,omitempty"`
57	// Message - A human-readable representation of the error.
58	Message *string `json:"message,omitempty"`
59}
60
61// ErrorResponse the error object.
62type ErrorResponse struct {
63	Error *ErrorDetails `json:"error,omitempty"`
64}
65
66// Info the management group resource.
67type Info struct {
68	// ID - READ-ONLY; The fully qualified ID for the management group.  For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000
69	ID *string `json:"id,omitempty"`
70	// Type - READ-ONLY; The type of the resource. For example, /providers/Microsoft.Management/managementGroups
71	Type *string `json:"type,omitempty"`
72	// Name - READ-ONLY; The name of the management group. For example, 00000000-0000-0000-0000-000000000000
73	Name            *string `json:"name,omitempty"`
74	*InfoProperties `json:"properties,omitempty"`
75}
76
77// MarshalJSON is the custom marshaler for Info.
78func (i Info) MarshalJSON() ([]byte, error) {
79	objectMap := make(map[string]interface{})
80	if i.InfoProperties != nil {
81		objectMap["properties"] = i.InfoProperties
82	}
83	return json.Marshal(objectMap)
84}
85
86// UnmarshalJSON is the custom unmarshaler for Info struct.
87func (i *Info) UnmarshalJSON(body []byte) error {
88	var m map[string]*json.RawMessage
89	err := json.Unmarshal(body, &m)
90	if err != nil {
91		return err
92	}
93	for k, v := range m {
94		switch k {
95		case "id":
96			if v != nil {
97				var ID string
98				err = json.Unmarshal(*v, &ID)
99				if err != nil {
100					return err
101				}
102				i.ID = &ID
103			}
104		case "type":
105			if v != nil {
106				var typeVar string
107				err = json.Unmarshal(*v, &typeVar)
108				if err != nil {
109					return err
110				}
111				i.Type = &typeVar
112			}
113		case "name":
114			if v != nil {
115				var name string
116				err = json.Unmarshal(*v, &name)
117				if err != nil {
118					return err
119				}
120				i.Name = &name
121			}
122		case "properties":
123			if v != nil {
124				var infoProperties InfoProperties
125				err = json.Unmarshal(*v, &infoProperties)
126				if err != nil {
127					return err
128				}
129				i.InfoProperties = &infoProperties
130			}
131		}
132	}
133
134	return nil
135}
136
137// InfoProperties the generic properties of a management group.
138type InfoProperties struct {
139	// TenantID - The AAD Tenant ID associated with the management group. For example, 00000000-0000-0000-0000-000000000000
140	TenantID *string `json:"tenantId,omitempty"`
141	// DisplayName - The friendly name of the management group.
142	DisplayName *string `json:"displayName,omitempty"`
143}
144
145// ListResult describes the result of the request to list management groups.
146type ListResult struct {
147	autorest.Response `json:"-"`
148	// Value - The list of management groups.
149	Value *[]Info `json:"value,omitempty"`
150	// NextLink - READ-ONLY; The URL to use for getting the next set of results.
151	NextLink *string `json:"nextLink,omitempty"`
152}
153
154// MarshalJSON is the custom marshaler for ListResult.
155func (lr ListResult) MarshalJSON() ([]byte, error) {
156	objectMap := make(map[string]interface{})
157	if lr.Value != nil {
158		objectMap["value"] = lr.Value
159	}
160	return json.Marshal(objectMap)
161}
162
163// ListResultIterator provides access to a complete listing of Info values.
164type ListResultIterator struct {
165	i    int
166	page ListResultPage
167}
168
169// NextWithContext advances to the next value.  If there was an error making
170// the request the iterator does not advance and the error is returned.
171func (iter *ListResultIterator) NextWithContext(ctx context.Context) (err error) {
172	if tracing.IsEnabled() {
173		ctx = tracing.StartSpan(ctx, fqdn+"/ListResultIterator.NextWithContext")
174		defer func() {
175			sc := -1
176			if iter.Response().Response.Response != nil {
177				sc = iter.Response().Response.Response.StatusCode
178			}
179			tracing.EndSpan(ctx, sc, err)
180		}()
181	}
182	iter.i++
183	if iter.i < len(iter.page.Values()) {
184		return nil
185	}
186	err = iter.page.NextWithContext(ctx)
187	if err != nil {
188		iter.i--
189		return err
190	}
191	iter.i = 0
192	return nil
193}
194
195// Next advances to the next value.  If there was an error making
196// the request the iterator does not advance and the error is returned.
197// Deprecated: Use NextWithContext() instead.
198func (iter *ListResultIterator) Next() error {
199	return iter.NextWithContext(context.Background())
200}
201
202// NotDone returns true if the enumeration should be started or is not yet complete.
203func (iter ListResultIterator) NotDone() bool {
204	return iter.page.NotDone() && iter.i < len(iter.page.Values())
205}
206
207// Response returns the raw server response from the last page request.
208func (iter ListResultIterator) Response() ListResult {
209	return iter.page.Response()
210}
211
212// Value returns the current value or a zero-initialized value if the
213// iterator has advanced beyond the end of the collection.
214func (iter ListResultIterator) Value() Info {
215	if !iter.page.NotDone() {
216		return Info{}
217	}
218	return iter.page.Values()[iter.i]
219}
220
221// Creates a new instance of the ListResultIterator type.
222func NewListResultIterator(page ListResultPage) ListResultIterator {
223	return ListResultIterator{page: page}
224}
225
226// IsEmpty returns true if the ListResult contains no values.
227func (lr ListResult) IsEmpty() bool {
228	return lr.Value == nil || len(*lr.Value) == 0
229}
230
231// hasNextLink returns true if the NextLink is not empty.
232func (lr ListResult) hasNextLink() bool {
233	return lr.NextLink != nil && len(*lr.NextLink) != 0
234}
235
236// listResultPreparer prepares a request to retrieve the next set of results.
237// It returns nil if no more results exist.
238func (lr ListResult) listResultPreparer(ctx context.Context) (*http.Request, error) {
239	if !lr.hasNextLink() {
240		return nil, nil
241	}
242	return autorest.Prepare((&http.Request{}).WithContext(ctx),
243		autorest.AsJSON(),
244		autorest.AsGet(),
245		autorest.WithBaseURL(to.String(lr.NextLink)))
246}
247
248// ListResultPage contains a page of Info values.
249type ListResultPage struct {
250	fn func(context.Context, ListResult) (ListResult, error)
251	lr ListResult
252}
253
254// NextWithContext advances to the next page of values.  If there was an error making
255// the request the page does not advance and the error is returned.
256func (page *ListResultPage) NextWithContext(ctx context.Context) (err error) {
257	if tracing.IsEnabled() {
258		ctx = tracing.StartSpan(ctx, fqdn+"/ListResultPage.NextWithContext")
259		defer func() {
260			sc := -1
261			if page.Response().Response.Response != nil {
262				sc = page.Response().Response.Response.StatusCode
263			}
264			tracing.EndSpan(ctx, sc, err)
265		}()
266	}
267	for {
268		next, err := page.fn(ctx, page.lr)
269		if err != nil {
270			return err
271		}
272		page.lr = next
273		if !next.hasNextLink() || !next.IsEmpty() {
274			break
275		}
276	}
277	return nil
278}
279
280// Next advances to the next page of values.  If there was an error making
281// the request the page does not advance and the error is returned.
282// Deprecated: Use NextWithContext() instead.
283func (page *ListResultPage) Next() error {
284	return page.NextWithContext(context.Background())
285}
286
287// NotDone returns true if the page enumeration should be started or is not yet complete.
288func (page ListResultPage) NotDone() bool {
289	return !page.lr.IsEmpty()
290}
291
292// Response returns the raw server response from the last page request.
293func (page ListResultPage) Response() ListResult {
294	return page.lr
295}
296
297// Values returns the slice of values for the current page or nil if there are no values.
298func (page ListResultPage) Values() []Info {
299	if page.lr.IsEmpty() {
300		return nil
301	}
302	return *page.lr.Value
303}
304
305// Creates a new instance of the ListResultPage type.
306func NewListResultPage(cur ListResult, getNextPage func(context.Context, ListResult) (ListResult, error)) ListResultPage {
307	return ListResultPage{
308		fn: getNextPage,
309		lr: cur,
310	}
311}
312
313// ManagementGroup the management group details.
314type ManagementGroup struct {
315	autorest.Response `json:"-"`
316	// ID - READ-ONLY; The fully qualified ID for the management group.  For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000
317	ID *string `json:"id,omitempty"`
318	// Type - READ-ONLY; The type of the resource.  For example, /providers/Microsoft.Management/managementGroups
319	Type *string `json:"type,omitempty"`
320	// Name - READ-ONLY; The name of the management group. For example, 00000000-0000-0000-0000-000000000000
321	Name        *string `json:"name,omitempty"`
322	*Properties `json:"properties,omitempty"`
323}
324
325// MarshalJSON is the custom marshaler for ManagementGroup.
326func (mg ManagementGroup) MarshalJSON() ([]byte, error) {
327	objectMap := make(map[string]interface{})
328	if mg.Properties != nil {
329		objectMap["properties"] = mg.Properties
330	}
331	return json.Marshal(objectMap)
332}
333
334// UnmarshalJSON is the custom unmarshaler for ManagementGroup struct.
335func (mg *ManagementGroup) UnmarshalJSON(body []byte) error {
336	var m map[string]*json.RawMessage
337	err := json.Unmarshal(body, &m)
338	if err != nil {
339		return err
340	}
341	for k, v := range m {
342		switch k {
343		case "id":
344			if v != nil {
345				var ID string
346				err = json.Unmarshal(*v, &ID)
347				if err != nil {
348					return err
349				}
350				mg.ID = &ID
351			}
352		case "type":
353			if v != nil {
354				var typeVar string
355				err = json.Unmarshal(*v, &typeVar)
356				if err != nil {
357					return err
358				}
359				mg.Type = &typeVar
360			}
361		case "name":
362			if v != nil {
363				var name string
364				err = json.Unmarshal(*v, &name)
365				if err != nil {
366					return err
367				}
368				mg.Name = &name
369			}
370		case "properties":
371			if v != nil {
372				var properties Properties
373				err = json.Unmarshal(*v, &properties)
374				if err != nil {
375					return err
376				}
377				mg.Properties = &properties
378			}
379		}
380	}
381
382	return nil
383}
384
385// Operation operation supported by the Microsoft.Management resource provider.
386type Operation struct {
387	// Name - READ-ONLY; Operation name: {provider}/{resource}/{operation}.
388	Name *string `json:"name,omitempty"`
389	// Display - The object that represents the operation.
390	Display *OperationDisplay `json:"display,omitempty"`
391}
392
393// MarshalJSON is the custom marshaler for Operation.
394func (o Operation) MarshalJSON() ([]byte, error) {
395	objectMap := make(map[string]interface{})
396	if o.Display != nil {
397		objectMap["display"] = o.Display
398	}
399	return json.Marshal(objectMap)
400}
401
402// OperationDisplay the object that represents the operation.
403type OperationDisplay struct {
404	// Provider - READ-ONLY; The name of the provider.
405	Provider *string `json:"provider,omitempty"`
406	// Resource - READ-ONLY; The resource on which the operation is performed.
407	Resource *string `json:"resource,omitempty"`
408	// Operation - READ-ONLY; The operation that can be performed.
409	Operation *string `json:"operation,omitempty"`
410	// Description - READ-ONLY; Operation description.
411	Description *string `json:"description,omitempty"`
412}
413
414// MarshalJSON is the custom marshaler for OperationDisplay.
415func (o OperationDisplay) MarshalJSON() ([]byte, error) {
416	objectMap := make(map[string]interface{})
417	return json.Marshal(objectMap)
418}
419
420// OperationListResult describes the result of the request to list Microsoft.Management operations.
421type OperationListResult struct {
422	autorest.Response `json:"-"`
423	// Value - READ-ONLY; List of operations supported by the Microsoft.Management resource provider.
424	Value *[]Operation `json:"value,omitempty"`
425	// NextLink - READ-ONLY; URL to get the next set of operation list results if there are any.
426	NextLink *string `json:"nextLink,omitempty"`
427}
428
429// MarshalJSON is the custom marshaler for OperationListResult.
430func (olr OperationListResult) MarshalJSON() ([]byte, error) {
431	objectMap := make(map[string]interface{})
432	return json.Marshal(objectMap)
433}
434
435// OperationListResultIterator provides access to a complete listing of Operation values.
436type OperationListResultIterator struct {
437	i    int
438	page OperationListResultPage
439}
440
441// NextWithContext advances to the next value.  If there was an error making
442// the request the iterator does not advance and the error is returned.
443func (iter *OperationListResultIterator) NextWithContext(ctx context.Context) (err error) {
444	if tracing.IsEnabled() {
445		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultIterator.NextWithContext")
446		defer func() {
447			sc := -1
448			if iter.Response().Response.Response != nil {
449				sc = iter.Response().Response.Response.StatusCode
450			}
451			tracing.EndSpan(ctx, sc, err)
452		}()
453	}
454	iter.i++
455	if iter.i < len(iter.page.Values()) {
456		return nil
457	}
458	err = iter.page.NextWithContext(ctx)
459	if err != nil {
460		iter.i--
461		return err
462	}
463	iter.i = 0
464	return nil
465}
466
467// Next advances to the next value.  If there was an error making
468// the request the iterator does not advance and the error is returned.
469// Deprecated: Use NextWithContext() instead.
470func (iter *OperationListResultIterator) Next() error {
471	return iter.NextWithContext(context.Background())
472}
473
474// NotDone returns true if the enumeration should be started or is not yet complete.
475func (iter OperationListResultIterator) NotDone() bool {
476	return iter.page.NotDone() && iter.i < len(iter.page.Values())
477}
478
479// Response returns the raw server response from the last page request.
480func (iter OperationListResultIterator) Response() OperationListResult {
481	return iter.page.Response()
482}
483
484// Value returns the current value or a zero-initialized value if the
485// iterator has advanced beyond the end of the collection.
486func (iter OperationListResultIterator) Value() Operation {
487	if !iter.page.NotDone() {
488		return Operation{}
489	}
490	return iter.page.Values()[iter.i]
491}
492
493// Creates a new instance of the OperationListResultIterator type.
494func NewOperationListResultIterator(page OperationListResultPage) OperationListResultIterator {
495	return OperationListResultIterator{page: page}
496}
497
498// IsEmpty returns true if the ListResult contains no values.
499func (olr OperationListResult) IsEmpty() bool {
500	return olr.Value == nil || len(*olr.Value) == 0
501}
502
503// hasNextLink returns true if the NextLink is not empty.
504func (olr OperationListResult) hasNextLink() bool {
505	return olr.NextLink != nil && len(*olr.NextLink) != 0
506}
507
508// operationListResultPreparer prepares a request to retrieve the next set of results.
509// It returns nil if no more results exist.
510func (olr OperationListResult) operationListResultPreparer(ctx context.Context) (*http.Request, error) {
511	if !olr.hasNextLink() {
512		return nil, nil
513	}
514	return autorest.Prepare((&http.Request{}).WithContext(ctx),
515		autorest.AsJSON(),
516		autorest.AsGet(),
517		autorest.WithBaseURL(to.String(olr.NextLink)))
518}
519
520// OperationListResultPage contains a page of Operation values.
521type OperationListResultPage struct {
522	fn  func(context.Context, OperationListResult) (OperationListResult, error)
523	olr OperationListResult
524}
525
526// NextWithContext advances to the next page of values.  If there was an error making
527// the request the page does not advance and the error is returned.
528func (page *OperationListResultPage) NextWithContext(ctx context.Context) (err error) {
529	if tracing.IsEnabled() {
530		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultPage.NextWithContext")
531		defer func() {
532			sc := -1
533			if page.Response().Response.Response != nil {
534				sc = page.Response().Response.Response.StatusCode
535			}
536			tracing.EndSpan(ctx, sc, err)
537		}()
538	}
539	for {
540		next, err := page.fn(ctx, page.olr)
541		if err != nil {
542			return err
543		}
544		page.olr = next
545		if !next.hasNextLink() || !next.IsEmpty() {
546			break
547		}
548	}
549	return nil
550}
551
552// Next advances to the next page of values.  If there was an error making
553// the request the page does not advance and the error is returned.
554// Deprecated: Use NextWithContext() instead.
555func (page *OperationListResultPage) Next() error {
556	return page.NextWithContext(context.Background())
557}
558
559// NotDone returns true if the page enumeration should be started or is not yet complete.
560func (page OperationListResultPage) NotDone() bool {
561	return !page.olr.IsEmpty()
562}
563
564// Response returns the raw server response from the last page request.
565func (page OperationListResultPage) Response() OperationListResult {
566	return page.olr
567}
568
569// Values returns the slice of values for the current page or nil if there are no values.
570func (page OperationListResultPage) Values() []Operation {
571	if page.olr.IsEmpty() {
572		return nil
573	}
574	return *page.olr.Value
575}
576
577// Creates a new instance of the OperationListResultPage type.
578func NewOperationListResultPage(cur OperationListResult, getNextPage func(context.Context, OperationListResult) (OperationListResult, error)) OperationListResultPage {
579	return OperationListResultPage{
580		fn:  getNextPage,
581		olr: cur,
582	}
583}
584
585// ParentGroupInfo (Optional) The ID of the parent management group.
586type ParentGroupInfo struct {
587	// ParentID - The fully qualified ID for the parent management group.  For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000
588	ParentID *string `json:"parentId,omitempty"`
589	// DisplayName - The friendly name of the parent management group.
590	DisplayName *string `json:"displayName,omitempty"`
591}
592
593// Properties the generic properties of a management group.
594type Properties struct {
595	// TenantID - The AAD Tenant ID associated with the management group. For example, 00000000-0000-0000-0000-000000000000
596	TenantID *string `json:"tenantId,omitempty"`
597	// DisplayName - The friendly name of the management group.
598	DisplayName *string  `json:"displayName,omitempty"`
599	Details     *Details `json:"details,omitempty"`
600	// Children - The list of children.
601	Children *[]ChildInfo `json:"children,omitempty"`
602}
603