1package storage
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
9import (
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// UsagesClient is the the Azure Storage Management API.
19type UsagesClient struct {
20	BaseClient
21}
22
23// NewUsagesClient creates an instance of the UsagesClient client.
24func NewUsagesClient(subscriptionID string) UsagesClient {
25	return NewUsagesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewUsagesClientWithBaseURI creates an instance of the UsagesClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewUsagesClientWithBaseURI(baseURI string, subscriptionID string) UsagesClient {
31	return UsagesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// ListByLocation gets the current usage count and the limit for the resources of the location under the subscription.
35// Parameters:
36// location - the location of the Azure Storage resource.
37func (client UsagesClient) ListByLocation(ctx context.Context, location string) (result UsageListResult, err error) {
38	if tracing.IsEnabled() {
39		ctx = tracing.StartSpan(ctx, fqdn+"/UsagesClient.ListByLocation")
40		defer func() {
41			sc := -1
42			if result.Response.Response != nil {
43				sc = result.Response.Response.StatusCode
44			}
45			tracing.EndSpan(ctx, sc, err)
46		}()
47	}
48	if err := validation.Validate([]validation.Validation{
49		{TargetValue: client.SubscriptionID,
50			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
51		return result, validation.NewError("storage.UsagesClient", "ListByLocation", err.Error())
52	}
53
54	req, err := client.ListByLocationPreparer(ctx, location)
55	if err != nil {
56		err = autorest.NewErrorWithError(err, "storage.UsagesClient", "ListByLocation", nil, "Failure preparing request")
57		return
58	}
59
60	resp, err := client.ListByLocationSender(req)
61	if err != nil {
62		result.Response = autorest.Response{Response: resp}
63		err = autorest.NewErrorWithError(err, "storage.UsagesClient", "ListByLocation", resp, "Failure sending request")
64		return
65	}
66
67	result, err = client.ListByLocationResponder(resp)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "storage.UsagesClient", "ListByLocation", resp, "Failure responding to request")
70		return
71	}
72
73	return
74}
75
76// ListByLocationPreparer prepares the ListByLocation request.
77func (client UsagesClient) ListByLocationPreparer(ctx context.Context, location string) (*http.Request, error) {
78	pathParameters := map[string]interface{}{
79		"location":       autorest.Encode("path", location),
80		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
81	}
82
83	const APIVersion = "2018-11-01"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87
88	preparer := autorest.CreatePreparer(
89		autorest.AsGet(),
90		autorest.WithBaseURL(client.BaseURI),
91		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Storage/locations/{location}/usages", pathParameters),
92		autorest.WithQueryParameters(queryParameters))
93	return preparer.Prepare((&http.Request{}).WithContext(ctx))
94}
95
96// ListByLocationSender sends the ListByLocation request. The method will close the
97// http.Response Body if it receives an error.
98func (client UsagesClient) ListByLocationSender(req *http.Request) (*http.Response, error) {
99	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
100}
101
102// ListByLocationResponder handles the response to the ListByLocation request. The method always
103// closes the http.Response Body.
104func (client UsagesClient) ListByLocationResponder(resp *http.Response) (result UsageListResult, err error) {
105	err = autorest.Respond(
106		resp,
107		azure.WithErrorUnlessStatusCode(http.StatusOK),
108		autorest.ByUnmarshallingJSON(&result),
109		autorest.ByClosing())
110	result.Response = autorest.Response{Response: resp}
111	return
112}
113