...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-05-01/locks/authorizationoperations.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-05-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  	"github.com/Azure/go-autorest/autorest"
    12  	"github.com/Azure/go-autorest/autorest/azure"
    13  	"github.com/Azure/go-autorest/tracing"
    14  	"net/http"
    15  )
    16  
    17  // AuthorizationOperationsClient is the azure resources can be locked to prevent other users in your organization from
    18  // deleting or modifying resources.
    19  type AuthorizationOperationsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewAuthorizationOperationsClient creates an instance of the AuthorizationOperationsClient client.
    24  func NewAuthorizationOperationsClient(subscriptionID string) AuthorizationOperationsClient {
    25  	return NewAuthorizationOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewAuthorizationOperationsClientWithBaseURI creates an instance of the AuthorizationOperationsClient client using a
    29  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    30  // Azure stack).
    31  func NewAuthorizationOperationsClientWithBaseURI(baseURI string, subscriptionID string) AuthorizationOperationsClient {
    32  	return AuthorizationOperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // List lists all of the available Microsoft.Authorization REST API operations.
    36  func (client AuthorizationOperationsClient) List(ctx context.Context) (result OperationListResultPage, err error) {
    37  	if tracing.IsEnabled() {
    38  		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationOperationsClient.List")
    39  		defer func() {
    40  			sc := -1
    41  			if result.olr.Response.Response != nil {
    42  				sc = result.olr.Response.Response.StatusCode
    43  			}
    44  			tracing.EndSpan(ctx, sc, err)
    45  		}()
    46  	}
    47  	result.fn = client.listNextResults
    48  	req, err := client.ListPreparer(ctx)
    49  	if err != nil {
    50  		err = autorest.NewErrorWithError(err, "locks.AuthorizationOperationsClient", "List", nil, "Failure preparing request")
    51  		return
    52  	}
    53  
    54  	resp, err := client.ListSender(req)
    55  	if err != nil {
    56  		result.olr.Response = autorest.Response{Response: resp}
    57  		err = autorest.NewErrorWithError(err, "locks.AuthorizationOperationsClient", "List", resp, "Failure sending request")
    58  		return
    59  	}
    60  
    61  	result.olr, err = client.ListResponder(resp)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "locks.AuthorizationOperationsClient", "List", resp, "Failure responding to request")
    64  		return
    65  	}
    66  	if result.olr.hasNextLink() && result.olr.IsEmpty() {
    67  		err = result.NextWithContext(ctx)
    68  		return
    69  	}
    70  
    71  	return
    72  }
    73  
    74  // ListPreparer prepares the List request.
    75  func (client AuthorizationOperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
    76  	const APIVersion = "2020-05-01"
    77  	queryParameters := map[string]interface{}{
    78  		"api-version": APIVersion,
    79  	}
    80  
    81  	preparer := autorest.CreatePreparer(
    82  		autorest.AsGet(),
    83  		autorest.WithBaseURL(client.BaseURI),
    84  		autorest.WithPath("/providers/Microsoft.Authorization/operations"),
    85  		autorest.WithQueryParameters(queryParameters))
    86  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    87  }
    88  
    89  // ListSender sends the List request. The method will close the
    90  // http.Response Body if it receives an error.
    91  func (client AuthorizationOperationsClient) ListSender(req *http.Request) (*http.Response, error) {
    92  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
    93  }
    94  
    95  // ListResponder handles the response to the List request. The method always
    96  // closes the http.Response Body.
    97  func (client AuthorizationOperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) {
    98  	err = autorest.Respond(
    99  		resp,
   100  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   101  		autorest.ByUnmarshallingJSON(&result),
   102  		autorest.ByClosing())
   103  	result.Response = autorest.Response{Response: resp}
   104  	return
   105  }
   106  
   107  // listNextResults retrieves the next set of results, if any.
   108  func (client AuthorizationOperationsClient) listNextResults(ctx context.Context, lastResults OperationListResult) (result OperationListResult, err error) {
   109  	req, err := lastResults.operationListResultPreparer(ctx)
   110  	if err != nil {
   111  		return result, autorest.NewErrorWithError(err, "locks.AuthorizationOperationsClient", "listNextResults", nil, "Failure preparing next results request")
   112  	}
   113  	if req == nil {
   114  		return
   115  	}
   116  	resp, err := client.ListSender(req)
   117  	if err != nil {
   118  		result.Response = autorest.Response{Response: resp}
   119  		return result, autorest.NewErrorWithError(err, "locks.AuthorizationOperationsClient", "listNextResults", resp, "Failure sending next results request")
   120  	}
   121  	result, err = client.ListResponder(resp)
   122  	if err != nil {
   123  		err = autorest.NewErrorWithError(err, "locks.AuthorizationOperationsClient", "listNextResults", resp, "Failure responding to next results request")
   124  	}
   125  	return
   126  }
   127  
   128  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   129  func (client AuthorizationOperationsClient) ListComplete(ctx context.Context) (result OperationListResultIterator, err error) {
   130  	if tracing.IsEnabled() {
   131  		ctx = tracing.StartSpan(ctx, fqdn+"/AuthorizationOperationsClient.List")
   132  		defer func() {
   133  			sc := -1
   134  			if result.Response().Response.Response != nil {
   135  				sc = result.page.Response().Response.Response.StatusCode
   136  			}
   137  			tracing.EndSpan(ctx, sc, err)
   138  		}()
   139  	}
   140  	result.page, err = client.List(ctx)
   141  	return
   142  }
   143  

View as plain text