...

Source file src/github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2015-11-01/subscriptions/subscriptions.go

Documentation: github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2015-11-01/subscriptions

     1  package subscriptions
     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  // Client is the client for the Subscriptions methods of the Subscriptions service.
    18  type Client struct {
    19  	BaseClient
    20  }
    21  
    22  // NewClient creates an instance of the Client client.
    23  func NewClient() Client {
    24  	return NewClientWithBaseURI(DefaultBaseURI)
    25  }
    26  
    27  // NewClientWithBaseURI creates an instance of the Client client using a custom endpoint.  Use this when interacting
    28  // with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewClientWithBaseURI(baseURI string) Client {
    30  	return Client{NewWithBaseURI(baseURI)}
    31  }
    32  
    33  // Get gets details about particular subscription.
    34  // Parameters:
    35  // subscriptionID - id of the subscription.
    36  func (client Client) Get(ctx context.Context, subscriptionID string) (result Subscription, err error) {
    37  	if tracing.IsEnabled() {
    38  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.Get")
    39  		defer func() {
    40  			sc := -1
    41  			if result.Response.Response != nil {
    42  				sc = result.Response.Response.StatusCode
    43  			}
    44  			tracing.EndSpan(ctx, sc, err)
    45  		}()
    46  	}
    47  	req, err := client.GetPreparer(ctx, subscriptionID)
    48  	if err != nil {
    49  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "Get", nil, "Failure preparing request")
    50  		return
    51  	}
    52  
    53  	resp, err := client.GetSender(req)
    54  	if err != nil {
    55  		result.Response = autorest.Response{Response: resp}
    56  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "Get", resp, "Failure sending request")
    57  		return
    58  	}
    59  
    60  	result, err = client.GetResponder(resp)
    61  	if err != nil {
    62  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "Get", resp, "Failure responding to request")
    63  		return
    64  	}
    65  
    66  	return
    67  }
    68  
    69  // GetPreparer prepares the Get request.
    70  func (client Client) GetPreparer(ctx context.Context, subscriptionID string) (*http.Request, error) {
    71  	pathParameters := map[string]interface{}{
    72  		"subscriptionId": autorest.Encode("path", subscriptionID),
    73  	}
    74  
    75  	const APIVersion = "2015-11-01"
    76  	queryParameters := map[string]interface{}{
    77  		"api-version": APIVersion,
    78  	}
    79  
    80  	preparer := autorest.CreatePreparer(
    81  		autorest.AsGet(),
    82  		autorest.WithBaseURL(client.BaseURI),
    83  		autorest.WithPathParameters("/subscriptions/{subscriptionId}", pathParameters),
    84  		autorest.WithQueryParameters(queryParameters))
    85  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    86  }
    87  
    88  // GetSender sends the Get request. The method will close the
    89  // http.Response Body if it receives an error.
    90  func (client Client) GetSender(req *http.Request) (*http.Response, error) {
    91  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
    92  }
    93  
    94  // GetResponder handles the response to the Get request. The method always
    95  // closes the http.Response Body.
    96  func (client Client) GetResponder(resp *http.Response) (result Subscription, err error) {
    97  	err = autorest.Respond(
    98  		resp,
    99  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   100  		autorest.ByUnmarshallingJSON(&result),
   101  		autorest.ByClosing())
   102  	result.Response = autorest.Response{Response: resp}
   103  	return
   104  }
   105  
   106  // List gets a list of the subscriptionIds.
   107  func (client Client) List(ctx context.Context) (result ListResultPage, err error) {
   108  	if tracing.IsEnabled() {
   109  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
   110  		defer func() {
   111  			sc := -1
   112  			if result.lr.Response.Response != nil {
   113  				sc = result.lr.Response.Response.StatusCode
   114  			}
   115  			tracing.EndSpan(ctx, sc, err)
   116  		}()
   117  	}
   118  	result.fn = client.listNextResults
   119  	req, err := client.ListPreparer(ctx)
   120  	if err != nil {
   121  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "List", nil, "Failure preparing request")
   122  		return
   123  	}
   124  
   125  	resp, err := client.ListSender(req)
   126  	if err != nil {
   127  		result.lr.Response = autorest.Response{Response: resp}
   128  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "List", resp, "Failure sending request")
   129  		return
   130  	}
   131  
   132  	result.lr, err = client.ListResponder(resp)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "List", resp, "Failure responding to request")
   135  		return
   136  	}
   137  	if result.lr.hasNextLink() && result.lr.IsEmpty() {
   138  		err = result.NextWithContext(ctx)
   139  		return
   140  	}
   141  
   142  	return
   143  }
   144  
   145  // ListPreparer prepares the List request.
   146  func (client Client) ListPreparer(ctx context.Context) (*http.Request, error) {
   147  	const APIVersion = "2015-11-01"
   148  	queryParameters := map[string]interface{}{
   149  		"api-version": APIVersion,
   150  	}
   151  
   152  	preparer := autorest.CreatePreparer(
   153  		autorest.AsGet(),
   154  		autorest.WithBaseURL(client.BaseURI),
   155  		autorest.WithPath("/subscriptions"),
   156  		autorest.WithQueryParameters(queryParameters))
   157  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   158  }
   159  
   160  // ListSender sends the List request. The method will close the
   161  // http.Response Body if it receives an error.
   162  func (client Client) ListSender(req *http.Request) (*http.Response, error) {
   163  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   164  }
   165  
   166  // ListResponder handles the response to the List request. The method always
   167  // closes the http.Response Body.
   168  func (client Client) ListResponder(resp *http.Response) (result ListResult, err error) {
   169  	err = autorest.Respond(
   170  		resp,
   171  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   172  		autorest.ByUnmarshallingJSON(&result),
   173  		autorest.ByClosing())
   174  	result.Response = autorest.Response{Response: resp}
   175  	return
   176  }
   177  
   178  // listNextResults retrieves the next set of results, if any.
   179  func (client Client) listNextResults(ctx context.Context, lastResults ListResult) (result ListResult, err error) {
   180  	req, err := lastResults.listResultPreparer(ctx)
   181  	if err != nil {
   182  		return result, autorest.NewErrorWithError(err, "subscriptions.Client", "listNextResults", nil, "Failure preparing next results request")
   183  	}
   184  	if req == nil {
   185  		return
   186  	}
   187  	resp, err := client.ListSender(req)
   188  	if err != nil {
   189  		result.Response = autorest.Response{Response: resp}
   190  		return result, autorest.NewErrorWithError(err, "subscriptions.Client", "listNextResults", resp, "Failure sending next results request")
   191  	}
   192  	result, err = client.ListResponder(resp)
   193  	if err != nil {
   194  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "listNextResults", resp, "Failure responding to next results request")
   195  	}
   196  	return
   197  }
   198  
   199  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   200  func (client Client) ListComplete(ctx context.Context) (result ListResultIterator, err error) {
   201  	if tracing.IsEnabled() {
   202  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.List")
   203  		defer func() {
   204  			sc := -1
   205  			if result.Response().Response.Response != nil {
   206  				sc = result.page.Response().Response.Response.StatusCode
   207  			}
   208  			tracing.EndSpan(ctx, sc, err)
   209  		}()
   210  	}
   211  	result.page, err = client.List(ctx)
   212  	return
   213  }
   214  
   215  // ListLocations gets a list of the subscription locations.
   216  // Parameters:
   217  // subscriptionID - id of the subscription
   218  func (client Client) ListLocations(ctx context.Context, subscriptionID string) (result LocationListResult, err error) {
   219  	if tracing.IsEnabled() {
   220  		ctx = tracing.StartSpan(ctx, fqdn+"/Client.ListLocations")
   221  		defer func() {
   222  			sc := -1
   223  			if result.Response.Response != nil {
   224  				sc = result.Response.Response.StatusCode
   225  			}
   226  			tracing.EndSpan(ctx, sc, err)
   227  		}()
   228  	}
   229  	req, err := client.ListLocationsPreparer(ctx, subscriptionID)
   230  	if err != nil {
   231  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "ListLocations", nil, "Failure preparing request")
   232  		return
   233  	}
   234  
   235  	resp, err := client.ListLocationsSender(req)
   236  	if err != nil {
   237  		result.Response = autorest.Response{Response: resp}
   238  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "ListLocations", resp, "Failure sending request")
   239  		return
   240  	}
   241  
   242  	result, err = client.ListLocationsResponder(resp)
   243  	if err != nil {
   244  		err = autorest.NewErrorWithError(err, "subscriptions.Client", "ListLocations", resp, "Failure responding to request")
   245  		return
   246  	}
   247  
   248  	return
   249  }
   250  
   251  // ListLocationsPreparer prepares the ListLocations request.
   252  func (client Client) ListLocationsPreparer(ctx context.Context, subscriptionID string) (*http.Request, error) {
   253  	pathParameters := map[string]interface{}{
   254  		"subscriptionId": autorest.Encode("path", subscriptionID),
   255  	}
   256  
   257  	const APIVersion = "2015-11-01"
   258  	queryParameters := map[string]interface{}{
   259  		"api-version": APIVersion,
   260  	}
   261  
   262  	preparer := autorest.CreatePreparer(
   263  		autorest.AsGet(),
   264  		autorest.WithBaseURL(client.BaseURI),
   265  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/locations", pathParameters),
   266  		autorest.WithQueryParameters(queryParameters))
   267  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   268  }
   269  
   270  // ListLocationsSender sends the ListLocations request. The method will close the
   271  // http.Response Body if it receives an error.
   272  func (client Client) ListLocationsSender(req *http.Request) (*http.Response, error) {
   273  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   274  }
   275  
   276  // ListLocationsResponder handles the response to the ListLocations request. The method always
   277  // closes the http.Response Body.
   278  func (client Client) ListLocationsResponder(resp *http.Response) (result LocationListResult, err error) {
   279  	err = autorest.Respond(
   280  		resp,
   281  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   282  		autorest.ByUnmarshallingJSON(&result),
   283  		autorest.ByClosing())
   284  	result.Response = autorest.Response{Response: resp}
   285  	return
   286  }
   287  

View as plain text