1package msi
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"encoding/json"
23	"github.com/Azure/go-autorest/autorest"
24	"github.com/Azure/go-autorest/autorest/to"
25	"github.com/Azure/go-autorest/tracing"
26	"github.com/satori/go.uuid"
27	"net/http"
28)
29
30// The package's fully qualified name.
31const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/msi/mgmt/2015-08-31-preview/msi"
32
33// UserAssignedIdentities enumerates the values for user assigned identities.
34type UserAssignedIdentities string
35
36const (
37	// MicrosoftManagedIdentityuserAssignedIdentities ...
38	MicrosoftManagedIdentityuserAssignedIdentities UserAssignedIdentities = "Microsoft.ManagedIdentity/userAssignedIdentities"
39)
40
41// PossibleUserAssignedIdentitiesValues returns an array of possible values for the UserAssignedIdentities const type.
42func PossibleUserAssignedIdentitiesValues() []UserAssignedIdentities {
43	return []UserAssignedIdentities{MicrosoftManagedIdentityuserAssignedIdentities}
44}
45
46// CloudError an error response from the ManagedServiceIdentity service.
47type CloudError struct {
48	// Error - A list of additional details about the error.
49	Error *CloudErrorBody `json:"error,omitempty"`
50}
51
52// CloudErrorBody an error response from the ManagedServiceIdentity service.
53type CloudErrorBody struct {
54	// Code - An identifier for the error.
55	Code *string `json:"code,omitempty"`
56	// Message - A message describing the error, intended to be suitable for display in a user interface.
57	Message *string `json:"message,omitempty"`
58	// Target - The target of the particular error. For example, the name of the property in error.
59	Target *string `json:"target,omitempty"`
60	// Details - A list of additional details about the error.
61	Details *[]CloudErrorBody `json:"details,omitempty"`
62}
63
64// Identity describes an identity resource.
65type Identity struct {
66	autorest.Response `json:"-"`
67	// ID - READ-ONLY; The id of the created identity.
68	ID *string `json:"id,omitempty"`
69	// Name - READ-ONLY; The name of the created identity.
70	Name *string `json:"name,omitempty"`
71	// Location - The Azure region where the identity lives.
72	Location *string `json:"location,omitempty"`
73	// Tags - Resource tags
74	Tags map[string]*string `json:"tags"`
75	// IdentityProperties - The properties associated with the identity.
76	*IdentityProperties `json:"properties,omitempty"`
77	// Type - READ-ONLY; The type of resource i.e. Microsoft.ManagedIdentity/userAssignedIdentities. Possible values include: 'MicrosoftManagedIdentityuserAssignedIdentities'
78	Type UserAssignedIdentities `json:"type,omitempty"`
79}
80
81// MarshalJSON is the custom marshaler for Identity.
82func (i Identity) MarshalJSON() ([]byte, error) {
83	objectMap := make(map[string]interface{})
84	if i.Location != nil {
85		objectMap["location"] = i.Location
86	}
87	if i.Tags != nil {
88		objectMap["tags"] = i.Tags
89	}
90	if i.IdentityProperties != nil {
91		objectMap["properties"] = i.IdentityProperties
92	}
93	return json.Marshal(objectMap)
94}
95
96// UnmarshalJSON is the custom unmarshaler for Identity struct.
97func (i *Identity) UnmarshalJSON(body []byte) error {
98	var m map[string]*json.RawMessage
99	err := json.Unmarshal(body, &m)
100	if err != nil {
101		return err
102	}
103	for k, v := range m {
104		switch k {
105		case "id":
106			if v != nil {
107				var ID string
108				err = json.Unmarshal(*v, &ID)
109				if err != nil {
110					return err
111				}
112				i.ID = &ID
113			}
114		case "name":
115			if v != nil {
116				var name string
117				err = json.Unmarshal(*v, &name)
118				if err != nil {
119					return err
120				}
121				i.Name = &name
122			}
123		case "location":
124			if v != nil {
125				var location string
126				err = json.Unmarshal(*v, &location)
127				if err != nil {
128					return err
129				}
130				i.Location = &location
131			}
132		case "tags":
133			if v != nil {
134				var tags map[string]*string
135				err = json.Unmarshal(*v, &tags)
136				if err != nil {
137					return err
138				}
139				i.Tags = tags
140			}
141		case "properties":
142			if v != nil {
143				var identityProperties IdentityProperties
144				err = json.Unmarshal(*v, &identityProperties)
145				if err != nil {
146					return err
147				}
148				i.IdentityProperties = &identityProperties
149			}
150		case "type":
151			if v != nil {
152				var typeVar UserAssignedIdentities
153				err = json.Unmarshal(*v, &typeVar)
154				if err != nil {
155					return err
156				}
157				i.Type = typeVar
158			}
159		}
160	}
161
162	return nil
163}
164
165// IdentityProperties the properties associated with the identity.
166type IdentityProperties struct {
167	// TenantID - READ-ONLY; The id of the tenant which the identity belongs to.
168	TenantID *uuid.UUID `json:"tenantId,omitempty"`
169	// PrincipalID - READ-ONLY; The id of the service principal object associated with the created identity.
170	PrincipalID *uuid.UUID `json:"principalId,omitempty"`
171	// ClientID - READ-ONLY; The id of the app associated with the identity. This is a random generated UUID by MSI.
172	ClientID *uuid.UUID `json:"clientId,omitempty"`
173	// ClientSecretURL - READ-ONLY;  The ManagedServiceIdentity DataPlane URL that can be queried to obtain the identity credentials.
174	ClientSecretURL *string `json:"clientSecretUrl,omitempty"`
175}
176
177// Operation operation supported by the Microsoft.ManagedIdentity REST API.
178type Operation struct {
179	// Name - The name of the REST Operation. This is of the format {provider}/{resource}/{operation}.
180	Name *string `json:"name,omitempty"`
181	// Display - The object that describes the operation.
182	Display *OperationDisplay `json:"display,omitempty"`
183}
184
185// OperationDisplay the object that describes the operation.
186type OperationDisplay struct {
187	// Provider - Friendly name of the resource provider.
188	Provider *string `json:"provider,omitempty"`
189	// Operation - The type of operation. For example: read, write, delete.
190	Operation *string `json:"operation,omitempty"`
191	// Resource - The resource type on which the operation is performed.
192	Resource *string `json:"resource,omitempty"`
193	// Description - A description of the operation.
194	Description *string `json:"description,omitempty"`
195}
196
197// OperationListResult a list of operations supported by Microsoft.ManagedIdentity Resource Provider.
198type OperationListResult struct {
199	autorest.Response `json:"-"`
200	// Value - A list of operations supported by Microsoft.ManagedIdentity Resource Provider.
201	Value *[]Operation `json:"value,omitempty"`
202	// NextLink - The url to get the next page of results, if any.
203	NextLink *string `json:"nextLink,omitempty"`
204}
205
206// OperationListResultIterator provides access to a complete listing of Operation values.
207type OperationListResultIterator struct {
208	i    int
209	page OperationListResultPage
210}
211
212// NextWithContext advances to the next value.  If there was an error making
213// the request the iterator does not advance and the error is returned.
214func (iter *OperationListResultIterator) NextWithContext(ctx context.Context) (err error) {
215	if tracing.IsEnabled() {
216		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultIterator.NextWithContext")
217		defer func() {
218			sc := -1
219			if iter.Response().Response.Response != nil {
220				sc = iter.Response().Response.Response.StatusCode
221			}
222			tracing.EndSpan(ctx, sc, err)
223		}()
224	}
225	iter.i++
226	if iter.i < len(iter.page.Values()) {
227		return nil
228	}
229	err = iter.page.NextWithContext(ctx)
230	if err != nil {
231		iter.i--
232		return err
233	}
234	iter.i = 0
235	return nil
236}
237
238// Next advances to the next value.  If there was an error making
239// the request the iterator does not advance and the error is returned.
240// Deprecated: Use NextWithContext() instead.
241func (iter *OperationListResultIterator) Next() error {
242	return iter.NextWithContext(context.Background())
243}
244
245// NotDone returns true if the enumeration should be started or is not yet complete.
246func (iter OperationListResultIterator) NotDone() bool {
247	return iter.page.NotDone() && iter.i < len(iter.page.Values())
248}
249
250// Response returns the raw server response from the last page request.
251func (iter OperationListResultIterator) Response() OperationListResult {
252	return iter.page.Response()
253}
254
255// Value returns the current value or a zero-initialized value if the
256// iterator has advanced beyond the end of the collection.
257func (iter OperationListResultIterator) Value() Operation {
258	if !iter.page.NotDone() {
259		return Operation{}
260	}
261	return iter.page.Values()[iter.i]
262}
263
264// Creates a new instance of the OperationListResultIterator type.
265func NewOperationListResultIterator(page OperationListResultPage) OperationListResultIterator {
266	return OperationListResultIterator{page: page}
267}
268
269// IsEmpty returns true if the ListResult contains no values.
270func (olr OperationListResult) IsEmpty() bool {
271	return olr.Value == nil || len(*olr.Value) == 0
272}
273
274// operationListResultPreparer prepares a request to retrieve the next set of results.
275// It returns nil if no more results exist.
276func (olr OperationListResult) operationListResultPreparer(ctx context.Context) (*http.Request, error) {
277	if olr.NextLink == nil || len(to.String(olr.NextLink)) < 1 {
278		return nil, nil
279	}
280	return autorest.Prepare((&http.Request{}).WithContext(ctx),
281		autorest.AsJSON(),
282		autorest.AsGet(),
283		autorest.WithBaseURL(to.String(olr.NextLink)))
284}
285
286// OperationListResultPage contains a page of Operation values.
287type OperationListResultPage struct {
288	fn  func(context.Context, OperationListResult) (OperationListResult, error)
289	olr OperationListResult
290}
291
292// NextWithContext advances to the next page of values.  If there was an error making
293// the request the page does not advance and the error is returned.
294func (page *OperationListResultPage) NextWithContext(ctx context.Context) (err error) {
295	if tracing.IsEnabled() {
296		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultPage.NextWithContext")
297		defer func() {
298			sc := -1
299			if page.Response().Response.Response != nil {
300				sc = page.Response().Response.Response.StatusCode
301			}
302			tracing.EndSpan(ctx, sc, err)
303		}()
304	}
305	next, err := page.fn(ctx, page.olr)
306	if err != nil {
307		return err
308	}
309	page.olr = next
310	return nil
311}
312
313// Next advances to the next page of values.  If there was an error making
314// the request the page does not advance and the error is returned.
315// Deprecated: Use NextWithContext() instead.
316func (page *OperationListResultPage) Next() error {
317	return page.NextWithContext(context.Background())
318}
319
320// NotDone returns true if the page enumeration should be started or is not yet complete.
321func (page OperationListResultPage) NotDone() bool {
322	return !page.olr.IsEmpty()
323}
324
325// Response returns the raw server response from the last page request.
326func (page OperationListResultPage) Response() OperationListResult {
327	return page.olr
328}
329
330// Values returns the slice of values for the current page or nil if there are no values.
331func (page OperationListResultPage) Values() []Operation {
332	if page.olr.IsEmpty() {
333		return nil
334	}
335	return *page.olr.Value
336}
337
338// Creates a new instance of the OperationListResultPage type.
339func NewOperationListResultPage(getNextPage func(context.Context, OperationListResult) (OperationListResult, error)) OperationListResultPage {
340	return OperationListResultPage{fn: getNextPage}
341}
342
343// UserAssignedIdentitiesListResult values returned by the List operation.
344type UserAssignedIdentitiesListResult struct {
345	autorest.Response `json:"-"`
346	// Value - The collection of userAssignedIdentities returned by the listing operation.
347	Value *[]Identity `json:"value,omitempty"`
348	// NextLink - The url to get the next page of results, if any.
349	NextLink *string `json:"nextLink,omitempty"`
350}
351
352// UserAssignedIdentitiesListResultIterator provides access to a complete listing of Identity values.
353type UserAssignedIdentitiesListResultIterator struct {
354	i    int
355	page UserAssignedIdentitiesListResultPage
356}
357
358// NextWithContext advances to the next value.  If there was an error making
359// the request the iterator does not advance and the error is returned.
360func (iter *UserAssignedIdentitiesListResultIterator) NextWithContext(ctx context.Context) (err error) {
361	if tracing.IsEnabled() {
362		ctx = tracing.StartSpan(ctx, fqdn+"/UserAssignedIdentitiesListResultIterator.NextWithContext")
363		defer func() {
364			sc := -1
365			if iter.Response().Response.Response != nil {
366				sc = iter.Response().Response.Response.StatusCode
367			}
368			tracing.EndSpan(ctx, sc, err)
369		}()
370	}
371	iter.i++
372	if iter.i < len(iter.page.Values()) {
373		return nil
374	}
375	err = iter.page.NextWithContext(ctx)
376	if err != nil {
377		iter.i--
378		return err
379	}
380	iter.i = 0
381	return nil
382}
383
384// Next advances to the next value.  If there was an error making
385// the request the iterator does not advance and the error is returned.
386// Deprecated: Use NextWithContext() instead.
387func (iter *UserAssignedIdentitiesListResultIterator) Next() error {
388	return iter.NextWithContext(context.Background())
389}
390
391// NotDone returns true if the enumeration should be started or is not yet complete.
392func (iter UserAssignedIdentitiesListResultIterator) NotDone() bool {
393	return iter.page.NotDone() && iter.i < len(iter.page.Values())
394}
395
396// Response returns the raw server response from the last page request.
397func (iter UserAssignedIdentitiesListResultIterator) Response() UserAssignedIdentitiesListResult {
398	return iter.page.Response()
399}
400
401// Value returns the current value or a zero-initialized value if the
402// iterator has advanced beyond the end of the collection.
403func (iter UserAssignedIdentitiesListResultIterator) Value() Identity {
404	if !iter.page.NotDone() {
405		return Identity{}
406	}
407	return iter.page.Values()[iter.i]
408}
409
410// Creates a new instance of the UserAssignedIdentitiesListResultIterator type.
411func NewUserAssignedIdentitiesListResultIterator(page UserAssignedIdentitiesListResultPage) UserAssignedIdentitiesListResultIterator {
412	return UserAssignedIdentitiesListResultIterator{page: page}
413}
414
415// IsEmpty returns true if the ListResult contains no values.
416func (uailr UserAssignedIdentitiesListResult) IsEmpty() bool {
417	return uailr.Value == nil || len(*uailr.Value) == 0
418}
419
420// userAssignedIdentitiesListResultPreparer prepares a request to retrieve the next set of results.
421// It returns nil if no more results exist.
422func (uailr UserAssignedIdentitiesListResult) userAssignedIdentitiesListResultPreparer(ctx context.Context) (*http.Request, error) {
423	if uailr.NextLink == nil || len(to.String(uailr.NextLink)) < 1 {
424		return nil, nil
425	}
426	return autorest.Prepare((&http.Request{}).WithContext(ctx),
427		autorest.AsJSON(),
428		autorest.AsGet(),
429		autorest.WithBaseURL(to.String(uailr.NextLink)))
430}
431
432// UserAssignedIdentitiesListResultPage contains a page of Identity values.
433type UserAssignedIdentitiesListResultPage struct {
434	fn    func(context.Context, UserAssignedIdentitiesListResult) (UserAssignedIdentitiesListResult, error)
435	uailr UserAssignedIdentitiesListResult
436}
437
438// NextWithContext advances to the next page of values.  If there was an error making
439// the request the page does not advance and the error is returned.
440func (page *UserAssignedIdentitiesListResultPage) NextWithContext(ctx context.Context) (err error) {
441	if tracing.IsEnabled() {
442		ctx = tracing.StartSpan(ctx, fqdn+"/UserAssignedIdentitiesListResultPage.NextWithContext")
443		defer func() {
444			sc := -1
445			if page.Response().Response.Response != nil {
446				sc = page.Response().Response.Response.StatusCode
447			}
448			tracing.EndSpan(ctx, sc, err)
449		}()
450	}
451	next, err := page.fn(ctx, page.uailr)
452	if err != nil {
453		return err
454	}
455	page.uailr = next
456	return nil
457}
458
459// Next advances to the next page of values.  If there was an error making
460// the request the page does not advance and the error is returned.
461// Deprecated: Use NextWithContext() instead.
462func (page *UserAssignedIdentitiesListResultPage) Next() error {
463	return page.NextWithContext(context.Background())
464}
465
466// NotDone returns true if the page enumeration should be started or is not yet complete.
467func (page UserAssignedIdentitiesListResultPage) NotDone() bool {
468	return !page.uailr.IsEmpty()
469}
470
471// Response returns the raw server response from the last page request.
472func (page UserAssignedIdentitiesListResultPage) Response() UserAssignedIdentitiesListResult {
473	return page.uailr
474}
475
476// Values returns the slice of values for the current page or nil if there are no values.
477func (page UserAssignedIdentitiesListResultPage) Values() []Identity {
478	if page.uailr.IsEmpty() {
479		return nil
480	}
481	return *page.uailr.Value
482}
483
484// Creates a new instance of the UserAssignedIdentitiesListResultPage type.
485func NewUserAssignedIdentitiesListResultPage(getNextPage func(context.Context, UserAssignedIdentitiesListResult) (UserAssignedIdentitiesListResult, error)) UserAssignedIdentitiesListResultPage {
486	return UserAssignedIdentitiesListResultPage{fn: getNextPage}
487}
488