...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-12-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/2016-12-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 - The type of the policy assignment.
    29  	Type *string `json:"type,omitempty"`
    30  	// Name - The name of the policy assignment.
    31  	Name *string `json:"name,omitempty"`
    32  }
    33  
    34  // MarshalJSON is the custom marshaler for Assignment.
    35  func (a Assignment) MarshalJSON() ([]byte, error) {
    36  	objectMap := make(map[string]interface{})
    37  	if a.AssignmentProperties != nil {
    38  		objectMap["properties"] = a.AssignmentProperties
    39  	}
    40  	if a.Type != nil {
    41  		objectMap["type"] = a.Type
    42  	}
    43  	if a.Name != nil {
    44  		objectMap["name"] = a.Name
    45  	}
    46  	return json.Marshal(objectMap)
    47  }
    48  
    49  // UnmarshalJSON is the custom unmarshaler for Assignment struct.
    50  func (a *Assignment) UnmarshalJSON(body []byte) error {
    51  	var m map[string]*json.RawMessage
    52  	err := json.Unmarshal(body, &m)
    53  	if err != nil {
    54  		return err
    55  	}
    56  	for k, v := range m {
    57  		switch k {
    58  		case "properties":
    59  			if v != nil {
    60  				var assignmentProperties AssignmentProperties
    61  				err = json.Unmarshal(*v, &assignmentProperties)
    62  				if err != nil {
    63  					return err
    64  				}
    65  				a.AssignmentProperties = &assignmentProperties
    66  			}
    67  		case "id":
    68  			if v != nil {
    69  				var ID string
    70  				err = json.Unmarshal(*v, &ID)
    71  				if err != nil {
    72  					return err
    73  				}
    74  				a.ID = &ID
    75  			}
    76  		case "type":
    77  			if v != nil {
    78  				var typeVar string
    79  				err = json.Unmarshal(*v, &typeVar)
    80  				if err != nil {
    81  					return err
    82  				}
    83  				a.Type = &typeVar
    84  			}
    85  		case "name":
    86  			if v != nil {
    87  				var name string
    88  				err = json.Unmarshal(*v, &name)
    89  				if err != nil {
    90  					return err
    91  				}
    92  				a.Name = &name
    93  			}
    94  		}
    95  	}
    96  
    97  	return nil
    98  }
    99  
   100  // AssignmentListResult list of policy assignments.
   101  type AssignmentListResult struct {
   102  	autorest.Response `json:"-"`
   103  	// Value - An array of policy assignments.
   104  	Value *[]Assignment `json:"value,omitempty"`
   105  	// NextLink - The URL to use for getting the next set of results.
   106  	NextLink *string `json:"nextLink,omitempty"`
   107  }
   108  
   109  // AssignmentListResultIterator provides access to a complete listing of Assignment values.
   110  type AssignmentListResultIterator struct {
   111  	i    int
   112  	page AssignmentListResultPage
   113  }
   114  
   115  // NextWithContext advances to the next value.  If there was an error making
   116  // the request the iterator does not advance and the error is returned.
   117  func (iter *AssignmentListResultIterator) NextWithContext(ctx context.Context) (err error) {
   118  	if tracing.IsEnabled() {
   119  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentListResultIterator.NextWithContext")
   120  		defer func() {
   121  			sc := -1
   122  			if iter.Response().Response.Response != nil {
   123  				sc = iter.Response().Response.Response.StatusCode
   124  			}
   125  			tracing.EndSpan(ctx, sc, err)
   126  		}()
   127  	}
   128  	iter.i++
   129  	if iter.i < len(iter.page.Values()) {
   130  		return nil
   131  	}
   132  	err = iter.page.NextWithContext(ctx)
   133  	if err != nil {
   134  		iter.i--
   135  		return err
   136  	}
   137  	iter.i = 0
   138  	return nil
   139  }
   140  
   141  // Next advances to the next value.  If there was an error making
   142  // the request the iterator does not advance and the error is returned.
   143  // Deprecated: Use NextWithContext() instead.
   144  func (iter *AssignmentListResultIterator) Next() error {
   145  	return iter.NextWithContext(context.Background())
   146  }
   147  
   148  // NotDone returns true if the enumeration should be started or is not yet complete.
   149  func (iter AssignmentListResultIterator) NotDone() bool {
   150  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   151  }
   152  
   153  // Response returns the raw server response from the last page request.
   154  func (iter AssignmentListResultIterator) Response() AssignmentListResult {
   155  	return iter.page.Response()
   156  }
   157  
   158  // Value returns the current value or a zero-initialized value if the
   159  // iterator has advanced beyond the end of the collection.
   160  func (iter AssignmentListResultIterator) Value() Assignment {
   161  	if !iter.page.NotDone() {
   162  		return Assignment{}
   163  	}
   164  	return iter.page.Values()[iter.i]
   165  }
   166  
   167  // Creates a new instance of the AssignmentListResultIterator type.
   168  func NewAssignmentListResultIterator(page AssignmentListResultPage) AssignmentListResultIterator {
   169  	return AssignmentListResultIterator{page: page}
   170  }
   171  
   172  // IsEmpty returns true if the ListResult contains no values.
   173  func (alr AssignmentListResult) IsEmpty() bool {
   174  	return alr.Value == nil || len(*alr.Value) == 0
   175  }
   176  
   177  // hasNextLink returns true if the NextLink is not empty.
   178  func (alr AssignmentListResult) hasNextLink() bool {
   179  	return alr.NextLink != nil && len(*alr.NextLink) != 0
   180  }
   181  
   182  // assignmentListResultPreparer prepares a request to retrieve the next set of results.
   183  // It returns nil if no more results exist.
   184  func (alr AssignmentListResult) assignmentListResultPreparer(ctx context.Context) (*http.Request, error) {
   185  	if !alr.hasNextLink() {
   186  		return nil, nil
   187  	}
   188  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   189  		autorest.AsJSON(),
   190  		autorest.AsGet(),
   191  		autorest.WithBaseURL(to.String(alr.NextLink)))
   192  }
   193  
   194  // AssignmentListResultPage contains a page of Assignment values.
   195  type AssignmentListResultPage struct {
   196  	fn  func(context.Context, AssignmentListResult) (AssignmentListResult, error)
   197  	alr AssignmentListResult
   198  }
   199  
   200  // NextWithContext advances to the next page of values.  If there was an error making
   201  // the request the page does not advance and the error is returned.
   202  func (page *AssignmentListResultPage) NextWithContext(ctx context.Context) (err error) {
   203  	if tracing.IsEnabled() {
   204  		ctx = tracing.StartSpan(ctx, fqdn+"/AssignmentListResultPage.NextWithContext")
   205  		defer func() {
   206  			sc := -1
   207  			if page.Response().Response.Response != nil {
   208  				sc = page.Response().Response.Response.StatusCode
   209  			}
   210  			tracing.EndSpan(ctx, sc, err)
   211  		}()
   212  	}
   213  	for {
   214  		next, err := page.fn(ctx, page.alr)
   215  		if err != nil {
   216  			return err
   217  		}
   218  		page.alr = next
   219  		if !next.hasNextLink() || !next.IsEmpty() {
   220  			break
   221  		}
   222  	}
   223  	return nil
   224  }
   225  
   226  // Next advances to the next page of values.  If there was an error making
   227  // the request the page does not advance and the error is returned.
   228  // Deprecated: Use NextWithContext() instead.
   229  func (page *AssignmentListResultPage) Next() error {
   230  	return page.NextWithContext(context.Background())
   231  }
   232  
   233  // NotDone returns true if the page enumeration should be started or is not yet complete.
   234  func (page AssignmentListResultPage) NotDone() bool {
   235  	return !page.alr.IsEmpty()
   236  }
   237  
   238  // Response returns the raw server response from the last page request.
   239  func (page AssignmentListResultPage) Response() AssignmentListResult {
   240  	return page.alr
   241  }
   242  
   243  // Values returns the slice of values for the current page or nil if there are no values.
   244  func (page AssignmentListResultPage) Values() []Assignment {
   245  	if page.alr.IsEmpty() {
   246  		return nil
   247  	}
   248  	return *page.alr.Value
   249  }
   250  
   251  // Creates a new instance of the AssignmentListResultPage type.
   252  func NewAssignmentListResultPage(cur AssignmentListResult, getNextPage func(context.Context, AssignmentListResult) (AssignmentListResult, error)) AssignmentListResultPage {
   253  	return AssignmentListResultPage{
   254  		fn:  getNextPage,
   255  		alr: cur,
   256  	}
   257  }
   258  
   259  // AssignmentProperties the policy assignment properties.
   260  type AssignmentProperties struct {
   261  	// DisplayName - The display name of the policy assignment.
   262  	DisplayName *string `json:"displayName,omitempty"`
   263  	// PolicyDefinitionID - The ID of the policy definition.
   264  	PolicyDefinitionID *string `json:"policyDefinitionId,omitempty"`
   265  	// Scope - The scope for the policy assignment.
   266  	Scope *string `json:"scope,omitempty"`
   267  	// Parameters - Required if a parameter is used in policy rule.
   268  	Parameters interface{} `json:"parameters,omitempty"`
   269  	// Description - This message will be part of response in case of policy violation.
   270  	Description *string `json:"description,omitempty"`
   271  }
   272  
   273  // Definition the policy definition.
   274  type Definition struct {
   275  	autorest.Response `json:"-"`
   276  	// DefinitionProperties - The policy definition properties.
   277  	*DefinitionProperties `json:"properties,omitempty"`
   278  	// ID - READ-ONLY; The ID of the policy definition.
   279  	ID *string `json:"id,omitempty"`
   280  	// Name - READ-ONLY; The name of the policy definition.
   281  	Name *string `json:"name,omitempty"`
   282  }
   283  
   284  // MarshalJSON is the custom marshaler for Definition.
   285  func (d Definition) MarshalJSON() ([]byte, error) {
   286  	objectMap := make(map[string]interface{})
   287  	if d.DefinitionProperties != nil {
   288  		objectMap["properties"] = d.DefinitionProperties
   289  	}
   290  	return json.Marshal(objectMap)
   291  }
   292  
   293  // UnmarshalJSON is the custom unmarshaler for Definition struct.
   294  func (d *Definition) UnmarshalJSON(body []byte) error {
   295  	var m map[string]*json.RawMessage
   296  	err := json.Unmarshal(body, &m)
   297  	if err != nil {
   298  		return err
   299  	}
   300  	for k, v := range m {
   301  		switch k {
   302  		case "properties":
   303  			if v != nil {
   304  				var definitionProperties DefinitionProperties
   305  				err = json.Unmarshal(*v, &definitionProperties)
   306  				if err != nil {
   307  					return err
   308  				}
   309  				d.DefinitionProperties = &definitionProperties
   310  			}
   311  		case "id":
   312  			if v != nil {
   313  				var ID string
   314  				err = json.Unmarshal(*v, &ID)
   315  				if err != nil {
   316  					return err
   317  				}
   318  				d.ID = &ID
   319  			}
   320  		case "name":
   321  			if v != nil {
   322  				var name string
   323  				err = json.Unmarshal(*v, &name)
   324  				if err != nil {
   325  					return err
   326  				}
   327  				d.Name = &name
   328  			}
   329  		}
   330  	}
   331  
   332  	return nil
   333  }
   334  
   335  // DefinitionListResult list of policy definitions.
   336  type DefinitionListResult struct {
   337  	autorest.Response `json:"-"`
   338  	// Value - An array of policy definitions.
   339  	Value *[]Definition `json:"value,omitempty"`
   340  	// NextLink - The URL to use for getting the next set of results.
   341  	NextLink *string `json:"nextLink,omitempty"`
   342  }
   343  
   344  // DefinitionListResultIterator provides access to a complete listing of Definition values.
   345  type DefinitionListResultIterator struct {
   346  	i    int
   347  	page DefinitionListResultPage
   348  }
   349  
   350  // NextWithContext advances to the next value.  If there was an error making
   351  // the request the iterator does not advance and the error is returned.
   352  func (iter *DefinitionListResultIterator) NextWithContext(ctx context.Context) (err error) {
   353  	if tracing.IsEnabled() {
   354  		ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionListResultIterator.NextWithContext")
   355  		defer func() {
   356  			sc := -1
   357  			if iter.Response().Response.Response != nil {
   358  				sc = iter.Response().Response.Response.StatusCode
   359  			}
   360  			tracing.EndSpan(ctx, sc, err)
   361  		}()
   362  	}
   363  	iter.i++
   364  	if iter.i < len(iter.page.Values()) {
   365  		return nil
   366  	}
   367  	err = iter.page.NextWithContext(ctx)
   368  	if err != nil {
   369  		iter.i--
   370  		return err
   371  	}
   372  	iter.i = 0
   373  	return nil
   374  }
   375  
   376  // Next advances to the next value.  If there was an error making
   377  // the request the iterator does not advance and the error is returned.
   378  // Deprecated: Use NextWithContext() instead.
   379  func (iter *DefinitionListResultIterator) Next() error {
   380  	return iter.NextWithContext(context.Background())
   381  }
   382  
   383  // NotDone returns true if the enumeration should be started or is not yet complete.
   384  func (iter DefinitionListResultIterator) NotDone() bool {
   385  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   386  }
   387  
   388  // Response returns the raw server response from the last page request.
   389  func (iter DefinitionListResultIterator) Response() DefinitionListResult {
   390  	return iter.page.Response()
   391  }
   392  
   393  // Value returns the current value or a zero-initialized value if the
   394  // iterator has advanced beyond the end of the collection.
   395  func (iter DefinitionListResultIterator) Value() Definition {
   396  	if !iter.page.NotDone() {
   397  		return Definition{}
   398  	}
   399  	return iter.page.Values()[iter.i]
   400  }
   401  
   402  // Creates a new instance of the DefinitionListResultIterator type.
   403  func NewDefinitionListResultIterator(page DefinitionListResultPage) DefinitionListResultIterator {
   404  	return DefinitionListResultIterator{page: page}
   405  }
   406  
   407  // IsEmpty returns true if the ListResult contains no values.
   408  func (dlr DefinitionListResult) IsEmpty() bool {
   409  	return dlr.Value == nil || len(*dlr.Value) == 0
   410  }
   411  
   412  // hasNextLink returns true if the NextLink is not empty.
   413  func (dlr DefinitionListResult) hasNextLink() bool {
   414  	return dlr.NextLink != nil && len(*dlr.NextLink) != 0
   415  }
   416  
   417  // definitionListResultPreparer prepares a request to retrieve the next set of results.
   418  // It returns nil if no more results exist.
   419  func (dlr DefinitionListResult) definitionListResultPreparer(ctx context.Context) (*http.Request, error) {
   420  	if !dlr.hasNextLink() {
   421  		return nil, nil
   422  	}
   423  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   424  		autorest.AsJSON(),
   425  		autorest.AsGet(),
   426  		autorest.WithBaseURL(to.String(dlr.NextLink)))
   427  }
   428  
   429  // DefinitionListResultPage contains a page of Definition values.
   430  type DefinitionListResultPage struct {
   431  	fn  func(context.Context, DefinitionListResult) (DefinitionListResult, error)
   432  	dlr DefinitionListResult
   433  }
   434  
   435  // NextWithContext advances to the next page of values.  If there was an error making
   436  // the request the page does not advance and the error is returned.
   437  func (page *DefinitionListResultPage) NextWithContext(ctx context.Context) (err error) {
   438  	if tracing.IsEnabled() {
   439  		ctx = tracing.StartSpan(ctx, fqdn+"/DefinitionListResultPage.NextWithContext")
   440  		defer func() {
   441  			sc := -1
   442  			if page.Response().Response.Response != nil {
   443  				sc = page.Response().Response.Response.StatusCode
   444  			}
   445  			tracing.EndSpan(ctx, sc, err)
   446  		}()
   447  	}
   448  	for {
   449  		next, err := page.fn(ctx, page.dlr)
   450  		if err != nil {
   451  			return err
   452  		}
   453  		page.dlr = next
   454  		if !next.hasNextLink() || !next.IsEmpty() {
   455  			break
   456  		}
   457  	}
   458  	return nil
   459  }
   460  
   461  // Next advances to the next page of values.  If there was an error making
   462  // the request the page does not advance and the error is returned.
   463  // Deprecated: Use NextWithContext() instead.
   464  func (page *DefinitionListResultPage) Next() error {
   465  	return page.NextWithContext(context.Background())
   466  }
   467  
   468  // NotDone returns true if the page enumeration should be started or is not yet complete.
   469  func (page DefinitionListResultPage) NotDone() bool {
   470  	return !page.dlr.IsEmpty()
   471  }
   472  
   473  // Response returns the raw server response from the last page request.
   474  func (page DefinitionListResultPage) Response() DefinitionListResult {
   475  	return page.dlr
   476  }
   477  
   478  // Values returns the slice of values for the current page or nil if there are no values.
   479  func (page DefinitionListResultPage) Values() []Definition {
   480  	if page.dlr.IsEmpty() {
   481  		return nil
   482  	}
   483  	return *page.dlr.Value
   484  }
   485  
   486  // Creates a new instance of the DefinitionListResultPage type.
   487  func NewDefinitionListResultPage(cur DefinitionListResult, getNextPage func(context.Context, DefinitionListResult) (DefinitionListResult, error)) DefinitionListResultPage {
   488  	return DefinitionListResultPage{
   489  		fn:  getNextPage,
   490  		dlr: cur,
   491  	}
   492  }
   493  
   494  // DefinitionProperties the policy definition properties.
   495  type DefinitionProperties struct {
   496  	// PolicyType - The type of policy definition. Possible values are NotSpecified, BuiltIn, and Custom. Possible values include: 'TypeNotSpecified', 'TypeBuiltIn', 'TypeCustom'
   497  	PolicyType Type `json:"policyType,omitempty"`
   498  	// Mode - The policy definition mode. Possible values are NotSpecified, Indexed, and All. Possible values include: 'NotSpecified', 'Indexed', 'All'
   499  	Mode Mode `json:"mode,omitempty"`
   500  	// DisplayName - The display name of the policy definition.
   501  	DisplayName *string `json:"displayName,omitempty"`
   502  	// Description - The policy definition description.
   503  	Description *string `json:"description,omitempty"`
   504  	// PolicyRule - The policy rule.
   505  	PolicyRule interface{} `json:"policyRule,omitempty"`
   506  	// Metadata - The policy definition metadata.
   507  	Metadata interface{} `json:"metadata,omitempty"`
   508  	// Parameters - Required if a parameter is used in policy rule.
   509  	Parameters interface{} `json:"parameters,omitempty"`
   510  }
   511  

View as plain text