...

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

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

View as plain text