...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2016-09-01/locks

     1  package locks
     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-09-01/locks"
    20  
    21  // ManagementLockListResult the list of locks.
    22  type ManagementLockListResult struct {
    23  	autorest.Response `json:"-"`
    24  	// Value - The list of locks.
    25  	Value *[]ManagementLockObject `json:"value,omitempty"`
    26  	// NextLink - The URL to use for getting the next set of results.
    27  	NextLink *string `json:"nextLink,omitempty"`
    28  }
    29  
    30  // ManagementLockListResultIterator provides access to a complete listing of ManagementLockObject values.
    31  type ManagementLockListResultIterator struct {
    32  	i    int
    33  	page ManagementLockListResultPage
    34  }
    35  
    36  // NextWithContext advances to the next value.  If there was an error making
    37  // the request the iterator does not advance and the error is returned.
    38  func (iter *ManagementLockListResultIterator) NextWithContext(ctx context.Context) (err error) {
    39  	if tracing.IsEnabled() {
    40  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementLockListResultIterator.NextWithContext")
    41  		defer func() {
    42  			sc := -1
    43  			if iter.Response().Response.Response != nil {
    44  				sc = iter.Response().Response.Response.StatusCode
    45  			}
    46  			tracing.EndSpan(ctx, sc, err)
    47  		}()
    48  	}
    49  	iter.i++
    50  	if iter.i < len(iter.page.Values()) {
    51  		return nil
    52  	}
    53  	err = iter.page.NextWithContext(ctx)
    54  	if err != nil {
    55  		iter.i--
    56  		return err
    57  	}
    58  	iter.i = 0
    59  	return nil
    60  }
    61  
    62  // Next advances to the next value.  If there was an error making
    63  // the request the iterator does not advance and the error is returned.
    64  // Deprecated: Use NextWithContext() instead.
    65  func (iter *ManagementLockListResultIterator) Next() error {
    66  	return iter.NextWithContext(context.Background())
    67  }
    68  
    69  // NotDone returns true if the enumeration should be started or is not yet complete.
    70  func (iter ManagementLockListResultIterator) NotDone() bool {
    71  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
    72  }
    73  
    74  // Response returns the raw server response from the last page request.
    75  func (iter ManagementLockListResultIterator) Response() ManagementLockListResult {
    76  	return iter.page.Response()
    77  }
    78  
    79  // Value returns the current value or a zero-initialized value if the
    80  // iterator has advanced beyond the end of the collection.
    81  func (iter ManagementLockListResultIterator) Value() ManagementLockObject {
    82  	if !iter.page.NotDone() {
    83  		return ManagementLockObject{}
    84  	}
    85  	return iter.page.Values()[iter.i]
    86  }
    87  
    88  // Creates a new instance of the ManagementLockListResultIterator type.
    89  func NewManagementLockListResultIterator(page ManagementLockListResultPage) ManagementLockListResultIterator {
    90  	return ManagementLockListResultIterator{page: page}
    91  }
    92  
    93  // IsEmpty returns true if the ListResult contains no values.
    94  func (mllr ManagementLockListResult) IsEmpty() bool {
    95  	return mllr.Value == nil || len(*mllr.Value) == 0
    96  }
    97  
    98  // hasNextLink returns true if the NextLink is not empty.
    99  func (mllr ManagementLockListResult) hasNextLink() bool {
   100  	return mllr.NextLink != nil && len(*mllr.NextLink) != 0
   101  }
   102  
   103  // managementLockListResultPreparer prepares a request to retrieve the next set of results.
   104  // It returns nil if no more results exist.
   105  func (mllr ManagementLockListResult) managementLockListResultPreparer(ctx context.Context) (*http.Request, error) {
   106  	if !mllr.hasNextLink() {
   107  		return nil, nil
   108  	}
   109  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   110  		autorest.AsJSON(),
   111  		autorest.AsGet(),
   112  		autorest.WithBaseURL(to.String(mllr.NextLink)))
   113  }
   114  
   115  // ManagementLockListResultPage contains a page of ManagementLockObject values.
   116  type ManagementLockListResultPage struct {
   117  	fn   func(context.Context, ManagementLockListResult) (ManagementLockListResult, error)
   118  	mllr ManagementLockListResult
   119  }
   120  
   121  // NextWithContext advances to the next page of values.  If there was an error making
   122  // the request the page does not advance and the error is returned.
   123  func (page *ManagementLockListResultPage) NextWithContext(ctx context.Context) (err error) {
   124  	if tracing.IsEnabled() {
   125  		ctx = tracing.StartSpan(ctx, fqdn+"/ManagementLockListResultPage.NextWithContext")
   126  		defer func() {
   127  			sc := -1
   128  			if page.Response().Response.Response != nil {
   129  				sc = page.Response().Response.Response.StatusCode
   130  			}
   131  			tracing.EndSpan(ctx, sc, err)
   132  		}()
   133  	}
   134  	for {
   135  		next, err := page.fn(ctx, page.mllr)
   136  		if err != nil {
   137  			return err
   138  		}
   139  		page.mllr = next
   140  		if !next.hasNextLink() || !next.IsEmpty() {
   141  			break
   142  		}
   143  	}
   144  	return nil
   145  }
   146  
   147  // Next advances to the next page of values.  If there was an error making
   148  // the request the page does not advance and the error is returned.
   149  // Deprecated: Use NextWithContext() instead.
   150  func (page *ManagementLockListResultPage) Next() error {
   151  	return page.NextWithContext(context.Background())
   152  }
   153  
   154  // NotDone returns true if the page enumeration should be started or is not yet complete.
   155  func (page ManagementLockListResultPage) NotDone() bool {
   156  	return !page.mllr.IsEmpty()
   157  }
   158  
   159  // Response returns the raw server response from the last page request.
   160  func (page ManagementLockListResultPage) Response() ManagementLockListResult {
   161  	return page.mllr
   162  }
   163  
   164  // Values returns the slice of values for the current page or nil if there are no values.
   165  func (page ManagementLockListResultPage) Values() []ManagementLockObject {
   166  	if page.mllr.IsEmpty() {
   167  		return nil
   168  	}
   169  	return *page.mllr.Value
   170  }
   171  
   172  // Creates a new instance of the ManagementLockListResultPage type.
   173  func NewManagementLockListResultPage(cur ManagementLockListResult, getNextPage func(context.Context, ManagementLockListResult) (ManagementLockListResult, error)) ManagementLockListResultPage {
   174  	return ManagementLockListResultPage{
   175  		fn:   getNextPage,
   176  		mllr: cur,
   177  	}
   178  }
   179  
   180  // ManagementLockObject the lock information.
   181  type ManagementLockObject struct {
   182  	autorest.Response `json:"-"`
   183  	// ManagementLockProperties - The properties of the lock.
   184  	*ManagementLockProperties `json:"properties,omitempty"`
   185  	// ID - READ-ONLY; The resource ID of the lock.
   186  	ID *string `json:"id,omitempty"`
   187  	// Type - READ-ONLY; The resource type of the lock - Microsoft.Authorization/locks.
   188  	Type *string `json:"type,omitempty"`
   189  	// Name - READ-ONLY; The name of the lock.
   190  	Name *string `json:"name,omitempty"`
   191  }
   192  
   193  // MarshalJSON is the custom marshaler for ManagementLockObject.
   194  func (mlo ManagementLockObject) MarshalJSON() ([]byte, error) {
   195  	objectMap := make(map[string]interface{})
   196  	if mlo.ManagementLockProperties != nil {
   197  		objectMap["properties"] = mlo.ManagementLockProperties
   198  	}
   199  	return json.Marshal(objectMap)
   200  }
   201  
   202  // UnmarshalJSON is the custom unmarshaler for ManagementLockObject struct.
   203  func (mlo *ManagementLockObject) UnmarshalJSON(body []byte) error {
   204  	var m map[string]*json.RawMessage
   205  	err := json.Unmarshal(body, &m)
   206  	if err != nil {
   207  		return err
   208  	}
   209  	for k, v := range m {
   210  		switch k {
   211  		case "properties":
   212  			if v != nil {
   213  				var managementLockProperties ManagementLockProperties
   214  				err = json.Unmarshal(*v, &managementLockProperties)
   215  				if err != nil {
   216  					return err
   217  				}
   218  				mlo.ManagementLockProperties = &managementLockProperties
   219  			}
   220  		case "id":
   221  			if v != nil {
   222  				var ID string
   223  				err = json.Unmarshal(*v, &ID)
   224  				if err != nil {
   225  					return err
   226  				}
   227  				mlo.ID = &ID
   228  			}
   229  		case "type":
   230  			if v != nil {
   231  				var typeVar string
   232  				err = json.Unmarshal(*v, &typeVar)
   233  				if err != nil {
   234  					return err
   235  				}
   236  				mlo.Type = &typeVar
   237  			}
   238  		case "name":
   239  			if v != nil {
   240  				var name string
   241  				err = json.Unmarshal(*v, &name)
   242  				if err != nil {
   243  					return err
   244  				}
   245  				mlo.Name = &name
   246  			}
   247  		}
   248  	}
   249  
   250  	return nil
   251  }
   252  
   253  // ManagementLockOwner lock owner properties.
   254  type ManagementLockOwner struct {
   255  	// ApplicationID - The application ID of the lock owner.
   256  	ApplicationID *string `json:"applicationId,omitempty"`
   257  }
   258  
   259  // ManagementLockProperties the lock properties.
   260  type ManagementLockProperties struct {
   261  	// Level - The level of the lock. Possible values are: NotSpecified, CanNotDelete, ReadOnly. CanNotDelete means authorized users are able to read and modify the resources, but not delete. ReadOnly means authorized users can only read from a resource, but they can't modify or delete it. Possible values include: 'NotSpecified', 'CanNotDelete', 'ReadOnly'
   262  	Level LockLevel `json:"level,omitempty"`
   263  	// Notes - Notes about the lock. Maximum of 512 characters.
   264  	Notes *string `json:"notes,omitempty"`
   265  	// Owners - The owners of the lock.
   266  	Owners *[]ManagementLockOwner `json:"owners,omitempty"`
   267  }
   268  
   269  // Operation microsoft.Authorization operation
   270  type Operation struct {
   271  	// Name - Operation name: {provider}/{resource}/{operation}
   272  	Name *string `json:"name,omitempty"`
   273  	// Display - The object that represents the operation.
   274  	Display *OperationDisplay `json:"display,omitempty"`
   275  }
   276  
   277  // OperationDisplay the object that represents the operation.
   278  type OperationDisplay struct {
   279  	// Provider - Service provider: Microsoft.Authorization
   280  	Provider *string `json:"provider,omitempty"`
   281  	// Resource - Resource on which the operation is performed: Profile, endpoint, etc.
   282  	Resource *string `json:"resource,omitempty"`
   283  	// Operation - Operation type: Read, write, delete, etc.
   284  	Operation *string `json:"operation,omitempty"`
   285  }
   286  
   287  // OperationListResult result of the request to list Microsoft.Authorization operations. It contains a list
   288  // of operations and a URL link to get the next set of results.
   289  type OperationListResult struct {
   290  	autorest.Response `json:"-"`
   291  	// Value - List of Microsoft.Authorization operations.
   292  	Value *[]Operation `json:"value,omitempty"`
   293  	// NextLink - URL to get the next set of operation list results if there are any.
   294  	NextLink *string `json:"nextLink,omitempty"`
   295  }
   296  
   297  // OperationListResultIterator provides access to a complete listing of Operation values.
   298  type OperationListResultIterator struct {
   299  	i    int
   300  	page OperationListResultPage
   301  }
   302  
   303  // NextWithContext advances to the next value.  If there was an error making
   304  // the request the iterator does not advance and the error is returned.
   305  func (iter *OperationListResultIterator) NextWithContext(ctx context.Context) (err error) {
   306  	if tracing.IsEnabled() {
   307  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultIterator.NextWithContext")
   308  		defer func() {
   309  			sc := -1
   310  			if iter.Response().Response.Response != nil {
   311  				sc = iter.Response().Response.Response.StatusCode
   312  			}
   313  			tracing.EndSpan(ctx, sc, err)
   314  		}()
   315  	}
   316  	iter.i++
   317  	if iter.i < len(iter.page.Values()) {
   318  		return nil
   319  	}
   320  	err = iter.page.NextWithContext(ctx)
   321  	if err != nil {
   322  		iter.i--
   323  		return err
   324  	}
   325  	iter.i = 0
   326  	return nil
   327  }
   328  
   329  // Next advances to the next value.  If there was an error making
   330  // the request the iterator does not advance and the error is returned.
   331  // Deprecated: Use NextWithContext() instead.
   332  func (iter *OperationListResultIterator) Next() error {
   333  	return iter.NextWithContext(context.Background())
   334  }
   335  
   336  // NotDone returns true if the enumeration should be started or is not yet complete.
   337  func (iter OperationListResultIterator) NotDone() bool {
   338  	return iter.page.NotDone() && iter.i < len(iter.page.Values())
   339  }
   340  
   341  // Response returns the raw server response from the last page request.
   342  func (iter OperationListResultIterator) Response() OperationListResult {
   343  	return iter.page.Response()
   344  }
   345  
   346  // Value returns the current value or a zero-initialized value if the
   347  // iterator has advanced beyond the end of the collection.
   348  func (iter OperationListResultIterator) Value() Operation {
   349  	if !iter.page.NotDone() {
   350  		return Operation{}
   351  	}
   352  	return iter.page.Values()[iter.i]
   353  }
   354  
   355  // Creates a new instance of the OperationListResultIterator type.
   356  func NewOperationListResultIterator(page OperationListResultPage) OperationListResultIterator {
   357  	return OperationListResultIterator{page: page}
   358  }
   359  
   360  // IsEmpty returns true if the ListResult contains no values.
   361  func (olr OperationListResult) IsEmpty() bool {
   362  	return olr.Value == nil || len(*olr.Value) == 0
   363  }
   364  
   365  // hasNextLink returns true if the NextLink is not empty.
   366  func (olr OperationListResult) hasNextLink() bool {
   367  	return olr.NextLink != nil && len(*olr.NextLink) != 0
   368  }
   369  
   370  // operationListResultPreparer prepares a request to retrieve the next set of results.
   371  // It returns nil if no more results exist.
   372  func (olr OperationListResult) operationListResultPreparer(ctx context.Context) (*http.Request, error) {
   373  	if !olr.hasNextLink() {
   374  		return nil, nil
   375  	}
   376  	return autorest.Prepare((&http.Request{}).WithContext(ctx),
   377  		autorest.AsJSON(),
   378  		autorest.AsGet(),
   379  		autorest.WithBaseURL(to.String(olr.NextLink)))
   380  }
   381  
   382  // OperationListResultPage contains a page of Operation values.
   383  type OperationListResultPage struct {
   384  	fn  func(context.Context, OperationListResult) (OperationListResult, error)
   385  	olr OperationListResult
   386  }
   387  
   388  // NextWithContext advances to the next page of values.  If there was an error making
   389  // the request the page does not advance and the error is returned.
   390  func (page *OperationListResultPage) NextWithContext(ctx context.Context) (err error) {
   391  	if tracing.IsEnabled() {
   392  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationListResultPage.NextWithContext")
   393  		defer func() {
   394  			sc := -1
   395  			if page.Response().Response.Response != nil {
   396  				sc = page.Response().Response.Response.StatusCode
   397  			}
   398  			tracing.EndSpan(ctx, sc, err)
   399  		}()
   400  	}
   401  	for {
   402  		next, err := page.fn(ctx, page.olr)
   403  		if err != nil {
   404  			return err
   405  		}
   406  		page.olr = next
   407  		if !next.hasNextLink() || !next.IsEmpty() {
   408  			break
   409  		}
   410  	}
   411  	return nil
   412  }
   413  
   414  // Next advances to the next page of values.  If there was an error making
   415  // the request the page does not advance and the error is returned.
   416  // Deprecated: Use NextWithContext() instead.
   417  func (page *OperationListResultPage) Next() error {
   418  	return page.NextWithContext(context.Background())
   419  }
   420  
   421  // NotDone returns true if the page enumeration should be started or is not yet complete.
   422  func (page OperationListResultPage) NotDone() bool {
   423  	return !page.olr.IsEmpty()
   424  }
   425  
   426  // Response returns the raw server response from the last page request.
   427  func (page OperationListResultPage) Response() OperationListResult {
   428  	return page.olr
   429  }
   430  
   431  // Values returns the slice of values for the current page or nil if there are no values.
   432  func (page OperationListResultPage) Values() []Operation {
   433  	if page.olr.IsEmpty() {
   434  		return nil
   435  	}
   436  	return *page.olr.Value
   437  }
   438  
   439  // Creates a new instance of the OperationListResultPage type.
   440  func NewOperationListResultPage(cur OperationListResult, getNextPage func(context.Context, OperationListResult) (OperationListResult, error)) OperationListResultPage {
   441  	return OperationListResultPage{
   442  		fn:  getNextPage,
   443  		olr: cur,
   444  	}
   445  }
   446  

View as plain text