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 } 77 78 return 79} 80 81// GetByBillingAccountPreparer prepares the GetByBillingAccount request. 82func (client BalancesClient) GetByBillingAccountPreparer(ctx context.Context, billingAccountID string) (*http.Request, error) { 83 pathParameters := map[string]interface{}{ 84 "billingAccountId": autorest.Encode("path", billingAccountID), 85 } 86 87 const APIVersion = "2018-08-31" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsGet(), 94 autorest.WithBaseURL(client.BaseURI), 95 autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/balances", pathParameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// GetByBillingAccountSender sends the GetByBillingAccount request. The method will close the 101// http.Response Body if it receives an error. 102func (client BalancesClient) GetByBillingAccountSender(req *http.Request) (*http.Response, error) { 103 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 104} 105 106// GetByBillingAccountResponder handles the response to the GetByBillingAccount request. The method always 107// closes the http.Response Body. 108func (client BalancesClient) GetByBillingAccountResponder(resp *http.Response) (result Balance, err error) { 109 err = autorest.Respond( 110 resp, 111 client.ByInspecting(), 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 } 152 153 return 154} 155 156// GetForBillingPeriodByBillingAccountPreparer prepares the GetForBillingPeriodByBillingAccount request. 157func (client BalancesClient) GetForBillingPeriodByBillingAccountPreparer(ctx context.Context, billingAccountID string, billingPeriodName string) (*http.Request, error) { 158 pathParameters := map[string]interface{}{ 159 "billingAccountId": autorest.Encode("path", billingAccountID), 160 "billingPeriodName": autorest.Encode("path", billingPeriodName), 161 } 162 163 const APIVersion = "2018-08-31" 164 queryParameters := map[string]interface{}{ 165 "api-version": APIVersion, 166 } 167 168 preparer := autorest.CreatePreparer( 169 autorest.AsGet(), 170 autorest.WithBaseURL(client.BaseURI), 171 autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/balances", pathParameters), 172 autorest.WithQueryParameters(queryParameters)) 173 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 174} 175 176// GetForBillingPeriodByBillingAccountSender sends the GetForBillingPeriodByBillingAccount request. The method will close the 177// http.Response Body if it receives an error. 178func (client BalancesClient) GetForBillingPeriodByBillingAccountSender(req *http.Request) (*http.Response, error) { 179 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 180} 181 182// GetForBillingPeriodByBillingAccountResponder handles the response to the GetForBillingPeriodByBillingAccount request. The method always 183// closes the http.Response Body. 184func (client BalancesClient) GetForBillingPeriodByBillingAccountResponder(resp *http.Response) (result Balance, err error) { 185 err = autorest.Respond( 186 resp, 187 client.ByInspecting(), 188 azure.WithErrorUnlessStatusCode(http.StatusOK), 189 autorest.ByUnmarshallingJSON(&result), 190 autorest.ByClosing()) 191 result.Response = autorest.Response{Response: resp} 192 return 193} 194