...

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

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

View as plain text