...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2019-06-01-preview/templatespecs/models.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2019-06-01-preview/templatespecs

     1  package templatespecs
     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  
     9  import (
    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.
    20  const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2019-06-01-preview/templatespecs"
    21  
    22  // BasicArtifact represents a Template Spec artifact.
    23  type BasicArtifact interface {
    24  	AsTemplateArtifact() (*TemplateArtifact, bool)
    25  	AsArtifact() (*Artifact, bool)
    26  }
    27  
    28  // Artifact represents a Template Spec artifact.
    29  type Artifact struct {
    30  	// Path - A filesystem safe relative path of the artifact.
    31  	Path *string `json:"path,omitempty"`
    32  	// Kind - Possible values include: 'KindTemplateSpecArtifact', 'KindTemplate'
    33  	Kind Kind `json:"kind,omitempty"`
    34  }
    35  
    36  func unmarshalBasicArtifact(body []byte) (BasicArtifact, error) {
    37  	var m map[string]interface{}
    38  	err := json.Unmarshal(body, &m)
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  
    43  	switch m["kind"] {
    44  	case string(KindTemplate):
    45  		var ta TemplateArtifact
    46  		err := json.Unmarshal(body, &ta)
    47  		return ta, err
    48  	default:
    49  		var a Artifact
    50  		err := json.Unmarshal(body, &a)
    51  		return a, err
    52  	}
    53  }
    54  func unmarshalBasicArtifactArray(body []byte) ([]BasicArtifact, error) {
    55  	var rawMessages []*json.RawMessage
    56  	err := json.Unmarshal(body, &rawMessages)
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  
    61  	aArray := make([]BasicArtifact, len(rawMessages))
    62  
    63  	for index, rawMessage := range rawMessages {
    64  		a, err := unmarshalBasicArtifact(*rawMessage)
    65  		if err != nil {
    66  			return nil, err
    67  		}
    68  		aArray[index] = a
    69  	}
    70  	return aArray, nil
    71  }
    72  
    73  // MarshalJSON is the custom marshaler for Artifact.
    74  func (a Artifact) MarshalJSON() ([]byte, error) {
    75  	a.Kind = KindTemplateSpecArtifact
    76  	objectMap := make(map[string]interface{})
    77  	if a.Path != nil {
    78  		objectMap["path"] = a.Path
    79  	}
    80  	if a.Kind != "" {
    81  		objectMap["kind"] = a.Kind
    82  	}
    83  	return json.Marshal(objectMap)
    84  }
    85  
    86  // AsTemplateArtifact is the BasicArtifact implementation for Artifact.
    87  func (a Artifact) AsTemplateArtifact() (*TemplateArtifact, bool) {
    88  	return nil, false
    89  }
    90  
    91  // AsArtifact is the BasicArtifact implementation for Artifact.
    92  func (a Artifact) AsArtifact() (*Artifact, bool) {
    93  	return &a, true
    94  }
    95  
    96  // AsBasicArtifact is the BasicArtifact implementation for Artifact.
    97  func (a Artifact) AsBasicArtifact() (BasicArtifact, bool) {
    98  	return &a, true
    99  }
   100  
   101  // AzureResourceBase common properties for all Azure resources.
   102  type AzureResourceBase struct {
   103  	// ID - READ-ONLY; String Id used to locate any resource on Azure.
   104  	ID *string `json:"id,omitempty"`
   105  	// Name - READ-ONLY; Name of this resource.
   106  	Name *string `json:"name,omitempty"`
   107  	// Type - READ-ONLY; Type of this resource.
   108  	Type *string `json:"type,omitempty"`
   109  	// SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information.
   110  	SystemData *SystemData `json:"systemData,omitempty"`
   111  }
   112  
   113  // MarshalJSON is the custom marshaler for AzureResourceBase.
   114  func (arb AzureResourceBase) MarshalJSON() ([]byte, error) {
   115  	objectMap := make(map[string]interface{})
   116  	return json.Marshal(objectMap)
   117  }
   118  
   119  // Error template Specs error response.
   120  type Error struct {
   121  	Error *ErrorResponse `json:"error,omitempty"`
   122  }
   123  
   124  // ErrorAdditionalInfo the resource management error additional info.
   125  type ErrorAdditionalInfo struct {
   126  	// Type - READ-ONLY; The additional info type.
   127  	Type *string `json:"type,omitempty"`
   128  	// Info - READ-ONLY; The additional info.
   129  	Info interface{} `json:"info,omitempty"`
   130  }
   131  
   132  // MarshalJSON is the custom marshaler for ErrorAdditionalInfo.
   133  func (eai ErrorAdditionalInfo) MarshalJSON() ([]byte, error) {
   134  	objectMap := make(map[string]interface{})
   135  	return json.Marshal(objectMap)
   136  }
   137  
   138  // ErrorResponse common error response for all Azure Resource Manager APIs to return error details for
   139  // failed operations. (This also follows the OData error response format.)
   140  type ErrorResponse struct {
   141  	// Code - READ-ONLY; The error code.
   142  	Code *string `json:"code,omitempty"`
   143  	// Message - READ-ONLY; The error message.
   144  	Message *string `json:"message,omitempty"`
   145  	// Target - READ-ONLY; The error target.
   146  	Target *string `json:"target,omitempty"`
   147  	// Details - READ-ONLY; The error details.
   148  	Details *[]ErrorResponse `json:"details,omitempty"`
   149  	// AdditionalInfo - READ-ONLY; The error additional info.
   150  	AdditionalInfo *[]ErrorAdditionalInfo `json:"additionalInfo,omitempty"`
   151  }
   152  
   153  // MarshalJSON is the custom marshaler for ErrorResponse.
   154  func (er ErrorResponse) MarshalJSON() ([]byte, error) {
   155  	objectMap := make(map[string]interface{})
   156  	return json.Marshal(objectMap)
   157  }
   158  
   159  // ListResult list of Template Specs.
   160  type ListResult struct {
   161  	autorest.Response `json:"-"`
   162  	// Value - An array of Template Specs.
   163  	Value *[]TemplateSpec `json:"value,omitempty"`
   164  	// NextLink - READ-ONLY; The URL to use for getting the next set of results.
   165  	NextLink *string `json:"nextLink,omitempty"`
   166  }
   167  
   168  // MarshalJSON is the custom marshaler for ListResult.
   169  func (lr ListResult) MarshalJSON() ([]byte, error) {
   170  	objectMap := make(map[string]interface{})
   171  	if lr.Value != nil {
   172  		objectMap["value"] = lr.Value
   173  	}
   174  	return json.Marshal(objectMap)
   175  }
   176  
   177  // ListResultIterator provides access to a complete listing of TemplateSpec values.
   178  type ListResultIterator struct {
   179  	i    int
   180  	page ListResultPage
   181  }
   182  
   183  // NextWithContext advances to the next value.  If there was an error making
   184  // the request the iterator does not advance and the error is returned.
   185  func (iter *ListResultIterator) NextWithContext(ctx context.Context) (err error) {
   186  	if tracing.IsEnabled() {
   187  		ctx = tracing.StartSpan(ctx, fqdn+"/ListResultIterator.NextWithContext")
   188  		defer func() {
   189  			sc := -1
   190  			if iter.Response().Response.Response != nil {
   191  				sc = iter.Response().Response.Response.StatusCode
   192  			}
   193  			tracing.EndSpan(ctx, sc, err)
   194  		}()
   195  	}
   196  	iter.i++
   197  	if iter.i < len(iter.page.Values()) {
   198  		return nil
   199  	}
   200  	err = iter.page.NextWithContext(ctx)
   201  	if err != nil {
   202  		iter.i--
   203  		return err
   204  	}
   205  	iter.i = 0
   206  	return nil
   207  }
   208  
   209  // Next advances to the next value.  If there was an error making
   210  // the request the iterator does not advance and the error is returned.
   211  // Deprecated: Use NextWithContext() instead.
   212  func (iter *ListResultIterator) Next() error {
   213  	return iter.NextWithContext(context.Background())
   214  }
   215  
   216  // NotDone returns true if the enumeration should be started or is not yet complete.
   217  func (iter ListResultIterator) NotDone() bool {
   218  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   219  }
   220  
   221  // Response returns the raw server response from the last page request.
   222  func (iter ListResultIterator) Response() ListResult {
   223  	return iter.page.Response()
   224  }
   225  
   226  // Value returns the current value or a zero-initialized value if the
   227  // iterator has advanced beyond the end of the collection.
   228  func (iter ListResultIterator) Value() TemplateSpec {
   229  	if !iter.page.NotDone() {
   230  		return TemplateSpec{}
   231  	}
   232  	return iter.page.Values()[iter.i]
   233  }
   234  
   235  // Creates a new instance of the ListResultIterator type.
   236  func NewListResultIterator(page ListResultPage) ListResultIterator {
   237  	return ListResultIterator{page: page}
   238  }
   239  
   240  // IsEmpty returns true if the ListResult contains no values.
   241  func (lr ListResult) IsEmpty() bool {
   242  	return lr.Value == nil || len(*lr.Value) == 0
   243  }
   244  
   245  // hasNextLink returns true if the NextLink is not empty.
   246  func (lr ListResult) hasNextLink() bool {
   247  	return lr.NextLink != nil && len(*lr.NextLink) != 0
   248  }
   249  
   250  // listResultPreparer prepares a request to retrieve the next set of results.
   251  // It returns nil if no more results exist.
   252  func (lr ListResult) listResultPreparer(ctx context.Context) (*http.Request, error) {
   253  	if !lr.hasNextLink() {
   254  		return nil, nil
   255  	}
   256  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   257  		autorest.AsJSON(),
   258  		autorest.AsGet(),
   259  		autorest.WithBaseURL(to.String(lr.NextLink)))
   260  }
   261  
   262  // ListResultPage contains a page of TemplateSpec values.
   263  type ListResultPage struct {
   264  	fn func(context.Context, ListResult) (ListResult, error)
   265  	lr ListResult
   266  }
   267  
   268  // NextWithContext advances to the next page of values.  If there was an error making
   269  // the request the page does not advance and the error is returned.
   270  func (page *ListResultPage) NextWithContext(ctx context.Context) (err error) {
   271  	if tracing.IsEnabled() {
   272  		ctx = tracing.StartSpan(ctx, fqdn+"/ListResultPage.NextWithContext")
   273  		defer func() {
   274  			sc := -1
   275  			if page.Response().Response.Response != nil {
   276  				sc = page.Response().Response.Response.StatusCode
   277  			}
   278  			tracing.EndSpan(ctx, sc, err)
   279  		}()
   280  	}
   281  	for {
   282  		next, err := page.fn(ctx, page.lr)
   283  		if err != nil {
   284  			return err
   285  		}
   286  		page.lr = next
   287  		if !next.hasNextLink() || !next.IsEmpty() {
   288  			break
   289  		}
   290  	}
   291  	return nil
   292  }
   293  
   294  // Next advances to the next page of values.  If there was an error making
   295  // the request the page does not advance and the error is returned.
   296  // Deprecated: Use NextWithContext() instead.
   297  func (page *ListResultPage) Next() error {
   298  	return page.NextWithContext(context.Background())
   299  }
   300  
   301  // NotDone returns true if the page enumeration should be started or is not yet complete.
   302  func (page ListResultPage) NotDone() bool {
   303  	return !page.lr.IsEmpty()
   304  }
   305  
   306  // Response returns the raw server response from the last page request.
   307  func (page ListResultPage) Response() ListResult {
   308  	return page.lr
   309  }
   310  
   311  // Values returns the slice of values for the current page or nil if there are no values.
   312  func (page ListResultPage) Values() []TemplateSpec {
   313  	if page.lr.IsEmpty() {
   314  		return nil
   315  	}
   316  	return *page.lr.Value
   317  }
   318  
   319  // Creates a new instance of the ListResultPage type.
   320  func NewListResultPage(cur ListResult, getNextPage func(context.Context, ListResult) (ListResult, error)) ListResultPage {
   321  	return ListResultPage{
   322  		fn: getNextPage,
   323  		lr: cur,
   324  	}
   325  }
   326  
   327  // Properties template Spec properties.
   328  type Properties struct {
   329  	// Description - Template Spec description.
   330  	Description *string `json:"description,omitempty"`
   331  	// DisplayName - Template Spec display name.
   332  	DisplayName *string `json:"displayName,omitempty"`
   333  	// Versions - READ-ONLY; High-level information about the versions within this Template Spec. The keys are the version names. Only populated if the $expand query parameter is set to 'versions'.
   334  	Versions map[string]*VersionInfo `json:"versions"`
   335  }
   336  
   337  // MarshalJSON is the custom marshaler for Properties.
   338  func (p Properties) MarshalJSON() ([]byte, error) {
   339  	objectMap := make(map[string]interface{})
   340  	if p.Description != nil {
   341  		objectMap["description"] = p.Description
   342  	}
   343  	if p.DisplayName != nil {
   344  		objectMap["displayName"] = p.DisplayName
   345  	}
   346  	return json.Marshal(objectMap)
   347  }
   348  
   349  // SystemData metadata pertaining to creation and last modification of the resource.
   350  type SystemData struct {
   351  	// CreatedBy - The identity that created the resource.
   352  	CreatedBy *string `json:"createdBy,omitempty"`
   353  	// CreatedByType - The type of identity that created the resource. Possible values include: 'User', 'Application', 'ManagedIdentity', 'Key'
   354  	CreatedByType CreatedByType `json:"createdByType,omitempty"`
   355  	// CreatedAt - The timestamp of resource creation (UTC).
   356  	CreatedAt *date.Time `json:"createdAt,omitempty"`
   357  	// LastModifiedBy - The identity that last modified the resource.
   358  	LastModifiedBy *string `json:"lastModifiedBy,omitempty"`
   359  	// LastModifiedByType - The type of identity that last modified the resource. Possible values include: 'User', 'Application', 'ManagedIdentity', 'Key'
   360  	LastModifiedByType CreatedByType `json:"lastModifiedByType,omitempty"`
   361  	// LastModifiedAt - The type of identity that last modified the resource.
   362  	LastModifiedAt *date.Time `json:"lastModifiedAt,omitempty"`
   363  }
   364  
   365  // TemplateArtifact represents a Template Spec artifact containing an embedded Azure Resource Manager
   366  // template.
   367  type TemplateArtifact struct {
   368  	// Template - The Azure Resource Manager template.
   369  	Template interface{} `json:"template,omitempty"`
   370  	// Path - A filesystem safe relative path of the artifact.
   371  	Path *string `json:"path,omitempty"`
   372  	// Kind - Possible values include: 'KindTemplateSpecArtifact', 'KindTemplate'
   373  	Kind Kind `json:"kind,omitempty"`
   374  }
   375  
   376  // MarshalJSON is the custom marshaler for TemplateArtifact.
   377  func (ta TemplateArtifact) MarshalJSON() ([]byte, error) {
   378  	ta.Kind = KindTemplate
   379  	objectMap := make(map[string]interface{})
   380  	if ta.Template != nil {
   381  		objectMap["template"] = ta.Template
   382  	}
   383  	if ta.Path != nil {
   384  		objectMap["path"] = ta.Path
   385  	}
   386  	if ta.Kind != "" {
   387  		objectMap["kind"] = ta.Kind
   388  	}
   389  	return json.Marshal(objectMap)
   390  }
   391  
   392  // AsTemplateArtifact is the BasicArtifact implementation for TemplateArtifact.
   393  func (ta TemplateArtifact) AsTemplateArtifact() (*TemplateArtifact, bool) {
   394  	return &ta, true
   395  }
   396  
   397  // AsArtifact is the BasicArtifact implementation for TemplateArtifact.
   398  func (ta TemplateArtifact) AsArtifact() (*Artifact, bool) {
   399  	return nil, false
   400  }
   401  
   402  // AsBasicArtifact is the BasicArtifact implementation for TemplateArtifact.
   403  func (ta TemplateArtifact) AsBasicArtifact() (BasicArtifact, bool) {
   404  	return &ta, true
   405  }
   406  
   407  // TemplateSpec template Spec object.
   408  type TemplateSpec struct {
   409  	autorest.Response `json:"-"`
   410  	// Location - The location of the Template Spec. It cannot be changed after Template Spec creation. It must be one of the supported Azure locations.
   411  	Location *string `json:"location,omitempty"`
   412  	// Properties - Template Spec properties.
   413  	*Properties `json:"properties,omitempty"`
   414  	// Tags - Resource tags.
   415  	Tags map[string]*string `json:"tags"`
   416  	// ID - READ-ONLY; String Id used to locate any resource on Azure.
   417  	ID *string `json:"id,omitempty"`
   418  	// Name - READ-ONLY; Name of this resource.
   419  	Name *string `json:"name,omitempty"`
   420  	// Type - READ-ONLY; Type of this resource.
   421  	Type *string `json:"type,omitempty"`
   422  	// SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information.
   423  	SystemData *SystemData `json:"systemData,omitempty"`
   424  }
   425  
   426  // MarshalJSON is the custom marshaler for TemplateSpec.
   427  func (ts TemplateSpec) MarshalJSON() ([]byte, error) {
   428  	objectMap := make(map[string]interface{})
   429  	if ts.Location != nil {
   430  		objectMap["location"] = ts.Location
   431  	}
   432  	if ts.Properties != nil {
   433  		objectMap["properties"] = ts.Properties
   434  	}
   435  	if ts.Tags != nil {
   436  		objectMap["tags"] = ts.Tags
   437  	}
   438  	return json.Marshal(objectMap)
   439  }
   440  
   441  // UnmarshalJSON is the custom unmarshaler for TemplateSpec struct.
   442  func (ts *TemplateSpec) UnmarshalJSON(body []byte) error {
   443  	var m map[string]*json.RawMessage
   444  	err := json.Unmarshal(body, &m)
   445  	if err != nil {
   446  		return err
   447  	}
   448  	for k, v := range m {
   449  		switch k {
   450  		case "location":
   451  			if v != nil {
   452  				var location string
   453  				err = json.Unmarshal(*v, &location)
   454  				if err != nil {
   455  					return err
   456  				}
   457  				ts.Location = &location
   458  			}
   459  		case "properties":
   460  			if v != nil {
   461  				var properties Properties
   462  				err = json.Unmarshal(*v, &properties)
   463  				if err != nil {
   464  					return err
   465  				}
   466  				ts.Properties = &properties
   467  			}
   468  		case "tags":
   469  			if v != nil {
   470  				var tags map[string]*string
   471  				err = json.Unmarshal(*v, &tags)
   472  				if err != nil {
   473  					return err
   474  				}
   475  				ts.Tags = tags
   476  			}
   477  		case "id":
   478  			if v != nil {
   479  				var ID string
   480  				err = json.Unmarshal(*v, &ID)
   481  				if err != nil {
   482  					return err
   483  				}
   484  				ts.ID = &ID
   485  			}
   486  		case "name":
   487  			if v != nil {
   488  				var name string
   489  				err = json.Unmarshal(*v, &name)
   490  				if err != nil {
   491  					return err
   492  				}
   493  				ts.Name = &name
   494  			}
   495  		case "type":
   496  			if v != nil {
   497  				var typeVar string
   498  				err = json.Unmarshal(*v, &typeVar)
   499  				if err != nil {
   500  					return err
   501  				}
   502  				ts.Type = &typeVar
   503  			}
   504  		case "systemData":
   505  			if v != nil {
   506  				var systemData SystemData
   507  				err = json.Unmarshal(*v, &systemData)
   508  				if err != nil {
   509  					return err
   510  				}
   511  				ts.SystemData = &systemData
   512  			}
   513  		}
   514  	}
   515  
   516  	return nil
   517  }
   518  
   519  // UpdateModel template Spec properties to be updated (only tags are currently supported).
   520  type UpdateModel struct {
   521  	// Tags - Resource tags.
   522  	Tags map[string]*string `json:"tags"`
   523  	// ID - READ-ONLY; String Id used to locate any resource on Azure.
   524  	ID *string `json:"id,omitempty"`
   525  	// Name - READ-ONLY; Name of this resource.
   526  	Name *string `json:"name,omitempty"`
   527  	// Type - READ-ONLY; Type of this resource.
   528  	Type *string `json:"type,omitempty"`
   529  	// SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information.
   530  	SystemData *SystemData `json:"systemData,omitempty"`
   531  }
   532  
   533  // MarshalJSON is the custom marshaler for UpdateModel.
   534  func (um UpdateModel) MarshalJSON() ([]byte, error) {
   535  	objectMap := make(map[string]interface{})
   536  	if um.Tags != nil {
   537  		objectMap["tags"] = um.Tags
   538  	}
   539  	return json.Marshal(objectMap)
   540  }
   541  
   542  // VersionInfo high-level information about a Template Spec version.
   543  type VersionInfo struct {
   544  	// Description - READ-ONLY; Template Spec version description.
   545  	Description *string `json:"description,omitempty"`
   546  	// TimeCreated - READ-ONLY; The timestamp of when the version was created.
   547  	TimeCreated *date.Time `json:"timeCreated,omitempty"`
   548  	// TimeModified - READ-ONLY; The timestamp of when the version was last modified.
   549  	TimeModified *date.Time `json:"timeModified,omitempty"`
   550  }
   551  
   552  // MarshalJSON is the custom marshaler for VersionInfo.
   553  func (vi VersionInfo) MarshalJSON() ([]byte, error) {
   554  	objectMap := make(map[string]interface{})
   555  	return json.Marshal(objectMap)
   556  }
   557  
   558  // VersionProperties template Spec Version properties.
   559  type VersionProperties struct {
   560  	// Artifacts - An array of Template Spec artifacts.
   561  	Artifacts *[]BasicArtifact `json:"artifacts,omitempty"`
   562  	// Description - Template Spec version description.
   563  	Description *string `json:"description,omitempty"`
   564  	// Template - The Azure Resource Manager template content.
   565  	Template interface{} `json:"template,omitempty"`
   566  }
   567  
   568  // UnmarshalJSON is the custom unmarshaler for VersionProperties struct.
   569  func (vp *VersionProperties) UnmarshalJSON(body []byte) error {
   570  	var m map[string]*json.RawMessage
   571  	err := json.Unmarshal(body, &m)
   572  	if err != nil {
   573  		return err
   574  	}
   575  	for k, v := range m {
   576  		switch k {
   577  		case "artifacts":
   578  			if v != nil {
   579  				artifacts, err := unmarshalBasicArtifactArray(*v)
   580  				if err != nil {
   581  					return err
   582  				}
   583  				vp.Artifacts = &artifacts
   584  			}
   585  		case "description":
   586  			if v != nil {
   587  				var description string
   588  				err = json.Unmarshal(*v, &description)
   589  				if err != nil {
   590  					return err
   591  				}
   592  				vp.Description = &description
   593  			}
   594  		case "template":
   595  			if v != nil {
   596  				var templateVar interface{}
   597  				err = json.Unmarshal(*v, &templateVar)
   598  				if err != nil {
   599  					return err
   600  				}
   601  				vp.Template = templateVar
   602  			}
   603  		}
   604  	}
   605  
   606  	return nil
   607  }
   608  
   609  // VersionsListResult list of Template Specs versions
   610  type VersionsListResult struct {
   611  	autorest.Response `json:"-"`
   612  	// Value - An array of Template Spec versions.
   613  	Value *[]VersionTemplatespecs `json:"value,omitempty"`
   614  	// NextLink - READ-ONLY; The URL to use for getting the next set of results.
   615  	NextLink *string `json:"nextLink,omitempty"`
   616  }
   617  
   618  // MarshalJSON is the custom marshaler for VersionsListResult.
   619  func (vlr VersionsListResult) MarshalJSON() ([]byte, error) {
   620  	objectMap := make(map[string]interface{})
   621  	if vlr.Value != nil {
   622  		objectMap["value"] = vlr.Value
   623  	}
   624  	return json.Marshal(objectMap)
   625  }
   626  
   627  // VersionsListResultIterator provides access to a complete listing of VersionTemplatespecs values.
   628  type VersionsListResultIterator struct {
   629  	i    int
   630  	page VersionsListResultPage
   631  }
   632  
   633  // NextWithContext advances to the next value.  If there was an error making
   634  // the request the iterator does not advance and the error is returned.
   635  func (iter *VersionsListResultIterator) NextWithContext(ctx context.Context) (err error) {
   636  	if tracing.IsEnabled() {
   637  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsListResultIterator.NextWithContext")
   638  		defer func() {
   639  			sc := -1
   640  			if iter.Response().Response.Response != nil {
   641  				sc = iter.Response().Response.Response.StatusCode
   642  			}
   643  			tracing.EndSpan(ctx, sc, err)
   644  		}()
   645  	}
   646  	iter.i++
   647  	if iter.i < len(iter.page.Values()) {
   648  		return nil
   649  	}
   650  	err = iter.page.NextWithContext(ctx)
   651  	if err != nil {
   652  		iter.i--
   653  		return err
   654  	}
   655  	iter.i = 0
   656  	return nil
   657  }
   658  
   659  // Next advances to the next value.  If there was an error making
   660  // the request the iterator does not advance and the error is returned.
   661  // Deprecated: Use NextWithContext() instead.
   662  func (iter *VersionsListResultIterator) Next() error {
   663  	return iter.NextWithContext(context.Background())
   664  }
   665  
   666  // NotDone returns true if the enumeration should be started or is not yet complete.
   667  func (iter VersionsListResultIterator) NotDone() bool {
   668  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   669  }
   670  
   671  // Response returns the raw server response from the last page request.
   672  func (iter VersionsListResultIterator) Response() VersionsListResult {
   673  	return iter.page.Response()
   674  }
   675  
   676  // Value returns the current value or a zero-initialized value if the
   677  // iterator has advanced beyond the end of the collection.
   678  func (iter VersionsListResultIterator) Value() VersionTemplatespecs {
   679  	if !iter.page.NotDone() {
   680  		return VersionTemplatespecs{}
   681  	}
   682  	return iter.page.Values()[iter.i]
   683  }
   684  
   685  // Creates a new instance of the VersionsListResultIterator type.
   686  func NewVersionsListResultIterator(page VersionsListResultPage) VersionsListResultIterator {
   687  	return VersionsListResultIterator{page: page}
   688  }
   689  
   690  // IsEmpty returns true if the ListResult contains no values.
   691  func (vlr VersionsListResult) IsEmpty() bool {
   692  	return vlr.Value == nil || len(*vlr.Value) == 0
   693  }
   694  
   695  // hasNextLink returns true if the NextLink is not empty.
   696  func (vlr VersionsListResult) hasNextLink() bool {
   697  	return vlr.NextLink != nil && len(*vlr.NextLink) != 0
   698  }
   699  
   700  // versionsListResultPreparer prepares a request to retrieve the next set of results.
   701  // It returns nil if no more results exist.
   702  func (vlr VersionsListResult) versionsListResultPreparer(ctx context.Context) (*http.Request, error) {
   703  	if !vlr.hasNextLink() {
   704  		return nil, nil
   705  	}
   706  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   707  		autorest.AsJSON(),
   708  		autorest.AsGet(),
   709  		autorest.WithBaseURL(to.String(vlr.NextLink)))
   710  }
   711  
   712  // VersionsListResultPage contains a page of VersionTemplatespecs values.
   713  type VersionsListResultPage struct {
   714  	fn  func(context.Context, VersionsListResult) (VersionsListResult, error)
   715  	vlr VersionsListResult
   716  }
   717  
   718  // NextWithContext advances to the next page of values.  If there was an error making
   719  // the request the page does not advance and the error is returned.
   720  func (page *VersionsListResultPage) NextWithContext(ctx context.Context) (err error) {
   721  	if tracing.IsEnabled() {
   722  		ctx = tracing.StartSpan(ctx, fqdn+"/VersionsListResultPage.NextWithContext")
   723  		defer func() {
   724  			sc := -1
   725  			if page.Response().Response.Response != nil {
   726  				sc = page.Response().Response.Response.StatusCode
   727  			}
   728  			tracing.EndSpan(ctx, sc, err)
   729  		}()
   730  	}
   731  	for {
   732  		next, err := page.fn(ctx, page.vlr)
   733  		if err != nil {
   734  			return err
   735  		}
   736  		page.vlr = next
   737  		if !next.hasNextLink() || !next.IsEmpty() {
   738  			break
   739  		}
   740  	}
   741  	return nil
   742  }
   743  
   744  // Next advances to the next page of values.  If there was an error making
   745  // the request the page does not advance and the error is returned.
   746  // Deprecated: Use NextWithContext() instead.
   747  func (page *VersionsListResultPage) Next() error {
   748  	return page.NextWithContext(context.Background())
   749  }
   750  
   751  // NotDone returns true if the page enumeration should be started or is not yet complete.
   752  func (page VersionsListResultPage) NotDone() bool {
   753  	return !page.vlr.IsEmpty()
   754  }
   755  
   756  // Response returns the raw server response from the last page request.
   757  func (page VersionsListResultPage) Response() VersionsListResult {
   758  	return page.vlr
   759  }
   760  
   761  // Values returns the slice of values for the current page or nil if there are no values.
   762  func (page VersionsListResultPage) Values() []VersionTemplatespecs {
   763  	if page.vlr.IsEmpty() {
   764  		return nil
   765  	}
   766  	return *page.vlr.Value
   767  }
   768  
   769  // Creates a new instance of the VersionsListResultPage type.
   770  func NewVersionsListResultPage(cur VersionsListResult, getNextPage func(context.Context, VersionsListResult) (VersionsListResult, error)) VersionsListResultPage {
   771  	return VersionsListResultPage{
   772  		fn:  getNextPage,
   773  		vlr: cur,
   774  	}
   775  }
   776  
   777  // VersionTemplatespecs template Spec Version object.
   778  type VersionTemplatespecs struct {
   779  	autorest.Response `json:"-"`
   780  	// Location - The location of the Template Spec Version. It must match the location of the parent Template Spec.
   781  	Location *string `json:"location,omitempty"`
   782  	// VersionProperties - Template Spec Version properties.
   783  	*VersionProperties `json:"properties,omitempty"`
   784  	// Tags - Resource tags.
   785  	Tags map[string]*string `json:"tags"`
   786  	// ID - READ-ONLY; String Id used to locate any resource on Azure.
   787  	ID *string `json:"id,omitempty"`
   788  	// Name - READ-ONLY; Name of this resource.
   789  	Name *string `json:"name,omitempty"`
   790  	// Type - READ-ONLY; Type of this resource.
   791  	Type *string `json:"type,omitempty"`
   792  	// SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information.
   793  	SystemData *SystemData `json:"systemData,omitempty"`
   794  }
   795  
   796  // MarshalJSON is the custom marshaler for VersionTemplatespecs.
   797  func (vt VersionTemplatespecs) MarshalJSON() ([]byte, error) {
   798  	objectMap := make(map[string]interface{})
   799  	if vt.Location != nil {
   800  		objectMap["location"] = vt.Location
   801  	}
   802  	if vt.VersionProperties != nil {
   803  		objectMap["properties"] = vt.VersionProperties
   804  	}
   805  	if vt.Tags != nil {
   806  		objectMap["tags"] = vt.Tags
   807  	}
   808  	return json.Marshal(objectMap)
   809  }
   810  
   811  // UnmarshalJSON is the custom unmarshaler for VersionTemplatespecs struct.
   812  func (vt *VersionTemplatespecs) UnmarshalJSON(body []byte) error {
   813  	var m map[string]*json.RawMessage
   814  	err := json.Unmarshal(body, &m)
   815  	if err != nil {
   816  		return err
   817  	}
   818  	for k, v := range m {
   819  		switch k {
   820  		case "location":
   821  			if v != nil {
   822  				var location string
   823  				err = json.Unmarshal(*v, &location)
   824  				if err != nil {
   825  					return err
   826  				}
   827  				vt.Location = &location
   828  			}
   829  		case "properties":
   830  			if v != nil {
   831  				var versionProperties VersionProperties
   832  				err = json.Unmarshal(*v, &versionProperties)
   833  				if err != nil {
   834  					return err
   835  				}
   836  				vt.VersionProperties = &versionProperties
   837  			}
   838  		case "tags":
   839  			if v != nil {
   840  				var tags map[string]*string
   841  				err = json.Unmarshal(*v, &tags)
   842  				if err != nil {
   843  					return err
   844  				}
   845  				vt.Tags = tags
   846  			}
   847  		case "id":
   848  			if v != nil {
   849  				var ID string
   850  				err = json.Unmarshal(*v, &ID)
   851  				if err != nil {
   852  					return err
   853  				}
   854  				vt.ID = &ID
   855  			}
   856  		case "name":
   857  			if v != nil {
   858  				var name string
   859  				err = json.Unmarshal(*v, &name)
   860  				if err != nil {
   861  					return err
   862  				}
   863  				vt.Name = &name
   864  			}
   865  		case "type":
   866  			if v != nil {
   867  				var typeVar string
   868  				err = json.Unmarshal(*v, &typeVar)
   869  				if err != nil {
   870  					return err
   871  				}
   872  				vt.Type = &typeVar
   873  			}
   874  		case "systemData":
   875  			if v != nil {
   876  				var systemData SystemData
   877  				err = json.Unmarshal(*v, &systemData)
   878  				if err != nil {
   879  					return err
   880  				}
   881  				vt.SystemData = &systemData
   882  			}
   883  		}
   884  	}
   885  
   886  	return nil
   887  }
   888  
   889  // VersionUpdateModel template Spec Version properties to be updated (only tags are currently supported).
   890  type VersionUpdateModel struct {
   891  	// Tags - Resource tags.
   892  	Tags map[string]*string `json:"tags"`
   893  	// ID - READ-ONLY; String Id used to locate any resource on Azure.
   894  	ID *string `json:"id,omitempty"`
   895  	// Name - READ-ONLY; Name of this resource.
   896  	Name *string `json:"name,omitempty"`
   897  	// Type - READ-ONLY; Type of this resource.
   898  	Type *string `json:"type,omitempty"`
   899  	// SystemData - READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information.
   900  	SystemData *SystemData `json:"systemData,omitempty"`
   901  }
   902  
   903  // MarshalJSON is the custom marshaler for VersionUpdateModel.
   904  func (vum VersionUpdateModel) MarshalJSON() ([]byte, error) {
   905  	objectMap := make(map[string]interface{})
   906  	if vum.Tags != nil {
   907  		objectMap["tags"] = vum.Tags
   908  	}
   909  	return json.Marshal(objectMap)
   910  }
   911  

View as plain text