1package 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 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// PriceSheetClient is the consumption management client provides access to consumption resources for Azure Enterprise 19// Subscriptions. 20type PriceSheetClient struct { 21 BaseClient 22} 23 24// NewPriceSheetClient creates an instance of the PriceSheetClient client. 25func NewPriceSheetClient(subscriptionID string) PriceSheetClient { 26 return NewPriceSheetClientWithBaseURI(DefaultBaseURI, subscriptionID) 27} 28 29// NewPriceSheetClientWithBaseURI creates an instance of the PriceSheetClient client using a custom endpoint. Use this 30// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 31func NewPriceSheetClientWithBaseURI(baseURI string, subscriptionID string) PriceSheetClient { 32 return PriceSheetClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// Get gets the price sheet for a scope by subscriptionId. Price sheet is available via this API only for May 1, 2014 36// or later. 37// Parameters: 38// expand - may be used to expand the properties/meterDetails within a price sheet. By default, these fields 39// are not included when returning price sheet. 40// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response 41// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that 42// specifies a starting point to use for subsequent calls. 43// top - may be used to limit the number of results to the top N results. 44func (client PriceSheetClient) Get(ctx context.Context, expand string, skiptoken string, top *int32) (result PriceSheetResult, err error) { 45 if tracing.IsEnabled() { 46 ctx = tracing.StartSpan(ctx, fqdn+"/PriceSheetClient.Get") 47 defer func() { 48 sc := -1 49 if result.Response.Response != nil { 50 sc = result.Response.Response.StatusCode 51 } 52 tracing.EndSpan(ctx, sc, err) 53 }() 54 } 55 if err := validation.Validate([]validation.Validation{ 56 {TargetValue: top, 57 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 58 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil}, 59 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, 60 }}}}}); err != nil { 61 return result, validation.NewError("consumption.PriceSheetClient", "Get", err.Error()) 62 } 63 64 req, err := client.GetPreparer(ctx, expand, skiptoken, top) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "consumption.PriceSheetClient", "Get", nil, "Failure preparing request") 67 return 68 } 69 70 resp, err := client.GetSender(req) 71 if err != nil { 72 result.Response = autorest.Response{Response: resp} 73 err = autorest.NewErrorWithError(err, "consumption.PriceSheetClient", "Get", resp, "Failure sending request") 74 return 75 } 76 77 result, err = client.GetResponder(resp) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "consumption.PriceSheetClient", "Get", resp, "Failure responding to request") 80 return 81 } 82 83 return 84} 85 86// GetPreparer prepares the Get request. 87func (client PriceSheetClient) GetPreparer(ctx context.Context, expand string, skiptoken string, top *int32) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 } 91 92 const APIVersion = "2018-03-31" 93 queryParameters := map[string]interface{}{ 94 "api-version": APIVersion, 95 } 96 if len(expand) > 0 { 97 queryParameters["$expand"] = autorest.Encode("query", expand) 98 } 99 if len(skiptoken) > 0 { 100 queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) 101 } 102 if top != nil { 103 queryParameters["$top"] = autorest.Encode("query", *top) 104 } 105 106 preparer := autorest.CreatePreparer( 107 autorest.AsGet(), 108 autorest.WithBaseURL(client.BaseURI), 109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/pricesheets/default", pathParameters), 110 autorest.WithQueryParameters(queryParameters)) 111 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 112} 113 114// GetSender sends the Get request. The method will close the 115// http.Response Body if it receives an error. 116func (client PriceSheetClient) GetSender(req *http.Request) (*http.Response, error) { 117 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 118} 119 120// GetResponder handles the response to the Get request. The method always 121// closes the http.Response Body. 122func (client PriceSheetClient) GetResponder(resp *http.Response) (result PriceSheetResult, err error) { 123 err = autorest.Respond( 124 resp, 125 azure.WithErrorUnlessStatusCode(http.StatusOK), 126 autorest.ByUnmarshallingJSON(&result), 127 autorest.ByClosing()) 128 result.Response = autorest.Response{Response: resp} 129 return 130} 131 132// GetByBillingPeriod get the price sheet for a scope by subscriptionId and billing period. Price sheet is available 133// via this API only for May 1, 2014 or later. 134// Parameters: 135// billingPeriodName - billing Period Name. 136// expand - may be used to expand the properties/meterDetails within a price sheet. By default, these fields 137// are not included when returning price sheet. 138// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response 139// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that 140// specifies a starting point to use for subsequent calls. 141// top - may be used to limit the number of results to the top N results. 142func (client PriceSheetClient) GetByBillingPeriod(ctx context.Context, billingPeriodName string, expand string, skiptoken string, top *int32) (result PriceSheetResult, err error) { 143 if tracing.IsEnabled() { 144 ctx = tracing.StartSpan(ctx, fqdn+"/PriceSheetClient.GetByBillingPeriod") 145 defer func() { 146 sc := -1 147 if result.Response.Response != nil { 148 sc = result.Response.Response.StatusCode 149 } 150 tracing.EndSpan(ctx, sc, err) 151 }() 152 } 153 if err := validation.Validate([]validation.Validation{ 154 {TargetValue: top, 155 Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, 156 Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil}, 157 {Target: "top", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil}, 158 }}}}}); err != nil { 159 return result, validation.NewError("consumption.PriceSheetClient", "GetByBillingPeriod", err.Error()) 160 } 161 162 req, err := client.GetByBillingPeriodPreparer(ctx, billingPeriodName, expand, skiptoken, top) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "consumption.PriceSheetClient", "GetByBillingPeriod", nil, "Failure preparing request") 165 return 166 } 167 168 resp, err := client.GetByBillingPeriodSender(req) 169 if err != nil { 170 result.Response = autorest.Response{Response: resp} 171 err = autorest.NewErrorWithError(err, "consumption.PriceSheetClient", "GetByBillingPeriod", resp, "Failure sending request") 172 return 173 } 174 175 result, err = client.GetByBillingPeriodResponder(resp) 176 if err != nil { 177 err = autorest.NewErrorWithError(err, "consumption.PriceSheetClient", "GetByBillingPeriod", resp, "Failure responding to request") 178 return 179 } 180 181 return 182} 183 184// GetByBillingPeriodPreparer prepares the GetByBillingPeriod request. 185func (client PriceSheetClient) GetByBillingPeriodPreparer(ctx context.Context, billingPeriodName string, expand string, skiptoken string, top *int32) (*http.Request, error) { 186 pathParameters := map[string]interface{}{ 187 "billingPeriodName": autorest.Encode("path", billingPeriodName), 188 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 189 } 190 191 const APIVersion = "2018-03-31" 192 queryParameters := map[string]interface{}{ 193 "api-version": APIVersion, 194 } 195 if len(expand) > 0 { 196 queryParameters["$expand"] = autorest.Encode("query", expand) 197 } 198 if len(skiptoken) > 0 { 199 queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) 200 } 201 if top != nil { 202 queryParameters["$top"] = autorest.Encode("query", *top) 203 } 204 205 preparer := autorest.CreatePreparer( 206 autorest.AsGet(), 207 autorest.WithBaseURL(client.BaseURI), 208 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/pricesheets/default", pathParameters), 209 autorest.WithQueryParameters(queryParameters)) 210 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 211} 212 213// GetByBillingPeriodSender sends the GetByBillingPeriod request. The method will close the 214// http.Response Body if it receives an error. 215func (client PriceSheetClient) GetByBillingPeriodSender(req *http.Request) (*http.Response, error) { 216 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 217} 218 219// GetByBillingPeriodResponder handles the response to the GetByBillingPeriod request. The method always 220// closes the http.Response Body. 221func (client PriceSheetClient) GetByBillingPeriodResponder(resp *http.Response) (result PriceSheetResult, err error) { 222 err = autorest.Respond( 223 resp, 224 azure.WithErrorUnlessStatusCode(http.StatusOK), 225 autorest.ByUnmarshallingJSON(&result), 226 autorest.ByClosing()) 227 result.Response = autorest.Response{Response: resp} 228 return 229} 230