...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2019-06-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/2019-06-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  	// EnforcementMode - The policy assignment enforcement mode. Possible values are Default and DoNotEnforce. Possible values include: 'Default', 'DoNotEnforce'
   312  	EnforcementMode EnforcementMode `json:"enforcementMode,omitempty"`
   313  }
   314  
   315  // Definition the policy definition.
   316  type Definition struct {
   317  	autorest.Response `json:"-"`
   318  	// DefinitionProperties - The policy definition properties.
   319  	*DefinitionProperties `json:"properties,omitempty"`
   320  	// ID - READ-ONLY; The ID of the policy definition.
   321  	ID *string `json:"id,omitempty"`
   322  	// Name - READ-ONLY; The name of the policy definition.
   323  	Name *string `json:"name,omitempty"`
   324  	// Type - READ-ONLY; The type of the resource (Microsoft.Authorization/policyDefinitions).
   325  	Type *string `json:"type,omitempty"`
   326  }
   327  
   328  // MarshalJSON is the custom marshaler for Definition.
   329  func (d Definition) MarshalJSON() ([]byte, error) {
   330  	objectMap := make(map[string]interface{})
   331  	if d.DefinitionProperties != nil {
   332  		objectMap["properties"] = d.DefinitionProperties
   333  	}
   334  	return json.Marshal(objectMap)
   335  }
   336  
   337  // UnmarshalJSON is the custom unmarshaler for Definition struct.
   338  func (d *Definition) UnmarshalJSON(body []byte) error {
   339  	var m map[string]*json.RawMessage
   340  	err := json.Unmarshal(body, &m)
   341  	if err != nil {
   342  		return err
   343  	}
   344  	for k, v := range m {
   345  		switch k {
   346  		case "properties":
   347  			if v != nil {
   348  				var definitionProperties DefinitionProperties
   349  				err = json.Unmarshal(*v, &definitionProperties)
   350  				if err != nil {
   351  					return err
   352  				}
   353  				d.DefinitionProperties = &definitionProperties
   354  			}
   355  		case "id":
   356  			if v != nil {
   357  				var ID string
   358  				err = json.Unmarshal(*v, &ID)
   359  				if err != nil {
   360  					return err
   361  				}
   362  				d.ID = &ID
   363  			}
   364  		case "name":
   365  			if v != nil {
   366  				var name string
   367  				err = json.Unmarshal(*v, &name)
   368  				if err != nil {
   369  					return err
   370  				}
   371  				d.Name = &name
   372  			}
   373  		case "type":
   374  			if v != nil {
   375  				var typeVar string
   376  				err = json.Unmarshal(*v, &typeVar)
   377  				if err != nil {
   378  					return err
   379  				}
   380  				d.Type = &typeVar
   381  			}
   382  		}
   383  	}
   384  
   385  	return nil
   386  }
   387  
   388  // DefinitionListResult list of policy definitions.
   389  type DefinitionListResult struct {
   390  	autorest.Response `json:"-"`
   391  	// Value - An array of policy definitions.
   392  	Value *[]Definition `json:"value,omitempty"`
   393  	// NextLink - The URL to use for getting the next set of results.
   394  	NextLink *string `json:"nextLink,omitempty"`
   395  }
   396  
   397  // DefinitionListResultIterator provides access to a complete listing of Definition values.
   398  type DefinitionListResultIterator struct {
   399  	i    int
   400  	page DefinitionListResultPage
   401  }
   402  
   403  // NextWithContext advances to the next value.  If there was an error making
   404  // the request the iterator does not advance and the error is returned.
   405  func (iter *DefinitionListResultIterator) NextWithContext(ctx context.Context) (err error) {
   406  	if tracing.IsEnabled() {
   407  		ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionListResultIterator.NextWithContext")
   408  		defer func() {
   409  			sc := -1
   410  			if iter.Response().Response.Response != nil {
   411  				sc = iter.Response().Response.Response.StatusCode
   412  			}
   413  			tracing.EndSpan(ctx, sc, err)
   414  		}()
   415  	}
   416  	iter.i++
   417  	if iter.i < len(iter.page.Values()) {
   418  		return nil
   419  	}
   420  	err = iter.page.NextWithContext(ctx)
   421  	if err != nil {
   422  		iter.i--
   423  		return err
   424  	}
   425  	iter.i = 0
   426  	return nil
   427  }
   428  
   429  // Next advances to the next value.  If there was an error making
   430  // the request the iterator does not advance and the error is returned.
   431  // Deprecated: Use NextWithContext() instead.
   432  func (iter *DefinitionListResultIterator) Next() error {
   433  	return iter.NextWithContext(context.Background())
   434  }
   435  
   436  // NotDone returns true if the enumeration should be started or is not yet complete.
   437  func (iter DefinitionListResultIterator) NotDone() bool {
   438  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   439  }
   440  
   441  // Response returns the raw server response from the last page request.
   442  func (iter DefinitionListResultIterator) Response() DefinitionListResult {
   443  	return iter.page.Response()
   444  }
   445  
   446  // Value returns the current value or a zero-initialized value if the
   447  // iterator has advanced beyond the end of the collection.
   448  func (iter DefinitionListResultIterator) Value() Definition {
   449  	if !iter.page.NotDone() {
   450  		return Definition{}
   451  	}
   452  	return iter.page.Values()[iter.i]
   453  }
   454  
   455  // Creates a new instance of the DefinitionListResultIterator type.
   456  func NewDefinitionListResultIterator(page DefinitionListResultPage) DefinitionListResultIterator {
   457  	return DefinitionListResultIterator{page: page}
   458  }
   459  
   460  // IsEmpty returns true if the ListResult contains no values.
   461  func (dlr DefinitionListResult) IsEmpty() bool {
   462  	return dlr.Value == nil || len(*dlr.Value) == 0
   463  }
   464  
   465  // hasNextLink returns true if the NextLink is not empty.
   466  func (dlr DefinitionListResult) hasNextLink() bool {
   467  	return dlr.NextLink != nil && len(*dlr.NextLink) != 0
   468  }
   469  
   470  // definitionListResultPreparer prepares a request to retrieve the next set of results.
   471  // It returns nil if no more results exist.
   472  func (dlr DefinitionListResult) definitionListResultPreparer(ctx context.Context) (*http.Request, error) {
   473  	if !dlr.hasNextLink() {
   474  		return nil, nil
   475  	}
   476  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   477  		autorest.AsJSON(),
   478  		autorest.AsGet(),
   479  		autorest.WithBaseURL(to.String(dlr.NextLink)))
   480  }
   481  
   482  // DefinitionListResultPage contains a page of Definition values.
   483  type DefinitionListResultPage struct {
   484  	fn  func(context.Context, DefinitionListResult) (DefinitionListResult, error)
   485  	dlr DefinitionListResult
   486  }
   487  
   488  // NextWithContext advances to the next page of values.  If there was an error making
   489  // the request the page does not advance and the error is returned.
   490  func (page *DefinitionListResultPage) NextWithContext(ctx context.Context) (err error) {
   491  	if tracing.IsEnabled() {
   492  		ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionListResultPage.NextWithContext")
   493  		defer func() {
   494  			sc := -1
   495  			if page.Response().Response.Response != nil {
   496  				sc = page.Response().Response.Response.StatusCode
   497  			}
   498  			tracing.EndSpan(ctx, sc, err)
   499  		}()
   500  	}
   501  	for {
   502  		next, err := page.fn(ctx, page.dlr)
   503  		if err != nil {
   504  			return err
   505  		}
   506  		page.dlr = next
   507  		if !next.hasNextLink() || !next.IsEmpty() {
   508  			break
   509  		}
   510  	}
   511  	return nil
   512  }
   513  
   514  // Next advances to the next page of values.  If there was an error making
   515  // the request the page does not advance and the error is returned.
   516  // Deprecated: Use NextWithContext() instead.
   517  func (page *DefinitionListResultPage) Next() error {
   518  	return page.NextWithContext(context.Background())
   519  }
   520  
   521  // NotDone returns true if the page enumeration should be started or is not yet complete.
   522  func (page DefinitionListResultPage) NotDone() bool {
   523  	return !page.dlr.IsEmpty()
   524  }
   525  
   526  // Response returns the raw server response from the last page request.
   527  func (page DefinitionListResultPage) Response() DefinitionListResult {
   528  	return page.dlr
   529  }
   530  
   531  // Values returns the slice of values for the current page or nil if there are no values.
   532  func (page DefinitionListResultPage) Values() []Definition {
   533  	if page.dlr.IsEmpty() {
   534  		return nil
   535  	}
   536  	return *page.dlr.Value
   537  }
   538  
   539  // Creates a new instance of the DefinitionListResultPage type.
   540  func NewDefinitionListResultPage(cur DefinitionListResult, getNextPage func(context.Context, DefinitionListResult) (DefinitionListResult, error)) DefinitionListResultPage {
   541  	return DefinitionListResultPage{
   542  		fn:  getNextPage,
   543  		dlr: cur,
   544  	}
   545  }
   546  
   547  // DefinitionProperties the policy definition properties.
   548  type DefinitionProperties struct {
   549  	// PolicyType - The type of policy definition. Possible values are NotSpecified, BuiltIn, and Custom. Possible values include: 'NotSpecified', 'BuiltIn', 'Custom'
   550  	PolicyType Type `json:"policyType,omitempty"`
   551  	// Mode - The policy definition mode. Some examples are All, Indexed, Microsoft.KeyVault.Data.
   552  	Mode *string `json:"mode,omitempty"`
   553  	// DisplayName - The display name of the policy definition.
   554  	DisplayName *string `json:"displayName,omitempty"`
   555  	// Description - The policy definition description.
   556  	Description *string `json:"description,omitempty"`
   557  	// PolicyRule - The policy rule.
   558  	PolicyRule interface{} `json:"policyRule,omitempty"`
   559  	// Metadata - The policy definition metadata.
   560  	Metadata interface{} `json:"metadata,omitempty"`
   561  	// Parameters - Required if a parameter is used in policy rule.
   562  	Parameters interface{} `json:"parameters,omitempty"`
   563  }
   564  
   565  // DefinitionReference the policy definition reference.
   566  type DefinitionReference struct {
   567  	// PolicyDefinitionID - The ID of the policy definition or policy set definition.
   568  	PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"`
   569  	// Parameters - Required if a parameter is used in policy rule.
   570  	Parameters interface{} `json:"parameters,omitempty"`
   571  }
   572  
   573  // ErrorResponse error response indicates Azure Resource Manager is not able to process the incoming
   574  // request. The reason is provided in the error message.
   575  type ErrorResponse struct {
   576  	// HTTPStatus - Http status code.
   577  	HTTPStatus *string `json:"httpStatus,omitempty"`
   578  	// ErrorCode - Error code.
   579  	ErrorCode *string `json:"errorCode,omitempty"`
   580  	// ErrorMessage - Error message indicating why the operation failed.
   581  	ErrorMessage *string `json:"errorMessage,omitempty"`
   582  }
   583  
   584  // Identity identity for the resource.
   585  type Identity struct {
   586  	// PrincipalID - READ-ONLY; The principal ID of the resource identity.
   587  	PrincipalID *string `json:"principalId,omitempty"`
   588  	// TenantID - READ-ONLY; The tenant ID of the resource identity.
   589  	TenantID *string `json:"tenantId,omitempty"`
   590  	// Type - The identity type. Possible values include: 'SystemAssigned', 'None'
   591  	Type ResourceIdentityType `json:"type,omitempty"`
   592  }
   593  
   594  // MarshalJSON is the custom marshaler for Identity.
   595  func (i Identity) MarshalJSON() ([]byte, error) {
   596  	objectMap := make(map[string]interface{})
   597  	if i.Type != "" {
   598  		objectMap["type"] = i.Type
   599  	}
   600  	return json.Marshal(objectMap)
   601  }
   602  
   603  // SetDefinition the policy set definition.
   604  type SetDefinition struct {
   605  	autorest.Response `json:"-"`
   606  	// SetDefinitionProperties - The policy definition properties.
   607  	*SetDefinitionProperties `json:"properties,omitempty"`
   608  	// ID - READ-ONLY; The ID of the policy set definition.
   609  	ID *string `json:"id,omitempty"`
   610  	// Name - READ-ONLY; The name of the policy set definition.
   611  	Name *string `json:"name,omitempty"`
   612  	// Type - READ-ONLY; The type of the resource (Microsoft.Authorization/policySetDefinitions).
   613  	Type *string `json:"type,omitempty"`
   614  }
   615  
   616  // MarshalJSON is the custom marshaler for SetDefinition.
   617  func (sd SetDefinition) MarshalJSON() ([]byte, error) {
   618  	objectMap := make(map[string]interface{})
   619  	if sd.SetDefinitionProperties != nil {
   620  		objectMap["properties"] = sd.SetDefinitionProperties
   621  	}
   622  	return json.Marshal(objectMap)
   623  }
   624  
   625  // UnmarshalJSON is the custom unmarshaler for SetDefinition struct.
   626  func (sd *SetDefinition) UnmarshalJSON(body []byte) error {
   627  	var m map[string]*json.RawMessage
   628  	err := json.Unmarshal(body, &m)
   629  	if err != nil {
   630  		return err
   631  	}
   632  	for k, v := range m {
   633  		switch k {
   634  		case "properties":
   635  			if v != nil {
   636  				var setDefinitionProperties SetDefinitionProperties
   637  				err = json.Unmarshal(*v, &setDefinitionProperties)
   638  				if err != nil {
   639  					return err
   640  				}
   641  				sd.SetDefinitionProperties = &setDefinitionProperties
   642  			}
   643  		case "id":
   644  			if v != nil {
   645  				var ID string
   646  				err = json.Unmarshal(*v, &ID)
   647  				if err != nil {
   648  					return err
   649  				}
   650  				sd.ID = &ID
   651  			}
   652  		case "name":
   653  			if v != nil {
   654  				var name string
   655  				err = json.Unmarshal(*v, &name)
   656  				if err != nil {
   657  					return err
   658  				}
   659  				sd.Name = &name
   660  			}
   661  		case "type":
   662  			if v != nil {
   663  				var typeVar string
   664  				err = json.Unmarshal(*v, &typeVar)
   665  				if err != nil {
   666  					return err
   667  				}
   668  				sd.Type = &typeVar
   669  			}
   670  		}
   671  	}
   672  
   673  	return nil
   674  }
   675  
   676  // SetDefinitionListResult list of policy set definitions.
   677  type SetDefinitionListResult struct {
   678  	autorest.Response `json:"-"`
   679  	// Value - An array of policy set definitions.
   680  	Value *[]SetDefinition `json:"value,omitempty"`
   681  	// NextLink - The URL to use for getting the next set of results.
   682  	NextLink *string `json:"nextLink,omitempty"`
   683  }
   684  
   685  // SetDefinitionListResultIterator provides access to a complete listing of SetDefinition values.
   686  type SetDefinitionListResultIterator struct {
   687  	i    int
   688  	page SetDefinitionListResultPage
   689  }
   690  
   691  // NextWithContext advances to the next value.  If there was an error making
   692  // the request the iterator does not advance and the error is returned.
   693  func (iter *SetDefinitionListResultIterator) NextWithContext(ctx context.Context) (err error) {
   694  	if tracing.IsEnabled() {
   695  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionListResultIterator.NextWithContext")
   696  		defer func() {
   697  			sc := -1
   698  			if iter.Response().Response.Response != nil {
   699  				sc = iter.Response().Response.Response.StatusCode
   700  			}
   701  			tracing.EndSpan(ctx, sc, err)
   702  		}()
   703  	}
   704  	iter.i++
   705  	if iter.i < len(iter.page.Values()) {
   706  		return nil
   707  	}
   708  	err = iter.page.NextWithContext(ctx)
   709  	if err != nil {
   710  		iter.i--
   711  		return err
   712  	}
   713  	iter.i = 0
   714  	return nil
   715  }
   716  
   717  // Next advances to the next value.  If there was an error making
   718  // the request the iterator does not advance and the error is returned.
   719  // Deprecated: Use NextWithContext() instead.
   720  func (iter *SetDefinitionListResultIterator) Next() error {
   721  	return iter.NextWithContext(context.Background())
   722  }
   723  
   724  // NotDone returns true if the enumeration should be started or is not yet complete.
   725  func (iter SetDefinitionListResultIterator) NotDone() bool {
   726  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   727  }
   728  
   729  // Response returns the raw server response from the last page request.
   730  func (iter SetDefinitionListResultIterator) Response() SetDefinitionListResult {
   731  	return iter.page.Response()
   732  }
   733  
   734  // Value returns the current value or a zero-initialized value if the
   735  // iterator has advanced beyond the end of the collection.
   736  func (iter SetDefinitionListResultIterator) Value() SetDefinition {
   737  	if !iter.page.NotDone() {
   738  		return SetDefinition{}
   739  	}
   740  	return iter.page.Values()[iter.i]
   741  }
   742  
   743  // Creates a new instance of the SetDefinitionListResultIterator type.
   744  func NewSetDefinitionListResultIterator(page SetDefinitionListResultPage) SetDefinitionListResultIterator {
   745  	return SetDefinitionListResultIterator{page: page}
   746  }
   747  
   748  // IsEmpty returns true if the ListResult contains no values.
   749  func (sdlr SetDefinitionListResult) IsEmpty() bool {
   750  	return sdlr.Value == nil || len(*sdlr.Value) == 0
   751  }
   752  
   753  // hasNextLink returns true if the NextLink is not empty.
   754  func (sdlr SetDefinitionListResult) hasNextLink() bool {
   755  	return sdlr.NextLink != nil && len(*sdlr.NextLink) != 0
   756  }
   757  
   758  // setDefinitionListResultPreparer prepares a request to retrieve the next set of results.
   759  // It returns nil if no more results exist.
   760  func (sdlr SetDefinitionListResult) setDefinitionListResultPreparer(ctx context.Context) (*http.Request, error) {
   761  	if !sdlr.hasNextLink() {
   762  		return nil, nil
   763  	}
   764  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   765  		autorest.AsJSON(),
   766  		autorest.AsGet(),
   767  		autorest.WithBaseURL(to.String(sdlr.NextLink)))
   768  }
   769  
   770  // SetDefinitionListResultPage contains a page of SetDefinition values.
   771  type SetDefinitionListResultPage struct {
   772  	fn   func(context.Context, SetDefinitionListResult) (SetDefinitionListResult, error)
   773  	sdlr SetDefinitionListResult
   774  }
   775  
   776  // NextWithContext advances to the next page of values.  If there was an error making
   777  // the request the page does not advance and the error is returned.
   778  func (page *SetDefinitionListResultPage) NextWithContext(ctx context.Context) (err error) {
   779  	if tracing.IsEnabled() {
   780  		ctx = tracing.StartSpan(ctx, fqdn+"/SetDefinitionListResultPage.NextWithContext")
   781  		defer func() {
   782  			sc := -1
   783  			if page.Response().Response.Response != nil {
   784  				sc = page.Response().Response.Response.StatusCode
   785  			}
   786  			tracing.EndSpan(ctx, sc, err)
   787  		}()
   788  	}
   789  	for {
   790  		next, err := page.fn(ctx, page.sdlr)
   791  		if err != nil {
   792  			return err
   793  		}
   794  		page.sdlr = next
   795  		if !next.hasNextLink() || !next.IsEmpty() {
   796  			break
   797  		}
   798  	}
   799  	return nil
   800  }
   801  
   802  // Next advances to the next page of values.  If there was an error making
   803  // the request the page does not advance and the error is returned.
   804  // Deprecated: Use NextWithContext() instead.
   805  func (page *SetDefinitionListResultPage) Next() error {
   806  	return page.NextWithContext(context.Background())
   807  }
   808  
   809  // NotDone returns true if the page enumeration should be started or is not yet complete.
   810  func (page SetDefinitionListResultPage) NotDone() bool {
   811  	return !page.sdlr.IsEmpty()
   812  }
   813  
   814  // Response returns the raw server response from the last page request.
   815  func (page SetDefinitionListResultPage) Response() SetDefinitionListResult {
   816  	return page.sdlr
   817  }
   818  
   819  // Values returns the slice of values for the current page or nil if there are no values.
   820  func (page SetDefinitionListResultPage) Values() []SetDefinition {
   821  	if page.sdlr.IsEmpty() {
   822  		return nil
   823  	}
   824  	return *page.sdlr.Value
   825  }
   826  
   827  // Creates a new instance of the SetDefinitionListResultPage type.
   828  func NewSetDefinitionListResultPage(cur SetDefinitionListResult, getNextPage func(context.Context, SetDefinitionListResult) (SetDefinitionListResult, error)) SetDefinitionListResultPage {
   829  	return SetDefinitionListResultPage{
   830  		fn:   getNextPage,
   831  		sdlr: cur,
   832  	}
   833  }
   834  
   835  // SetDefinitionProperties the policy set definition properties.
   836  type SetDefinitionProperties struct {
   837  	// PolicyType - The type of policy definition. Possible values are NotSpecified, BuiltIn, and Custom. Possible values include: 'NotSpecified', 'BuiltIn', 'Custom'
   838  	PolicyType Type `json:"policyType,omitempty"`
   839  	// DisplayName - The display name of the policy set definition.
   840  	DisplayName *string `json:"displayName,omitempty"`
   841  	// Description - The policy set definition description.
   842  	Description *string `json:"description,omitempty"`
   843  	// Metadata - The policy set definition metadata.
   844  	Metadata interface{} `json:"metadata,omitempty"`
   845  	// Parameters - The policy set definition parameters that can be used in policy definition references.
   846  	Parameters interface{} `json:"parameters,omitempty"`
   847  	// PolicyDefinitions - An array of policy definition references.
   848  	PolicyDefinitions *[]DefinitionReference `json:"policyDefinitions,omitempty"`
   849  }
   850  
   851  // Sku the policy sku. This property is optional, obsolete, and will be ignored.
   852  type Sku struct {
   853  	// Name - The name of the policy sku. Possible values are A0 and A1.
   854  	Name *string `json:"name,omitempty"`
   855  	// Tier - The policy sku tier. Possible values are Free and Standard.
   856  	Tier *string `json:"tier,omitempty"`
   857  }
   858  

View as plain text