...

Source file src/github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2019-10-01/consumption/marketplaces.go

Documentation: github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2019-10-01/consumption

     1  package consumption
     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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // MarketplacesClient is the consumption management client provides access to consumption resources for Azure
    19  // Enterprise Subscriptions.
    20  type MarketplacesClient struct {
    21  	BaseClient
    22  }
    23  
    24  // NewMarketplacesClient creates an instance of the MarketplacesClient client.
    25  func NewMarketplacesClient(subscriptionID string) MarketplacesClient {
    26  	return NewMarketplacesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    27  }
    28  
    29  // NewMarketplacesClientWithBaseURI creates an instance of the MarketplacesClient client using a custom endpoint.  Use
    30  // this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewMarketplacesClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesClient {
    32  	return MarketplacesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // List lists the marketplaces for a scope at the defined scope. Marketplaces are available via this API only for May
    36  // 1, 2014 or later.
    37  // Parameters:
    38  // scope - the scope associated with marketplace operations. This includes '/subscriptions/{subscriptionId}/'
    39  // for subscription scope, '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing
    40  // Account scope, '/providers/Microsoft.Billing/departments/{departmentId}' for Department scope,
    41  // '/providers/Microsoft.Billing/enrollmentAccounts/{enrollmentAccountId}' for EnrollmentAccount scope and
    42  // '/providers/Microsoft.Management/managementGroups/{managementGroupId}' for Management Group scope. For
    43  // subscription, billing account, department, enrollment account and ManagementGroup, you can also add billing
    44  // period to the scope using '/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}'. For e.g. to
    45  // specify billing period at department scope use
    46  // '/providers/Microsoft.Billing/departments/{departmentId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}'
    47  // filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc
    48  // time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq',
    49  // 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'.
    50  // top - may be used to limit the number of results to the most recent N marketplaces.
    51  // skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response
    52  // contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that
    53  // specifies a starting point to use for subsequent calls.
    54  func (client MarketplacesClient) List(ctx context.Context, scope string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) {
    55  	if tracing.IsEnabled() {
    56  		ctx = tracing.StartSpan(ctx, fqdn+"/MarketplacesClient.List")
    57  		defer func() {
    58  			sc := -1
    59  			if result.mlr.Response.Response != nil {
    60  				sc = result.mlr.Response.Response.StatusCode
    61  			}
    62  			tracing.EndSpan(ctx, sc, err)
    63  		}()
    64  	}
    65  	if err := validation.Validate([]validation.Validation{
    66  		{TargetValue: top,
    67  			Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false,
    68  				Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
    69  					{Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
    70  				}}}}}); err != nil {
    71  		return result, validation.NewError("consumption.MarketplacesClient", "List", err.Error())
    72  	}
    73  
    74  	result.fn = client.listNextResults
    75  	req, err := client.ListPreparer(ctx, scope, filter, top, skiptoken)
    76  	if err != nil {
    77  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesClient", "List", nil, "Failure preparing request")
    78  		return
    79  	}
    80  
    81  	resp, err := client.ListSender(req)
    82  	if err != nil {
    83  		result.mlr.Response = autorest.Response{Response: resp}
    84  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesClient", "List", resp, "Failure sending request")
    85  		return
    86  	}
    87  
    88  	result.mlr, err = client.ListResponder(resp)
    89  	if err != nil {
    90  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesClient", "List", resp, "Failure responding to request")
    91  		return
    92  	}
    93  	if result.mlr.hasNextLink() && result.mlr.IsEmpty() {
    94  		err = result.NextWithContext(ctx)
    95  		return
    96  	}
    97  
    98  	return
    99  }
   100  
   101  // ListPreparer prepares the List request.
   102  func (client MarketplacesClient) ListPreparer(ctx context.Context, scope string, filter string, top *int32, skiptoken string) (*http.Request, error) {
   103  	pathParameters := map[string]interface{}{
   104  		"scope": scope,
   105  	}
   106  
   107  	const APIVersion = "2019-10-01"
   108  	queryParameters := map[string]interface{}{
   109  		"api-version": APIVersion,
   110  	}
   111  	if len(filter) > 0 {
   112  		queryParameters["$filter"] = autorest.Encode("query", filter)
   113  	}
   114  	if top != nil {
   115  		queryParameters["$top"] = autorest.Encode("query", *top)
   116  	}
   117  	if len(skiptoken) > 0 {
   118  		queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken)
   119  	}
   120  
   121  	preparer := autorest.CreatePreparer(
   122  		autorest.AsGet(),
   123  		autorest.WithBaseURL(client.BaseURI),
   124  		autorest.WithPathParameters("/{scope}/providers/Microsoft.Consumption/marketplaces", pathParameters),
   125  		autorest.WithQueryParameters(queryParameters))
   126  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   127  }
   128  
   129  // ListSender sends the List request. The method will close the
   130  // http.Response Body if it receives an error.
   131  func (client MarketplacesClient) ListSender(req *http.Request) (*http.Response, error) {
   132  	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
   133  }
   134  
   135  // ListResponder handles the response to the List request. The method always
   136  // closes the http.Response Body.
   137  func (client MarketplacesClient) ListResponder(resp *http.Response) (result MarketplacesListResult, err error) {
   138  	err = autorest.Respond(
   139  		resp,
   140  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   141  		autorest.ByUnmarshallingJSON(&result),
   142  		autorest.ByClosing())
   143  	result.Response = autorest.Response{Response: resp}
   144  	return
   145  }
   146  
   147  // listNextResults retrieves the next set of results, if any.
   148  func (client MarketplacesClient) listNextResults(ctx context.Context, lastResults MarketplacesListResult) (result MarketplacesListResult, err error) {
   149  	req, err := lastResults.marketplacesListResultPreparer(ctx)
   150  	if err != nil {
   151  		return result, autorest.NewErrorWithError(err, "consumption.MarketplacesClient", "listNextResults", nil, "Failure preparing next results request")
   152  	}
   153  	if req == nil {
   154  		return
   155  	}
   156  	resp, err := client.ListSender(req)
   157  	if err != nil {
   158  		result.Response = autorest.Response{Response: resp}
   159  		return result, autorest.NewErrorWithError(err, "consumption.MarketplacesClient", "listNextResults", resp, "Failure sending next results request")
   160  	}
   161  	result, err = client.ListResponder(resp)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "consumption.MarketplacesClient", "listNextResults", resp, "Failure responding to next results request")
   164  	}
   165  	return
   166  }
   167  
   168  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   169  func (client MarketplacesClient) ListComplete(ctx context.Context, scope string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) {
   170  	if tracing.IsEnabled() {
   171  		ctx = tracing.StartSpan(ctx, fqdn+"/MarketplacesClient.List")
   172  		defer func() {
   173  			sc := -1
   174  			if result.Response().Response.Response != nil {
   175  				sc = result.page.Response().Response.Response.StatusCode
   176  			}
   177  			tracing.EndSpan(ctx, sc, err)
   178  		}()
   179  	}
   180  	result.page, err = client.List(ctx, scope, filter, top, skiptoken)
   181  	return
   182  }
   183  

View as plain text