1package consumption 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// BalancesClient is the consumption management client provides access to consumption resources for Azure Enterprise 29// Subscriptions. 30type BalancesClient struct { 31 BaseClient 32} 33 34// NewBalancesClient creates an instance of the BalancesClient client. 35func NewBalancesClient(subscriptionID string) BalancesClient { 36 return NewBalancesClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewBalancesClientWithBaseURI creates an instance of the BalancesClient client using a custom endpoint. Use this 40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewBalancesClientWithBaseURI(baseURI string, subscriptionID string) BalancesClient { 42 return BalancesClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// GetByBillingAccount gets the balances for a scope by billingAccountId. Balances are available via this API only for 46// May 1, 2014 or later. 47// Parameters: 48// billingAccountID - billingAccount ID 49func (client BalancesClient) GetByBillingAccount(ctx context.Context, billingAccountID string) (result Balance, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/BalancesClient.GetByBillingAccount") 52 defer func() { 53 sc := -1 54 if result.Response.Response != nil { 55 sc = result.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 req, err := client.GetByBillingAccountPreparer(ctx, billingAccountID) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "consumption.BalancesClient", "GetByBillingAccount", nil, "Failure preparing request") 63 return 64 } 65 66 resp, err := client.GetByBillingAccountSender(req) 67 if err != nil { 68 result.Response = autorest.Response{Response: resp} 69 err = autorest.NewErrorWithError(err, "consumption.BalancesClient", "GetByBillingAccount", resp, "Failure sending request") 70 return 71 } 72 73 result, err = client.GetByBillingAccountResponder(resp) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "consumption.BalancesClient", "GetByBillingAccount", resp, "Failure responding to request") 76 return 77 } 78 79 return 80} 81 82// GetByBillingAccountPreparer prepares the GetByBillingAccount request. 83func (client BalancesClient) GetByBillingAccountPreparer(ctx context.Context, billingAccountID string) (*http.Request, error) { 84 pathParameters := map[string]interface{}{ 85 "billingAccountId": autorest.Encode("path", billingAccountID), 86 } 87 88 const APIVersion = "2018-10-01" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 93 preparer := autorest.CreatePreparer( 94 autorest.AsGet(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/balances", pathParameters), 97 autorest.WithQueryParameters(queryParameters)) 98 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 99} 100 101// GetByBillingAccountSender sends the GetByBillingAccount request. The method will close the 102// http.Response Body if it receives an error. 103func (client BalancesClient) GetByBillingAccountSender(req *http.Request) (*http.Response, error) { 104 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 105} 106 107// GetByBillingAccountResponder handles the response to the GetByBillingAccount request. The method always 108// closes the http.Response Body. 109func (client BalancesClient) GetByBillingAccountResponder(resp *http.Response) (result Balance, err error) { 110 err = autorest.Respond( 111 resp, 112 azure.WithErrorUnlessStatusCode(http.StatusOK), 113 autorest.ByUnmarshallingJSON(&result), 114 autorest.ByClosing()) 115 result.Response = autorest.Response{Response: resp} 116 return 117} 118 119// GetForBillingPeriodByBillingAccount gets the balances for a scope by billing period and billingAccountId. Balances 120// are available via this API only for May 1, 2014 or later. 121// Parameters: 122// billingAccountID - billingAccount ID 123// billingPeriodName - billing Period Name. 124func (client BalancesClient) GetForBillingPeriodByBillingAccount(ctx context.Context, billingAccountID string, billingPeriodName string) (result Balance, err error) { 125 if tracing.IsEnabled() { 126 ctx = tracing.StartSpan(ctx, fqdn+"/BalancesClient.GetForBillingPeriodByBillingAccount") 127 defer func() { 128 sc := -1 129 if result.Response.Response != nil { 130 sc = result.Response.Response.StatusCode 131 } 132 tracing.EndSpan(ctx, sc, err) 133 }() 134 } 135 req, err := client.GetForBillingPeriodByBillingAccountPreparer(ctx, billingAccountID, billingPeriodName) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "consumption.BalancesClient", "GetForBillingPeriodByBillingAccount", nil, "Failure preparing request") 138 return 139 } 140 141 resp, err := client.GetForBillingPeriodByBillingAccountSender(req) 142 if err != nil { 143 result.Response = autorest.Response{Response: resp} 144 err = autorest.NewErrorWithError(err, "consumption.BalancesClient", "GetForBillingPeriodByBillingAccount", resp, "Failure sending request") 145 return 146 } 147 148 result, err = client.GetForBillingPeriodByBillingAccountResponder(resp) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "consumption.BalancesClient", "GetForBillingPeriodByBillingAccount", resp, "Failure responding to request") 151 return 152 } 153 154 return 155} 156 157// GetForBillingPeriodByBillingAccountPreparer prepares the GetForBillingPeriodByBillingAccount request. 158func (client BalancesClient) GetForBillingPeriodByBillingAccountPreparer(ctx context.Context, billingAccountID string, billingPeriodName string) (*http.Request, error) { 159 pathParameters := map[string]interface{}{ 160 "billingAccountId": autorest.Encode("path", billingAccountID), 161 "billingPeriodName": autorest.Encode("path", billingPeriodName), 162 } 163 164 const APIVersion = "2018-10-01" 165 queryParameters := map[string]interface{}{ 166 "api-version": APIVersion, 167 } 168 169 preparer := autorest.CreatePreparer( 170 autorest.AsGet(), 171 autorest.WithBaseURL(client.BaseURI), 172 autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/balances", pathParameters), 173 autorest.WithQueryParameters(queryParameters)) 174 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 175} 176 177// GetForBillingPeriodByBillingAccountSender sends the GetForBillingPeriodByBillingAccount request. The method will close the 178// http.Response Body if it receives an error. 179func (client BalancesClient) GetForBillingPeriodByBillingAccountSender(req *http.Request) (*http.Response, error) { 180 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 181} 182 183// GetForBillingPeriodByBillingAccountResponder handles the response to the GetForBillingPeriodByBillingAccount request. The method always 184// closes the http.Response Body. 185func (client BalancesClient) GetForBillingPeriodByBillingAccountResponder(resp *http.Response) (result Balance, err error) { 186 err = autorest.Respond( 187 resp, 188 azure.WithErrorUnlessStatusCode(http.StatusOK), 189 autorest.ByUnmarshallingJSON(&result), 190 autorest.ByClosing()) 191 result.Response = autorest.Response{Response: resp} 192 return 193} 194