...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/policy/models.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/policy

     1  package policy
     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/to"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // The package's fully qualified name.
    19  const fqdn = "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/policy"
    20  
    21  // Assignment the policy assignment.
    22  type Assignment struct {
    23  	autorest.Response `json:"-"`
    24  	// AssignmentProperties - Properties for the policy assignment.
    25  	*AssignmentProperties `json:"properties,omitempty"`
    26  	// ID - READ-ONLY; The ID of the policy assignment.
    27  	ID *string `json:"id,omitempty"`
    28  	// Type - READ-ONLY; The type of the policy assignment.
    29  	Type *string `json:"type,omitempty"`
    30  	// Name - READ-ONLY; The name of the policy assignment.
    31  	Name *string `json:"name,omitempty"`
    32  	// Sku - The policy sku. This property is optional, obsolete, and will be ignored.
    33  	Sku *Sku `json:"sku,omitempty"`
    34  	// Location - The location of the policy assignment. Only required when utilizing managed identity.
    35  	Location *string `json:"location,omitempty"`
    36  	// Identity - The managed identity associated with the policy assignment.
    37  	Identity *Identity `json:"identity,omitempty"`
    38  }
    39  
    40  // MarshalJSON is the custom marshaler for Assignment.
    41  func (a Assignment) MarshalJSON() ([]byte, error) {
    42  	objectMap := make(map[string]interface{})
    43  	if a.AssignmentProperties != nil {
    44  		objectMap["properties"] = a.AssignmentProperties
    45  	}
    46  	if a.Sku != nil {
    47  		objectMap["sku"] = a.Sku
    48  	}
    49  	if a.Location != nil {
    50  		objectMap["location"] = a.Location
    51  	}
    52  	if a.Identity != nil {
    53  		objectMap["identity"] = a.Identity
    54  	}
    55  	return json.Marshal(objectMap)
    56  }
    57  
    58  // UnmarshalJSON is the custom unmarshaler for Assignment struct.
    59  func (a *Assignment) UnmarshalJSON(body []byte) error {
    60  	var m map[string]*json.RawMessage
    61  	err := json.Unmarshal(body, &m)
    62  	if err != nil {
    63  		return err
    64  	}
    65  	for k, v := range m {
    66  		switch k {
    67  		case "properties":
    68  			if v != nil {
    69  				var assignmentProperties AssignmentProperties
    70  				err = json.Unmarshal(*v, &assignmentProperties)
    71  				if err != nil {
    72  					return err
    73  				}
    74  				a.AssignmentProperties = &assignmentProperties
    75  			}
    76  		case "id":
    77  			if v != nil {
    78  				var ID string
    79  				err = json.Unmarshal(*v, &ID)
    80  				if err != nil {
    81  					return err
    82  				}
    83  				a.ID = &ID
    84  			}
    85  		case "type":
    86  			if v != nil {
    87  				var typeVar string
    88  				err = json.Unmarshal(*v, &typeVar)
    89  				if err != nil {
    90  					return err
    91  				}
    92  				a.Type = &typeVar
    93  			}
    94  		case "name":
    95  			if v != nil {
    96  				var name string
    97  				err = json.Unmarshal(*v, &name)
    98  				if err != nil {
    99  					return err
   100  				}
   101  				a.Name = &name
   102  			}
   103  		case "sku":
   104  			if v != nil {
   105  				var sku Sku
   106  				err = json.Unmarshal(*v, &sku)
   107  				if err != nil {
   108  					return err
   109  				}
   110  				a.Sku = &sku
   111  			}
   112  		case "location":
   113  			if v != nil {
   114  				var location string
   115  				err = json.Unmarshal(*v, &location)
   116  				if err != nil {
   117  					return err
   118  				}
   119  				a.Location = &location
   120  			}
   121  		case "identity":
   122  			if v != nil {
   123  				var identity Identity
   124  				err = json.Unmarshal(*v, &identity)
   125  				if err != nil {
   126  					return err
   127  				}
   128  				a.Identity = &identity
   129  			}
   130  		}
   131  	}
   132  
   133  	return nil
   134  }
   135  
   136  // AssignmentListResult list of policy assignments.
   137  type AssignmentListResult struct {
   138  	autorest.Response `json:"-"`
   139  	// Value - An array of policy assignments.
   140  	Value *[]Assignment `json:"value,omitempty"`
   141  	// NextLink - The URL to use for getting the next set of results.
   142  	NextLink *string `json:"nextLink,omitempty"`
   143  }
   144  
   145  // AssignmentListResultIterator provides access to a complete listing of Assignment values.
   146  type AssignmentListResultIterator struct {
   147  	i    int
   148  	page AssignmentListResultPage
   149  }
   150  
   151  // NextWithContext advances to the next value.  If there was an error making
   152  // the request the iterator does not advance and the error is returned.
   153  func (iter *AssignmentListResultIterator) NextWithContext(ctx context.Context) (err error) {
   154  	if tracing.IsEnabled() {
   155  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentListResultIterator.NextWithContext")
   156  		defer func() {
   157  			sc := -1
   158  			if iter.Response().Response.Response != nil {
   159  				sc = iter.Response().Response.Response.StatusCode
   160  			}
   161  			tracing.EndSpan(ctx, sc, err)
   162  		}()
   163  	}
   164  	iter.i++
   165  	if iter.i < len(iter.page.Values()) {
   166  		return nil
   167  	}
   168  	err = iter.page.NextWithContext(ctx)
   169  	if err != nil {
   170  		iter.i--
   171  		return err
   172  	}
   173  	iter.i = 0
   174  	return nil
   175  }
   176  
   177  // Next advances to the next value.  If there was an error making
   178  // the request the iterator does not advance and the error is returned.
   179  // Deprecated: Use NextWithContext() instead.
   180  func (iter *AssignmentListResultIterator) Next() error {
   181  	return iter.NextWithContext(context.Background())
   182  }
   183  
   184  // NotDone returns true if the enumeration should be started or is not yet complete.
   185  func (iter AssignmentListResultIterator) NotDone() bool {
   186  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   187  }
   188  
   189  // Response returns the raw server response from the last page request.
   190  func (iter AssignmentListResultIterator) Response() AssignmentListResult {
   191  	return iter.page.Response()
   192  }
   193  
   194  // Value returns the current value or a zero-initialized value if the
   195  // iterator has advanced beyond the end of the collection.
   196  func (iter AssignmentListResultIterator) Value() Assignment {
   197  	if !iter.page.NotDone() {
   198  		return Assignment{}
   199  	}
   200  	return iter.page.Values()[iter.i]
   201  }
   202  
   203  // Creates a new instance of the AssignmentListResultIterator type.
   204  func NewAssignmentListResultIterator(page AssignmentListResultPage) AssignmentListResultIterator {
   205  	return AssignmentListResultIterator{page: page}
   206  }
   207  
   208  // IsEmpty returns true if the ListResult contains no values.
   209  func (alr AssignmentListResult) IsEmpty() bool {
   210  	return alr.Value == nil || len(*alr.Value) == 0
   211  }
   212  
   213  // hasNextLink returns true if the NextLink is not empty.
   214  func (alr AssignmentListResult) hasNextLink() bool {
   215  	return alr.NextLink != nil && len(*alr.NextLink) != 0
   216  }
   217  
   218  // assignmentListResultPreparer prepares a request to retrieve the next set of results.
   219  // It returns nil if no more results exist.
   220  func (alr AssignmentListResult) assignmentListResultPreparer(ctx context.Context) (*http.Request, error) {
   221  	if !alr.hasNextLink() {
   222  		return nil, nil
   223  	}
   224  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   225  		autorest.AsJSON(),
   226  		autorest.AsGet(),
   227  		autorest.WithBaseURL(to.String(alr.NextLink)))
   228  }
   229  
   230  // AssignmentListResultPage contains a page of Assignment values.
   231  type AssignmentListResultPage struct {
   232  	fn  func(context.Context, AssignmentListResult) (AssignmentListResult, error)
   233  	alr AssignmentListResult
   234  }
   235  
   236  // NextWithContext advances to the next page of values.  If there was an error making
   237  // the request the page does not advance and the error is returned.
   238  func (page *AssignmentListResultPage) NextWithContext(ctx context.Context) (err error) {
   239  	if tracing.IsEnabled() {
   240  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentListResultPage.NextWithContext")
   241  		defer func() {
   242  			sc := -1
   243  			if page.Response().Response.Response != nil {
   244  				sc = page.Response().Response.Response.StatusCode
   245  			}
   246  			tracing.EndSpan(ctx, sc, err)
   247  		}()
   248  	}
   249  	for {
   250  		next, err := page.fn(ctx, page.alr)
   251  		if err != nil {
   252  			return err
   253  		}
   254  		page.alr = next
   255  		if !next.hasNextLink() || !next.IsEmpty() {
   256  			break
   257  		}
   258  	}
   259  	return nil
   260  }
   261  
   262  // Next advances to the next page of values.  If there was an error making
   263  // the request the page does not advance and the error is returned.
   264  // Deprecated: Use NextWithContext() instead.
   265  func (page *AssignmentListResultPage) Next() error {
   266  	return page.NextWithContext(context.Background())
   267  }
   268  
   269  // NotDone returns true if the page enumeration should be started or is not yet complete.
   270  func (page AssignmentListResultPage) NotDone() bool {
   271  	return !page.alr.IsEmpty()
   272  }
   273  
   274  // Response returns the raw server response from the last page request.
   275  func (page AssignmentListResultPage) Response() AssignmentListResult {
   276  	return page.alr
   277  }
   278  
   279  // Values returns the slice of values for the current page or nil if there are no values.
   280  func (page AssignmentListResultPage) Values() []Assignment {
   281  	if page.alr.IsEmpty() {
   282  		return nil
   283  	}
   284  	return *page.alr.Value
   285  }
   286  
   287  // Creates a new instance of the AssignmentListResultPage type.
   288  func NewAssignmentListResultPage(cur AssignmentListResult, getNextPage func(context.Context, AssignmentListResult) (AssignmentListResult, error)) AssignmentListResultPage {
   289  	return AssignmentListResultPage{
   290  		fn:  getNextPage,
   291  		alr: cur,
   292  	}
   293  }
   294  
   295  // AssignmentProperties the policy assignment properties.
   296  type AssignmentProperties struct {
   297  	// DisplayName - The display name of the policy assignment.
   298  	DisplayName *string `json:"displayName,omitempty"`
   299  	// PolicyDefinitionID - The ID of the policy definition or policy set definition being assigned.
   300  	PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"`
   301  	// Scope - The scope for the policy assignment.
   302  	Scope *string `json:"scope,omitempty"`
   303  	// NotScopes - The policy's excluded scopes.
   304  	NotScopes *[]string `json:"notScopes,omitempty"`
   305  	// Parameters - Required if a parameter is used in policy rule.
   306  	Parameters interface{} `json:"parameters,omitempty"`
   307  	// Description - This message will be part of response in case of policy violation.
   308  	Description *string `json:"description,omitempty"`
   309  	// Metadata - The policy assignment metadata.
   310  	Metadata interface{} `json:"metadata,omitempty"`
   311  }
   312  
   313  // Definition the policy definition.
   314  type Definition struct {
   315  	autorest.Response `json:"-"`
   316  	// DefinitionProperties - The policy definition properties.
   317  	*DefinitionProperties `json:"properties,omitempty"`
   318  	// ID - READ-ONLY; The ID of the policy definition.
   319  	ID *string `json:"id,omitempty"`
   320  	// Name - READ-ONLY; The name of the policy definition.
   321  	Name *string `json:"name,omitempty"`
   322  	// Type - READ-ONLY; The type of the resource (Microsoft.Authorization/policyDefinitions).
   323  	Type *string `json:"type,omitempty"`
   324  }
   325  
   326  // MarshalJSON is the custom marshaler for Definition.
   327  func (d Definition) MarshalJSON() ([]byte, error) {
   328  	objectMap := make(map[string]interface{})
   329  	if d.DefinitionProperties != nil {
   330  		objectMap["properties"] = d.DefinitionProperties
   331  	}
   332  	return json.Marshal(objectMap)
   333  }
   334  
   335  // UnmarshalJSON is the custom unmarshaler for Definition struct.
   336  func (d *Definition) UnmarshalJSON(body []byte) error {
   337  	var m map[string]*json.RawMessage
   338  	err := json.Unmarshal(body, &m)
   339  	if err != nil {
   340  		return err
   341  	}
   342  	for k, v := range m {
   343  		switch k {
   344  		case "properties":
   345  			if v != nil {
   346  				var definitionProperties DefinitionProperties
   347  				err = json.Unmarshal(*v, &definitionProperties)
   348  				if err != nil {
   349  					return err
   350  				}
   351  				d.DefinitionProperties = &definitionProperties
   352  			}
   353  		case "id":
   354  			if v != nil {
   355  				var ID string
   356  				err = json.Unmarshal(*v, &ID)
   357  				if err != nil {
   358  					return err
   359  				}
   360  				d.ID = &ID
   361  			}
   362  		case "name":
   363  			if v != nil {
   364  				var name string
   365  				err = json.Unmarshal(*v, &name)
   366  				if err != nil {
   367  					return err
   368  				}
   369  				d.Name = &name
   370  			}
   371  		case "type":
   372  			if v != nil {
   373  				var typeVar string
   374  				err = json.Unmarshal(*v, &typeVar)
   375  				if err != nil {
   376  					return err
   377  				}
   378  				d.Type = &typeVar
   379  			}
   380  		}
   381  	}
   382  
   383  	return nil
   384  }
   385  
   386  // DefinitionListResult list of policy definitions.
   387  type DefinitionListResult struct {
   388  	autorest.Response `json:"-"`
   389  	// Value - An array of policy definitions.
   390  	Value *[]Definition `json:"value,omitempty"`
   391  	// NextLink - The URL to use for getting the next set of results.
   392  	NextLink *string `json:"nextLink,omitempty"`
   393  }
   394  
   395  // DefinitionListResultIterator provides access to a complete listing of Definition values.
   396  type DefinitionListResultIterator struct {
   397  	i    int
   398  	page DefinitionListResultPage
   399  }
   400  
   401  // NextWithContext advances to the next value.  If there was an error making
   402  // the request the iterator does not advance and the error is returned.
   403  func (iter *DefinitionListResultIterator) NextWithContext(ctx context.Context) (err error) {
   404  	if tracing.IsEnabled() {
   405  		ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionListResultIterator.NextWithContext")
   406  		defer func() {
   407  			sc := -1
   408  			if iter.Response().Response.Response != nil {
   409  				sc = iter.Response().Response.Response.StatusCode
   410  			}
   411  			tracing.EndSpan(ctx, sc, err)
   412  		}()
   413  	}
   414  	iter.i++
   415  	if iter.i < len(iter.page.Values()) {
   416  		return nil
   417  	}
   418  	err = iter.page.NextWithContext(ctx)
   419  	if err != nil {
   420  		iter.i--
   421  		return err
   422  	}
   423  	iter.i = 0
   424  	return nil
   425  }
   426  
   427  // Next advances to the next value.  If there was an error making
   428  // the request the iterator does not advance and the error is returned.
   429  // Deprecated: Use NextWithContext() instead.
   430  func (iter *DefinitionListResultIterator) Next() error {
   431  	return iter.NextWithContext(context.Background())
   432  }
   433  
   434  // NotDone returns true if the enumeration should be started or is not yet complete.
   435  func (iter DefinitionListResultIterator) NotDone() bool {
   436  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   437  }
   438  
   439  // Response returns the raw server response from the last page request.
   440  func (iter DefinitionListResultIterator) Response() DefinitionListResult {
   441  	return iter.page.Response()
   442  }
   443  
   444  // Value returns the current value or a zero-initialized value if the
   445  // iterator has advanced beyond the end of the collection.
   446  func (iter DefinitionListResultIterator) Value() Definition {
   447  	if !iter.page.NotDone() {
   448  		return Definition{}
   449  	}
   450  	return iter.page.Values()[iter.i]
   451  }
   452  
   453  // Creates a new instance of the DefinitionListResultIterator type.
   454  func NewDefinitionListResultIterator(page DefinitionListResultPage) DefinitionListResultIterator {
   455  	return DefinitionListResultIterator{page: page}
   456  }
   457  
   458  // IsEmpty returns true if the ListResult contains no values.
   459  func (dlr DefinitionListResult) IsEmpty() bool {
   460  	return dlr.Value == nil || len(*dlr.Value) == 0
   461  }
   462  
   463  // hasNextLink returns true if the NextLink is not empty.
   464  func (dlr DefinitionListResult) hasNextLink() bool {
   465  	return dlr.NextLink != nil && len(*dlr.NextLink) != 0
   466  }
   467  
   468  // definitionListResultPreparer prepares a request to retrieve the next set of results.
   469  // It returns nil if no more results exist.
   470  func (dlr DefinitionListResult) definitionListResultPreparer(ctx context.Context) (*http.Request, error) {
   471  	if !dlr.hasNextLink() {
   472  		return nil, nil
   473  	}
   474  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   475  		autorest.AsJSON(),
   476  		autorest.AsGet(),
   477  		autorest.WithBaseURL(to.String(dlr.NextLink)))
   478  }
   479  
   480  // DefinitionListResultPage contains a page of Definition values.
   481  type DefinitionListResultPage struct {
   482  	fn  func(context.Context, DefinitionListResult) (DefinitionListResult, error)
   483  	dlr DefinitionListResult
   484  }
   485  
   486  // NextWithContext advances to the next page of values.  If there was an error making
   487  // the request the page does not advance and the error is returned.
   488  func (page *DefinitionListResultPage) NextWithContext(ctx context.Context) (err error) {
   489  	if tracing.IsEnabled() {
   490  		ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionListResultPage.NextWithContext")
   491  		defer func() {
   492  			sc := -1
   493  			if page.Response().Response.Response != nil {
   494  				sc = page.Response().Response.Response.StatusCode
   495  			}
   496  			tracing.EndSpan(ctx, sc, err)
   497  		}()
   498  	}
   499  	for {
   500  		next, err := page.fn(ctx, page.dlr)
   501  		if err != nil {
   502  			return err
   503  		}
   504  		page.dlr = next
   505  		if !next.hasNextLink() || !next.IsEmpty() {
   506  			break
   507  		}
   508  	}
   509  	return nil
   510  }
   511  
   512  // Next advances to the next page of values.  If there was an error making
   513  // the request the page does not advance and the error is returned.
   514  // Deprecated: Use NextWithContext() instead.
   515  func (page *DefinitionListResultPage) Next() error {
   516  	return page.NextWithContext(context.Background())
   517  }
   518  
   519  // NotDone returns true if the page enumeration should be started or is not yet complete.
   520  func (page DefinitionListResultPage) NotDone() bool {
   521  	return !page.dlr.IsEmpty()
   522  }
   523  
   524  // Response returns the raw server response from the last page request.
   525  func (page DefinitionListResultPage) Response() DefinitionListResult {
   526  	return page.dlr
   527  }
   528  
   529  // Values returns the slice of values for the current page or nil if there are no values.
   530  func (page DefinitionListResultPage) Values() []Definition {
   531  	if page.dlr.IsEmpty() {
   532  		return nil
   533  	}
   534  	return *page.dlr.Value
   535  }
   536  
   537  // Creates a new instance of the DefinitionListResultPage type.
   538  func NewDefinitionListResultPage(cur DefinitionListResult, getNextPage func(context.Context, DefinitionListResult) (DefinitionListResult, error)) DefinitionListResultPage {
   539  	return DefinitionListResultPage{
   540  		fn:  getNextPage,
   541  		dlr: cur,
   542  	}
   543  }
   544  
   545  // DefinitionProperties the policy definition properties.
   546  type DefinitionProperties struct {
   547  	// PolicyType - The type of policy definition. Possible values are NotSpecified, BuiltIn, and Custom. Possible values include: 'TypeNotSpecified', 'TypeBuiltIn', 'TypeCustom'
   548  	PolicyType Type `json:"policyType,omitempty"`
   549  	// Mode - The policy definition mode. Possible values are NotSpecified, Indexed, and All. Possible values include: 'NotSpecified', 'Indexed', 'All'
   550  	Mode Mode `json:"mode,omitempty"`
   551  	// DisplayName - The display name of the policy definition.
   552  	DisplayName *string `json:"displayName,omitempty"`
   553  	// Description - The policy definition description.
   554  	Description *string `json:"description,omitempty"`
   555  	// PolicyRule - The policy rule.
   556  	PolicyRule interface{} `json:"policyRule,omitempty"`
   557  	// Metadata - The policy definition metadata.
   558  	Metadata interface{} `json:"metadata,omitempty"`
   559  	// Parameters - Required if a parameter is used in policy rule.
   560  	Parameters interface{} `json:"parameters,omitempty"`
   561  }
   562  
   563  // DefinitionReference the policy definition reference.
   564  type DefinitionReference struct {
   565  	// PolicyDefinitionID - The ID of the policy definition or policy set definition.
   566  	PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"`
   567  	// Parameters - Required if a parameter is used in policy rule.
   568  	Parameters interface{} `json:"parameters,omitempty"`
   569  }
   570  
   571  // ErrorResponse error response indicates Azure Resource Manager is not able to process the incoming
   572  // request. The reason is provided in the error message.
   573  type ErrorResponse struct {
   574  	// HTTPStatus - Http status code.
   575  	HTTPStatus *string `json:"httpStatus,omitempty"`
   576  	// ErrorCode - Error code.
   577  	ErrorCode *string `json:"errorCode,omitempty"`
   578  	// ErrorMessage - Error message indicating why the operation failed.
   579  	ErrorMessage *string `json:"errorMessage,omitempty"`
   580  }
   581  
   582  // Identity identity for the resource.
   583  type Identity struct {
   584  	// PrincipalID - READ-ONLY; The principal ID of the resource identity.
   585  	PrincipalID *string `json:"principalId,omitempty"`
   586  	// TenantID - READ-ONLY; The tenant ID of the resource identity.
   587  	TenantID *string `json:"tenantId,omitempty"`
   588  	// Type - The identity type. Possible values include: 'SystemAssigned', 'None'
   589  	Type ResourceIdentityType `json:"type,omitempty"`
   590  }
   591  
   592  // MarshalJSON is the custom marshaler for Identity.
   593  func (i Identity) MarshalJSON() ([]byte, error) {
   594  	objectMap := make(map[string]interface{})
   595  	if i.Type != "" {
   596  		objectMap["type"] = i.Type
   597  	}
   598  	return json.Marshal(objectMap)
   599  }
   600  
   601  // SetDefinition the policy set definition.
   602  type SetDefinition struct {
   603  	autorest.Response `json:"-"`
   604  	// SetDefinitionProperties - The policy definition properties.
   605  	*SetDefinitionProperties `json:"properties,omitempty"`
   606  	// ID - READ-ONLY; The ID of the policy set definition.
   607  	ID *string `json:"id,omitempty"`
   608  	// Name - READ-ONLY; The name of the policy set definition.
   609  	Name *string `json:"name,omitempty"`
   610  	// Type - READ-ONLY; The type of the resource (Microsoft.Authorization/policySetDefinitions).
   611  	Type *string `json:"type,omitempty"`
   612  }
   613  
   614  // MarshalJSON is the custom marshaler for SetDefinition.
   615  func (sd SetDefinition) MarshalJSON() ([]byte, error) {
   616  	objectMap := make(map[string]interface{})
   617  	if sd.SetDefinitionProperties != nil {
   618  		objectMap["properties"] = sd.SetDefinitionProperties
   619  	}
   620  	return json.Marshal(objectMap)
   621  }
   622  
   623  // UnmarshalJSON is the custom unmarshaler for SetDefinition struct.
   624  func (sd *SetDefinition) UnmarshalJSON(body []byte) error {
   625  	var m map[string]*json.RawMessage
   626  	err := json.Unmarshal(body, &m)
   627  	if err != nil {
   628  		return err
   629  	}
   630  	for k, v := range m {
   631  		switch k {
   632  		case "properties":
   633  			if v != nil {
   634  				var setDefinitionProperties SetDefinitionProperties
   635  				err = json.Unmarshal(*v, &setDefinitionProperties)
   636  				if err != nil {
   637  					return err
   638  				}
   639  				sd.SetDefinitionProperties = &setDefinitionProperties
   640  			}
   641  		case "id":
   642  			if v != nil {
   643  				var ID string
   644  				err = json.Unmarshal(*v, &ID)
   645  				if err != nil {
   646  					return err
   647  				}
   648  				sd.ID = &ID
   649  			}
   650  		case "name":
   651  			if v != nil {
   652  				var name string
   653  				err = json.Unmarshal(*v, &name)
   654  				if err != nil {
   655  					return err
   656  				}
   657  				sd.Name = &name
   658  			}
   659  		case "type":
   660  			if v != nil {
   661  				var typeVar string
   662  				err = json.Unmarshal(*v, &typeVar)
   663  				if err != nil {
   664  					return err
   665  				}
   666  				sd.Type = &typeVar
   667  			}
   668  		}
   669  	}
   670  
   671  	return nil
   672  }
   673  
   674  // SetDefinitionListResult list of policy set definitions.
   675  type SetDefinitionListResult struct {
   676  	autorest.Response `json:"-"`
   677  	// Value - An array of policy set definitions.
   678  	Value *[]SetDefinition `json:"value,omitempty"`
   679  	// NextLink - The URL to use for getting the next set of results.
   680  	NextLink *string `json:"nextLink,omitempty"`
   681  }
   682  
   683  // SetDefinitionListResultIterator provides access to a complete listing of SetDefinition values.
   684  type SetDefinitionListResultIterator struct {
   685  	i    int
   686  	page SetDefinitionListResultPage
   687  }
   688  
   689  // NextWithContext advances to the next value.  If there was an error making
   690  // the request the iterator does not advance and the error is returned.
   691  func (iter *SetDefinitionListResultIterator) NextWithContext(ctx context.Context) (err error) {
   692  	if tracing.IsEnabled() {
   693  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionListResultIterator.NextWithContext")
   694  		defer func() {
   695  			sc := -1
   696  			if iter.Response().Response.Response != nil {
   697  				sc = iter.Response().Response.Response.StatusCode
   698  			}
   699  			tracing.EndSpan(ctx, sc, err)
   700  		}()
   701  	}
   702  	iter.i++
   703  	if iter.i < len(iter.page.Values()) {
   704  		return nil
   705  	}
   706  	err = iter.page.NextWithContext(ctx)
   707  	if err != nil {
   708  		iter.i--
   709  		return err
   710  	}
   711  	iter.i = 0
   712  	return nil
   713  }
   714  
   715  // Next advances to the next value.  If there was an error making
   716  // the request the iterator does not advance and the error is returned.
   717  // Deprecated: Use NextWithContext() instead.
   718  func (iter *SetDefinitionListResultIterator) Next() error {
   719  	return iter.NextWithContext(context.Background())
   720  }
   721  
   722  // NotDone returns true if the enumeration should be started or is not yet complete.
   723  func (iter SetDefinitionListResultIterator) NotDone() bool {
   724  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   725  }
   726  
   727  // Response returns the raw server response from the last page request.
   728  func (iter SetDefinitionListResultIterator) Response() SetDefinitionListResult {
   729  	return iter.page.Response()
   730  }
   731  
   732  // Value returns the current value or a zero-initialized value if the
   733  // iterator has advanced beyond the end of the collection.
   734  func (iter SetDefinitionListResultIterator) Value() SetDefinition {
   735  	if !iter.page.NotDone() {
   736  		return SetDefinition{}
   737  	}
   738  	return iter.page.Values()[iter.i]
   739  }
   740  
   741  // Creates a new instance of the SetDefinitionListResultIterator type.
   742  func NewSetDefinitionListResultIterator(page SetDefinitionListResultPage) SetDefinitionListResultIterator {
   743  	return SetDefinitionListResultIterator{page: page}
   744  }
   745  
   746  // IsEmpty returns true if the ListResult contains no values.
   747  func (sdlr SetDefinitionListResult) IsEmpty() bool {
   748  	return sdlr.Value == nil || len(*sdlr.Value) == 0
   749  }
   750  
   751  // hasNextLink returns true if the NextLink is not empty.
   752  func (sdlr SetDefinitionListResult) hasNextLink() bool {
   753  	return sdlr.NextLink != nil && len(*sdlr.NextLink) != 0
   754  }
   755  
   756  // setDefinitionListResultPreparer prepares a request to retrieve the next set of results.
   757  // It returns nil if no more results exist.
   758  func (sdlr SetDefinitionListResult) setDefinitionListResultPreparer(ctx context.Context) (*http.Request, error) {
   759  	if !sdlr.hasNextLink() {
   760  		return nil, nil
   761  	}
   762  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   763  		autorest.AsJSON(),
   764  		autorest.AsGet(),
   765  		autorest.WithBaseURL(to.String(sdlr.NextLink)))
   766  }
   767  
   768  // SetDefinitionListResultPage contains a page of SetDefinition values.
   769  type SetDefinitionListResultPage struct {
   770  	fn   func(context.Context, SetDefinitionListResult) (SetDefinitionListResult, error)
   771  	sdlr SetDefinitionListResult
   772  }
   773  
   774  // NextWithContext advances to the next page of values.  If there was an error making
   775  // the request the page does not advance and the error is returned.
   776  func (page *SetDefinitionListResultPage) NextWithContext(ctx context.Context) (err error) {
   777  	if tracing.IsEnabled() {
   778  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionListResultPage.NextWithContext")
   779  		defer func() {
   780  			sc := -1
   781  			if page.Response().Response.Response != nil {
   782  				sc = page.Response().Response.Response.StatusCode
   783  			}
   784  			tracing.EndSpan(ctx, sc, err)
   785  		}()
   786  	}
   787  	for {
   788  		next, err := page.fn(ctx, page.sdlr)
   789  		if err != nil {
   790  			return err
   791  		}
   792  		page.sdlr = next
   793  		if !next.hasNextLink() || !next.IsEmpty() {
   794  			break
   795  		}
   796  	}
   797  	return nil
   798  }
   799  
   800  // Next advances to the next page of values.  If there was an error making
   801  // the request the page does not advance and the error is returned.
   802  // Deprecated: Use NextWithContext() instead.
   803  func (page *SetDefinitionListResultPage) Next() error {
   804  	return page.NextWithContext(context.Background())
   805  }
   806  
   807  // NotDone returns true if the page enumeration should be started or is not yet complete.
   808  func (page SetDefinitionListResultPage) NotDone() bool {
   809  	return !page.sdlr.IsEmpty()
   810  }
   811  
   812  // Response returns the raw server response from the last page request.
   813  func (page SetDefinitionListResultPage) Response() SetDefinitionListResult {
   814  	return page.sdlr
   815  }
   816  
   817  // Values returns the slice of values for the current page or nil if there are no values.
   818  func (page SetDefinitionListResultPage) Values() []SetDefinition {
   819  	if page.sdlr.IsEmpty() {
   820  		return nil
   821  	}
   822  	return *page.sdlr.Value
   823  }
   824  
   825  // Creates a new instance of the SetDefinitionListResultPage type.
   826  func NewSetDefinitionListResultPage(cur SetDefinitionListResult, getNextPage func(context.Context, SetDefinitionListResult) (SetDefinitionListResult, error)) SetDefinitionListResultPage {
   827  	return SetDefinitionListResultPage{
   828  		fn:   getNextPage,
   829  		sdlr: cur,
   830  	}
   831  }
   832  
   833  // SetDefinitionProperties the policy set definition properties.
   834  type SetDefinitionProperties struct {
   835  	// PolicyType - The type of policy definition. Possible values are NotSpecified, BuiltIn, and Custom. Possible values include: 'TypeNotSpecified', 'TypeBuiltIn', 'TypeCustom'
   836  	PolicyType Type `json:"policyType,omitempty"`
   837  	// DisplayName - The display name of the policy set definition.
   838  	DisplayName *string `json:"displayName,omitempty"`
   839  	// Description - The policy set definition description.
   840  	Description *string `json:"description,omitempty"`
   841  	// Metadata - The policy set definition metadata.
   842  	Metadata interface{} `json:"metadata,omitempty"`
   843  	// Parameters - The policy set definition parameters that can be used in policy definition references.
   844  	Parameters interface{} `json:"parameters,omitempty"`
   845  	// PolicyDefinitions - An array of policy definition references.
   846  	PolicyDefinitions *[]DefinitionReference `json:"policyDefinitions,omitempty"`
   847  }
   848  
   849  // Sku the policy sku. This property is optional, obsolete, and will be ignored.
   850  type Sku struct {
   851  	// Name - The name of the policy sku. Possible values are A0 and A1.
   852  	Name *string `json:"name,omitempty"`
   853  	// Tier - The policy sku tier. Possible values are Free and Standard.
   854  	Tier *string `json:"tier,omitempty"`
   855  }
   856  

View as plain text