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// TenantsClient is the consumption management client provides access to consumption resources for Azure Enterprise 29// Subscriptions. 30type TenantsClient struct { 31 BaseClient 32} 33 34// NewTenantsClient creates an instance of the TenantsClient client. 35func NewTenantsClient(subscriptionID string) TenantsClient { 36 return NewTenantsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewTenantsClientWithBaseURI creates an instance of the TenantsClient client using a custom endpoint. Use this when 40// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewTenantsClientWithBaseURI(baseURI string, subscriptionID string) TenantsClient { 42 return TenantsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// Get gets a Tenant Properties. 46// Parameters: 47// billingAccountID - billing Account Id. 48// billingProfileID - billing Profile Id. 49func (client TenantsClient) Get(ctx context.Context, billingAccountID string, billingProfileID string) (result TenantListResult, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/TenantsClient.Get") 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.GetPreparer(ctx, billingAccountID, billingProfileID) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "consumption.TenantsClient", "Get", nil, "Failure preparing request") 63 return 64 } 65 66 resp, err := client.GetSender(req) 67 if err != nil { 68 result.Response = autorest.Response{Response: resp} 69 err = autorest.NewErrorWithError(err, "consumption.TenantsClient", "Get", resp, "Failure sending request") 70 return 71 } 72 73 result, err = client.GetResponder(resp) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "consumption.TenantsClient", "Get", resp, "Failure responding to request") 76 return 77 } 78 79 return 80} 81 82// GetPreparer prepares the Get request. 83func (client TenantsClient) GetPreparer(ctx context.Context, billingAccountID string, billingProfileID string) (*http.Request, error) { 84 pathParameters := map[string]interface{}{ 85 "billingAccountId": autorest.Encode("path", billingAccountID), 86 "billingProfileId": autorest.Encode("path", billingProfileID), 87 } 88 89 const APIVersion = "2018-10-01" 90 queryParameters := map[string]interface{}{ 91 "api-version": APIVersion, 92 } 93 94 preparer := autorest.CreatePreparer( 95 autorest.AsGet(), 96 autorest.WithBaseURL(client.BaseURI), 97 autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}/providers/Microsoft.Consumption/tenants", pathParameters), 98 autorest.WithQueryParameters(queryParameters)) 99 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 100} 101 102// GetSender sends the Get request. The method will close the 103// http.Response Body if it receives an error. 104func (client TenantsClient) GetSender(req *http.Request) (*http.Response, error) { 105 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 106} 107 108// GetResponder handles the response to the Get request. The method always 109// closes the http.Response Body. 110func (client TenantsClient) GetResponder(resp *http.Response) (result TenantListResult, err error) { 111 err = autorest.Respond( 112 resp, 113 azure.WithErrorUnlessStatusCode(http.StatusOK), 114 autorest.ByUnmarshallingJSON(&result), 115 autorest.ByClosing()) 116 result.Response = autorest.Response{Response: resp} 117 return 118} 119