diff --git a/profiles/preview/consumption/mgmt/consumption/models.go b/profiles/preview/consumption/mgmt/consumption/models.go index 8ebf23e92c2f..cf86760f7a86 100644 --- a/profiles/preview/consumption/mgmt/consumption/models.go +++ b/profiles/preview/consumption/mgmt/consumption/models.go @@ -19,144 +19,70 @@ package consumption -import original "github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2018-03-31/consumption" - -type BudgetsClient = original.BudgetsClient +import original "github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2018-05-31/consumption" const ( DefaultBaseURI = original.DefaultBaseURI ) type BaseClient = original.BaseClient -type CostTagsClient = original.CostTagsClient -type MarketplacesClient = original.MarketplacesClient -type CategoryType = original.CategoryType - -const ( - Cost CategoryType = original.Cost - Usage CategoryType = original.Usage -) - -type Datagrain = original.Datagrain +type ForecastsClient = original.ForecastsClient +type Bound = original.Bound const ( - DailyGrain Datagrain = original.DailyGrain - MonthlyGrain Datagrain = original.MonthlyGrain + Lower Bound = original.Lower + Upper Bound = original.Upper ) -type OperatorType = original.OperatorType +type ChargeType = original.ChargeType const ( - EqualTo OperatorType = original.EqualTo - GreaterThan OperatorType = original.GreaterThan - GreaterThanOrEqualTo OperatorType = original.GreaterThanOrEqualTo + ChargeTypeActual ChargeType = original.ChargeTypeActual + ChargeTypeForecast ChargeType = original.ChargeTypeForecast ) -type TimeGrainType = original.TimeGrainType +type Grain = original.Grain const ( - Annually TimeGrainType = original.Annually - Monthly TimeGrainType = original.Monthly - Quarterly TimeGrainType = original.Quarterly + Daily Grain = original.Daily + Monthly Grain = original.Monthly + Yearly Grain = original.Yearly ) -type Budget = original.Budget -type BudgetProperties = original.BudgetProperties -type BudgetsListResult = original.BudgetsListResult -type BudgetsListResultIterator = original.BudgetsListResultIterator -type BudgetsListResultPage = original.BudgetsListResultPage -type BudgetTimePeriod = original.BudgetTimePeriod -type CostTag = original.CostTag -type CostTagProperties = original.CostTagProperties -type CostTags = original.CostTags -type CurrentSpend = original.CurrentSpend type ErrorDetails = original.ErrorDetails type ErrorResponse = original.ErrorResponse -type Filters = original.Filters -type Marketplace = original.Marketplace -type MarketplaceProperties = original.MarketplaceProperties -type MarketplacesListResult = original.MarketplacesListResult -type MarketplacesListResultIterator = original.MarketplacesListResultIterator -type MarketplacesListResultPage = original.MarketplacesListResultPage -type MeterDetails = original.MeterDetails -type Notification = original.Notification +type Forecast = original.Forecast +type ForecastProperties = original.ForecastProperties +type ForecastPropertiesConfidenceLevelsItem = original.ForecastPropertiesConfidenceLevelsItem +type ForecastsListResult = original.ForecastsListResult type Operation = original.Operation type OperationDisplay = original.OperationDisplay type OperationListResult = original.OperationListResult type OperationListResultIterator = original.OperationListResultIterator type OperationListResultPage = original.OperationListResultPage -type PriceSheetModel = original.PriceSheetModel -type PriceSheetProperties = original.PriceSheetProperties -type PriceSheetResult = original.PriceSheetResult -type ProxyResource = original.ProxyResource -type ReservationDetails = original.ReservationDetails -type ReservationDetailsListResult = original.ReservationDetailsListResult -type ReservationDetailsListResultIterator = original.ReservationDetailsListResultIterator -type ReservationDetailsListResultPage = original.ReservationDetailsListResultPage -type ReservationDetailsProperties = original.ReservationDetailsProperties -type ReservationRecommendations = original.ReservationRecommendations -type ReservationRecommendationsListResult = original.ReservationRecommendationsListResult -type ReservationRecommendationsListResultIterator = original.ReservationRecommendationsListResultIterator -type ReservationRecommendationsListResultPage = original.ReservationRecommendationsListResultPage -type ReservationRecommendationsProperties = original.ReservationRecommendationsProperties -type ReservationSummaries = original.ReservationSummaries -type ReservationSummariesListResult = original.ReservationSummariesListResult -type ReservationSummariesListResultIterator = original.ReservationSummariesListResultIterator -type ReservationSummariesListResultPage = original.ReservationSummariesListResultPage -type ReservationSummariesProperties = original.ReservationSummariesProperties type Resource = original.Resource -type ResourceAttributes = original.ResourceAttributes -type Tag = original.Tag -type TagProperties = original.TagProperties -type Tags = original.Tags -type UsageDetail = original.UsageDetail -type UsageDetailProperties = original.UsageDetailProperties -type UsageDetailsListResult = original.UsageDetailsListResult -type UsageDetailsListResultIterator = original.UsageDetailsListResultIterator -type UsageDetailsListResultPage = original.UsageDetailsListResultPage type OperationsClient = original.OperationsClient -type PriceSheetClient = original.PriceSheetClient -type ReservationRecommendationsClient = original.ReservationRecommendationsClient -type ReservationsDetailsClient = original.ReservationsDetailsClient -type ReservationsSummariesClient = original.ReservationsSummariesClient -type TagsClient = original.TagsClient -type UsageDetailsClient = original.UsageDetailsClient -func NewBudgetsClient(subscriptionID string) BudgetsClient { - return original.NewBudgetsClient(subscriptionID) -} -func NewBudgetsClientWithBaseURI(baseURI string, subscriptionID string) BudgetsClient { - return original.NewBudgetsClientWithBaseURI(baseURI, subscriptionID) -} func New(subscriptionID string) BaseClient { return original.New(subscriptionID) } func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { return original.NewWithBaseURI(baseURI, subscriptionID) } -func NewCostTagsClient(subscriptionID string) CostTagsClient { - return original.NewCostTagsClient(subscriptionID) -} -func NewCostTagsClientWithBaseURI(baseURI string, subscriptionID string) CostTagsClient { - return original.NewCostTagsClientWithBaseURI(baseURI, subscriptionID) -} -func NewMarketplacesClient(subscriptionID string) MarketplacesClient { - return original.NewMarketplacesClient(subscriptionID) +func NewForecastsClient(subscriptionID string) ForecastsClient { + return original.NewForecastsClient(subscriptionID) } -func NewMarketplacesClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesClient { - return original.NewMarketplacesClientWithBaseURI(baseURI, subscriptionID) +func NewForecastsClientWithBaseURI(baseURI string, subscriptionID string) ForecastsClient { + return original.NewForecastsClientWithBaseURI(baseURI, subscriptionID) } -func PossibleCategoryTypeValues() []CategoryType { - return original.PossibleCategoryTypeValues() +func PossibleBoundValues() []Bound { + return original.PossibleBoundValues() } -func PossibleDatagrainValues() []Datagrain { - return original.PossibleDatagrainValues() +func PossibleChargeTypeValues() []ChargeType { + return original.PossibleChargeTypeValues() } -func PossibleOperatorTypeValues() []OperatorType { - return original.PossibleOperatorTypeValues() -} -func PossibleTimeGrainTypeValues() []TimeGrainType { - return original.PossibleTimeGrainTypeValues() +func PossibleGrainValues() []Grain { + return original.PossibleGrainValues() } func NewOperationsClient(subscriptionID string) OperationsClient { return original.NewOperationsClient(subscriptionID) @@ -164,42 +90,6 @@ func NewOperationsClient(subscriptionID string) OperationsClient { func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient { return original.NewOperationsClientWithBaseURI(baseURI, subscriptionID) } -func NewPriceSheetClient(subscriptionID string) PriceSheetClient { - return original.NewPriceSheetClient(subscriptionID) -} -func NewPriceSheetClientWithBaseURI(baseURI string, subscriptionID string) PriceSheetClient { - return original.NewPriceSheetClientWithBaseURI(baseURI, subscriptionID) -} -func NewReservationRecommendationsClient(subscriptionID string) ReservationRecommendationsClient { - return original.NewReservationRecommendationsClient(subscriptionID) -} -func NewReservationRecommendationsClientWithBaseURI(baseURI string, subscriptionID string) ReservationRecommendationsClient { - return original.NewReservationRecommendationsClientWithBaseURI(baseURI, subscriptionID) -} -func NewReservationsDetailsClient(subscriptionID string) ReservationsDetailsClient { - return original.NewReservationsDetailsClient(subscriptionID) -} -func NewReservationsDetailsClientWithBaseURI(baseURI string, subscriptionID string) ReservationsDetailsClient { - return original.NewReservationsDetailsClientWithBaseURI(baseURI, subscriptionID) -} -func NewReservationsSummariesClient(subscriptionID string) ReservationsSummariesClient { - return original.NewReservationsSummariesClient(subscriptionID) -} -func NewReservationsSummariesClientWithBaseURI(baseURI string, subscriptionID string) ReservationsSummariesClient { - return original.NewReservationsSummariesClientWithBaseURI(baseURI, subscriptionID) -} -func NewTagsClient(subscriptionID string) TagsClient { - return original.NewTagsClient(subscriptionID) -} -func NewTagsClientWithBaseURI(baseURI string, subscriptionID string) TagsClient { - return original.NewTagsClientWithBaseURI(baseURI, subscriptionID) -} -func NewUsageDetailsClient(subscriptionID string) UsageDetailsClient { - return original.NewUsageDetailsClient(subscriptionID) -} -func NewUsageDetailsClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsClient { - return original.NewUsageDetailsClientWithBaseURI(baseURI, subscriptionID) -} func UserAgent() string { return original.UserAgent() + " profiles/preview" } diff --git a/services/consumption/mgmt/2018-03-31/consumption/client.go b/services/consumption/mgmt/2018-03-31/consumption/client.go index 8fdda610a9f5..195726329d0d 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/client.go +++ b/services/consumption/mgmt/2018-03-31/consumption/client.go @@ -21,7 +21,10 @@ package consumption // Changes may cause incorrect behavior and will be lost if the code is regenerated. import ( + "context" "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" ) const ( @@ -49,3 +52,68 @@ func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { SubscriptionID: subscriptionID, } } + +// GetBalancesByBillingAccount gets the balances for a scope by billingAccountId. Balances are available via this API +// only for May 1, 2014 or later. +// Parameters: +// billingAccountID - billingAccount ID +func (client BaseClient) GetBalancesByBillingAccount(ctx context.Context, billingAccountID string) (result Balance, err error) { + req, err := client.GetBalancesByBillingAccountPreparer(ctx, billingAccountID) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BaseClient", "GetBalancesByBillingAccount", nil, "Failure preparing request") + return + } + + resp, err := client.GetBalancesByBillingAccountSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.BaseClient", "GetBalancesByBillingAccount", resp, "Failure sending request") + return + } + + result, err = client.GetBalancesByBillingAccountResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BaseClient", "GetBalancesByBillingAccount", resp, "Failure responding to request") + } + + return +} + +// GetBalancesByBillingAccountPreparer prepares the GetBalancesByBillingAccount request. +func (client BaseClient) GetBalancesByBillingAccountPreparer(ctx context.Context, billingAccountID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingAccountId": autorest.Encode("path", billingAccountID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/balances", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetBalancesByBillingAccountSender sends the GetBalancesByBillingAccount request. The method will close the +// http.Response Body if it receives an error. +func (client BaseClient) GetBalancesByBillingAccountSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetBalancesByBillingAccountResponder handles the response to the GetBalancesByBillingAccount request. The method always +// closes the http.Response Body. +func (client BaseClient) GetBalancesByBillingAccountResponder(resp *http.Response) (result Balance, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/costtags.go b/services/consumption/mgmt/2018-03-31/consumption/costtags.go index 3432354e19d3..7932dab9c2b9 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/costtags.go +++ b/services/consumption/mgmt/2018-03-31/consumption/costtags.go @@ -44,7 +44,7 @@ func NewCostTagsClientWithBaseURI(baseURI string, subscriptionID string) CostTag // requires latest eTag to be set in the request mandatorily. You may obtain the latest eTag by performing a get // operation. Create operation does not require eTag. // Parameters: -// billingAccountID - azure Billing Account ID. +// billingAccountID - billingAccount ID // parameters - parameters supplied to the Create cost tags operation. func (client CostTagsClient) CreateOrUpdate(ctx context.Context, billingAccountID string, parameters CostTags) (result CostTags, err error) { req, err := client.CreateOrUpdatePreparer(ctx, billingAccountID, parameters) @@ -83,7 +83,7 @@ func (client CostTagsClient) CreateOrUpdatePreparer(ctx context.Context, billing autorest.AsContentType("application/json; charset=utf-8"), autorest.AsPut(), autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/providers/Microsoft.CostManagement/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/costTags", pathParameters), + autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/costTags", pathParameters), autorest.WithJSON(parameters), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) @@ -111,7 +111,7 @@ func (client CostTagsClient) CreateOrUpdateResponder(resp *http.Response) (resul // Get get cost tags for a billing account. // Parameters: -// billingAccountID - azure Billing Account ID. +// billingAccountID - billingAccount ID func (client CostTagsClient) Get(ctx context.Context, billingAccountID string) (result CostTags, err error) { req, err := client.GetPreparer(ctx, billingAccountID) if err != nil { @@ -148,7 +148,7 @@ func (client CostTagsClient) GetPreparer(ctx context.Context, billingAccountID s preparer := autorest.CreatePreparer( autorest.AsGet(), autorest.WithBaseURL(client.BaseURI), - autorest.WithPathParameters("/providers/Microsoft.CostManagement/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/costTags", pathParameters), + autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/costTags", pathParameters), autorest.WithQueryParameters(queryParameters)) return preparer.Prepare((&http.Request{}).WithContext(ctx)) } diff --git a/services/consumption/mgmt/2018-03-31/consumption/getbalancesbybillingaccount.go b/services/consumption/mgmt/2018-03-31/consumption/getbalancesbybillingaccount.go new file mode 100644 index 000000000000..f1822148b1f9 --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/getbalancesbybillingaccount.go @@ -0,0 +1,108 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// GetBalancesByBillingAccountClient is the consumption management client provides access to consumption resources for +// Azure Enterprise Subscriptions. +type GetBalancesByBillingAccountClient struct { + BaseClient +} + +// NewGetBalancesByBillingAccountClient creates an instance of the GetBalancesByBillingAccountClient client. +func NewGetBalancesByBillingAccountClient(subscriptionID string) GetBalancesByBillingAccountClient { + return NewGetBalancesByBillingAccountClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewGetBalancesByBillingAccountClientWithBaseURI creates an instance of the GetBalancesByBillingAccountClient client. +func NewGetBalancesByBillingAccountClientWithBaseURI(baseURI string, subscriptionID string) GetBalancesByBillingAccountClient { + return GetBalancesByBillingAccountClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// ByBillingPeriod gets the balances for a scope by billing period and billingAccountId. Balances are available via +// this API only for May 1, 2014 or later. +// Parameters: +// billingAccountID - billingAccount ID +// billingPeriodName - billing Period Name. +func (client GetBalancesByBillingAccountClient) ByBillingPeriod(ctx context.Context, billingAccountID string, billingPeriodName string) (result Balance, err error) { + req, err := client.ByBillingPeriodPreparer(ctx, billingAccountID, billingPeriodName) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.GetBalancesByBillingAccountClient", "ByBillingPeriod", nil, "Failure preparing request") + return + } + + resp, err := client.ByBillingPeriodSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.GetBalancesByBillingAccountClient", "ByBillingPeriod", resp, "Failure sending request") + return + } + + result, err = client.ByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.GetBalancesByBillingAccountClient", "ByBillingPeriod", resp, "Failure responding to request") + } + + return +} + +// ByBillingPeriodPreparer prepares the ByBillingPeriod request. +func (client GetBalancesByBillingAccountClient) ByBillingPeriodPreparer(ctx context.Context, billingAccountID string, billingPeriodName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingAccountId": autorest.Encode("path", billingAccountID), + "billingPeriodName": autorest.Encode("path", billingPeriodName), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/balances", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ByBillingPeriodSender sends the ByBillingPeriod request. The method will close the +// http.Response Body if it receives an error. +func (client GetBalancesByBillingAccountClient) ByBillingPeriodSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ByBillingPeriodResponder handles the response to the ByBillingPeriod request. The method always +// closes the http.Response Body. +func (client GetBalancesByBillingAccountClient) ByBillingPeriodResponder(resp *http.Response) (result Balance, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/marketplaces.go b/services/consumption/mgmt/2018-03-31/consumption/marketplaces.go index 4d24b76a1f49..88950ed6d2c2 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/marketplaces.go +++ b/services/consumption/mgmt/2018-03-31/consumption/marketplaces.go @@ -41,8 +41,8 @@ func NewMarketplacesClientWithBaseURI(baseURI string, subscriptionID string) Mar return MarketplacesClient{NewWithBaseURI(baseURI, subscriptionID)} } -// List lists the marketplaces for a scope by subscriptionId. Marketplaces are available via this API only for May 1, -// 2014 or later. +// List lists the marketplaces for a scope by subscriptionId and current billing period. Marketplaces are available via +// this API only for May 1, 2014 or later. // Parameters: // filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc // time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', diff --git a/services/consumption/mgmt/2018-03-31/consumption/marketplacesbybillingaccount.go b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbybillingaccount.go new file mode 100644 index 000000000000..6d44b306684e --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbybillingaccount.go @@ -0,0 +1,281 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// MarketplacesByBillingAccountClient is the consumption management client provides access to consumption resources for +// Azure Enterprise Subscriptions. +type MarketplacesByBillingAccountClient struct { + BaseClient +} + +// NewMarketplacesByBillingAccountClient creates an instance of the MarketplacesByBillingAccountClient client. +func NewMarketplacesByBillingAccountClient(subscriptionID string) MarketplacesByBillingAccountClient { + return NewMarketplacesByBillingAccountClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewMarketplacesByBillingAccountClientWithBaseURI creates an instance of the MarketplacesByBillingAccountClient +// client. +func NewMarketplacesByBillingAccountClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesByBillingAccountClient { + return MarketplacesByBillingAccountClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists the marketplaces for a scope by billingAccountId and current billing period. Marketplaces are available +// via this API only for May 1, 2014 or later. +// Parameters: +// billingAccountID - billingAccount ID +// filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. +// top - may be used to limit the number of results to the most recent N marketplaces. +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +func (client MarketplacesByBillingAccountClient) List(ctx context.Context, billingAccountID string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.MarketplacesByBillingAccountClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, billingAccountID, filter, top, skiptoken) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.mlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "List", resp, "Failure sending request") + return + } + + result.mlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client MarketplacesByBillingAccountClient) ListPreparer(ctx context.Context, billingAccountID string, filter string, top *int32, skiptoken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingAccountId": autorest.Encode("path", billingAccountID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/marketplaces", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client MarketplacesByBillingAccountClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client MarketplacesByBillingAccountClient) ListResponder(resp *http.Response) (result MarketplacesListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client MarketplacesByBillingAccountClient) listNextResults(lastResults MarketplacesListResult) (result MarketplacesListResult, err error) { + req, err := lastResults.marketplacesListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client MarketplacesByBillingAccountClient) ListComplete(ctx context.Context, billingAccountID string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) { + result.page, err = client.List(ctx, billingAccountID, filter, top, skiptoken) + return +} + +// ListByBillingPeriod lists the marketplaces for a scope by billing period and billingAccountId. Marketplaces are +// available via this API only for May 1, 2014 or later. +// Parameters: +// billingAccountID - billingAccount ID +// billingPeriodName - billing Period Name. +// filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. +// top - may be used to limit the number of results to the most recent N marketplaces. +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +func (client MarketplacesByBillingAccountClient) ListByBillingPeriod(ctx context.Context, billingAccountID string, billingPeriodName string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.MarketplacesByBillingAccountClient", "ListByBillingPeriod", err.Error()) + } + + result.fn = client.listByBillingPeriodNextResults + req, err := client.ListByBillingPeriodPreparer(ctx, billingAccountID, billingPeriodName, filter, top, skiptoken) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "ListByBillingPeriod", nil, "Failure preparing request") + return + } + + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.mlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "ListByBillingPeriod", resp, "Failure sending request") + return + } + + result.mlr, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "ListByBillingPeriod", resp, "Failure responding to request") + } + + return +} + +// ListByBillingPeriodPreparer prepares the ListByBillingPeriod request. +func (client MarketplacesByBillingAccountClient) ListByBillingPeriodPreparer(ctx context.Context, billingAccountID string, billingPeriodName string, filter string, top *int32, skiptoken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingAccountId": autorest.Encode("path", billingAccountID), + "billingPeriodName": autorest.Encode("path", billingPeriodName), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/marketplaces", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByBillingPeriodSender sends the ListByBillingPeriod request. The method will close the +// http.Response Body if it receives an error. +func (client MarketplacesByBillingAccountClient) ListByBillingPeriodSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByBillingPeriodResponder handles the response to the ListByBillingPeriod request. The method always +// closes the http.Response Body. +func (client MarketplacesByBillingAccountClient) ListByBillingPeriodResponder(resp *http.Response) (result MarketplacesListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByBillingPeriodNextResults retrieves the next set of results, if any. +func (client MarketplacesByBillingAccountClient) listByBillingPeriodNextResults(lastResults MarketplacesListResult) (result MarketplacesListResult, err error) { + req, err := lastResults.marketplacesListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "listByBillingPeriodNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "listByBillingPeriodNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByBillingAccountClient", "listByBillingPeriodNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByBillingPeriodComplete enumerates all values, automatically crossing page boundaries as required. +func (client MarketplacesByBillingAccountClient) ListByBillingPeriodComplete(ctx context.Context, billingAccountID string, billingPeriodName string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) { + result.page, err = client.ListByBillingPeriod(ctx, billingAccountID, billingPeriodName, filter, top, skiptoken) + return +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/marketplacesbydepartment.go b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbydepartment.go new file mode 100644 index 000000000000..285d8810324f --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbydepartment.go @@ -0,0 +1,280 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// MarketplacesByDepartmentClient is the consumption management client provides access to consumption resources for +// Azure Enterprise Subscriptions. +type MarketplacesByDepartmentClient struct { + BaseClient +} + +// NewMarketplacesByDepartmentClient creates an instance of the MarketplacesByDepartmentClient client. +func NewMarketplacesByDepartmentClient(subscriptionID string) MarketplacesByDepartmentClient { + return NewMarketplacesByDepartmentClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewMarketplacesByDepartmentClientWithBaseURI creates an instance of the MarketplacesByDepartmentClient client. +func NewMarketplacesByDepartmentClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesByDepartmentClient { + return MarketplacesByDepartmentClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists the marketplaces for a scope by departmentId and current billing period. Marketplaces are available via +// this API only for May 1, 2014 or later. +// Parameters: +// departmentID - department ID +// filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. +// top - may be used to limit the number of results to the most recent N marketplaces. +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +func (client MarketplacesByDepartmentClient) List(ctx context.Context, departmentID string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.MarketplacesByDepartmentClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, departmentID, filter, top, skiptoken) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.mlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "List", resp, "Failure sending request") + return + } + + result.mlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client MarketplacesByDepartmentClient) ListPreparer(ctx context.Context, departmentID string, filter string, top *int32, skiptoken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "departmentId": autorest.Encode("path", departmentID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/departments/{departmentId}/providers/Microsoft.Consumption/marketplaces", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client MarketplacesByDepartmentClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client MarketplacesByDepartmentClient) ListResponder(resp *http.Response) (result MarketplacesListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client MarketplacesByDepartmentClient) listNextResults(lastResults MarketplacesListResult) (result MarketplacesListResult, err error) { + req, err := lastResults.marketplacesListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client MarketplacesByDepartmentClient) ListComplete(ctx context.Context, departmentID string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) { + result.page, err = client.List(ctx, departmentID, filter, top, skiptoken) + return +} + +// ListByBillingPeriod lists the marketplaces for a scope by billing period and departmentId. Marketplaces are +// available via this API only for May 1, 2014 or later. +// Parameters: +// departmentID - department ID +// billingPeriodName - billing Period Name. +// filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. +// top - may be used to limit the number of results to the most recent N marketplaces. +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +func (client MarketplacesByDepartmentClient) ListByBillingPeriod(ctx context.Context, departmentID string, billingPeriodName string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.MarketplacesByDepartmentClient", "ListByBillingPeriod", err.Error()) + } + + result.fn = client.listByBillingPeriodNextResults + req, err := client.ListByBillingPeriodPreparer(ctx, departmentID, billingPeriodName, filter, top, skiptoken) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "ListByBillingPeriod", nil, "Failure preparing request") + return + } + + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.mlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "ListByBillingPeriod", resp, "Failure sending request") + return + } + + result.mlr, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "ListByBillingPeriod", resp, "Failure responding to request") + } + + return +} + +// ListByBillingPeriodPreparer prepares the ListByBillingPeriod request. +func (client MarketplacesByDepartmentClient) ListByBillingPeriodPreparer(ctx context.Context, departmentID string, billingPeriodName string, filter string, top *int32, skiptoken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingPeriodName": autorest.Encode("path", billingPeriodName), + "departmentId": autorest.Encode("path", departmentID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/departments/{departmentId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/marketplaces", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByBillingPeriodSender sends the ListByBillingPeriod request. The method will close the +// http.Response Body if it receives an error. +func (client MarketplacesByDepartmentClient) ListByBillingPeriodSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByBillingPeriodResponder handles the response to the ListByBillingPeriod request. The method always +// closes the http.Response Body. +func (client MarketplacesByDepartmentClient) ListByBillingPeriodResponder(resp *http.Response) (result MarketplacesListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByBillingPeriodNextResults retrieves the next set of results, if any. +func (client MarketplacesByDepartmentClient) listByBillingPeriodNextResults(lastResults MarketplacesListResult) (result MarketplacesListResult, err error) { + req, err := lastResults.marketplacesListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listByBillingPeriodNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listByBillingPeriodNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByDepartmentClient", "listByBillingPeriodNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByBillingPeriodComplete enumerates all values, automatically crossing page boundaries as required. +func (client MarketplacesByDepartmentClient) ListByBillingPeriodComplete(ctx context.Context, departmentID string, billingPeriodName string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) { + result.page, err = client.ListByBillingPeriod(ctx, departmentID, billingPeriodName, filter, top, skiptoken) + return +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/marketplacesbyenrollmentaccounts.go b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbyenrollmentaccounts.go new file mode 100644 index 000000000000..2f1e8de5d14b --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbyenrollmentaccounts.go @@ -0,0 +1,281 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// MarketplacesByEnrollmentAccountsClient is the consumption management client provides access to consumption resources +// for Azure Enterprise Subscriptions. +type MarketplacesByEnrollmentAccountsClient struct { + BaseClient +} + +// NewMarketplacesByEnrollmentAccountsClient creates an instance of the MarketplacesByEnrollmentAccountsClient client. +func NewMarketplacesByEnrollmentAccountsClient(subscriptionID string) MarketplacesByEnrollmentAccountsClient { + return NewMarketplacesByEnrollmentAccountsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewMarketplacesByEnrollmentAccountsClientWithBaseURI creates an instance of the +// MarketplacesByEnrollmentAccountsClient client. +func NewMarketplacesByEnrollmentAccountsClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesByEnrollmentAccountsClient { + return MarketplacesByEnrollmentAccountsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists the marketplaces for a scope by enrollmentAccountId and current billing period. Marketplaces are +// available via this API only for May 1, 2014 or later. +// Parameters: +// enrollmentAccountID - enrollmentAccount ID +// filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. +// top - may be used to limit the number of results to the most recent N marketplaces. +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +func (client MarketplacesByEnrollmentAccountsClient) List(ctx context.Context, enrollmentAccountID string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.MarketplacesByEnrollmentAccountsClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, enrollmentAccountID, filter, top, skiptoken) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.mlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "List", resp, "Failure sending request") + return + } + + result.mlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client MarketplacesByEnrollmentAccountsClient) ListPreparer(ctx context.Context, enrollmentAccountID string, filter string, top *int32, skiptoken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "enrollmentAccountId": autorest.Encode("path", enrollmentAccountID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/enrollmentAccounts/{enrollmentAccountId}/providers/Microsoft.Consumption/marketplaces", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client MarketplacesByEnrollmentAccountsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client MarketplacesByEnrollmentAccountsClient) ListResponder(resp *http.Response) (result MarketplacesListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client MarketplacesByEnrollmentAccountsClient) listNextResults(lastResults MarketplacesListResult) (result MarketplacesListResult, err error) { + req, err := lastResults.marketplacesListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client MarketplacesByEnrollmentAccountsClient) ListComplete(ctx context.Context, enrollmentAccountID string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) { + result.page, err = client.List(ctx, enrollmentAccountID, filter, top, skiptoken) + return +} + +// ListByBillingPeriod lists the marketplaces for a scope by billing period and enrollmentAccountId. Marketplaces are +// available via this API only for May 1, 2014 or later. +// Parameters: +// enrollmentAccountID - enrollmentAccount ID +// billingPeriodName - billing Period Name. +// filter - may be used to filter marketplaces by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. +// top - may be used to limit the number of results to the most recent N marketplaces. +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +func (client MarketplacesByEnrollmentAccountsClient) ListByBillingPeriod(ctx context.Context, enrollmentAccountID string, billingPeriodName string, filter string, top *int32, skiptoken string) (result MarketplacesListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.MarketplacesByEnrollmentAccountsClient", "ListByBillingPeriod", err.Error()) + } + + result.fn = client.listByBillingPeriodNextResults + req, err := client.ListByBillingPeriodPreparer(ctx, enrollmentAccountID, billingPeriodName, filter, top, skiptoken) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "ListByBillingPeriod", nil, "Failure preparing request") + return + } + + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.mlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "ListByBillingPeriod", resp, "Failure sending request") + return + } + + result.mlr, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "ListByBillingPeriod", resp, "Failure responding to request") + } + + return +} + +// ListByBillingPeriodPreparer prepares the ListByBillingPeriod request. +func (client MarketplacesByEnrollmentAccountsClient) ListByBillingPeriodPreparer(ctx context.Context, enrollmentAccountID string, billingPeriodName string, filter string, top *int32, skiptoken string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingPeriodName": autorest.Encode("path", billingPeriodName), + "enrollmentAccountId": autorest.Encode("path", enrollmentAccountID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/enrollmentAccounts/{enrollmentAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/marketplaces", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByBillingPeriodSender sends the ListByBillingPeriod request. The method will close the +// http.Response Body if it receives an error. +func (client MarketplacesByEnrollmentAccountsClient) ListByBillingPeriodSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByBillingPeriodResponder handles the response to the ListByBillingPeriod request. The method always +// closes the http.Response Body. +func (client MarketplacesByEnrollmentAccountsClient) ListByBillingPeriodResponder(resp *http.Response) (result MarketplacesListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByBillingPeriodNextResults retrieves the next set of results, if any. +func (client MarketplacesByEnrollmentAccountsClient) listByBillingPeriodNextResults(lastResults MarketplacesListResult) (result MarketplacesListResult, err error) { + req, err := lastResults.marketplacesListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "listByBillingPeriodNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "listByBillingPeriodNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.MarketplacesByEnrollmentAccountsClient", "listByBillingPeriodNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByBillingPeriodComplete enumerates all values, automatically crossing page boundaries as required. +func (client MarketplacesByEnrollmentAccountsClient) ListByBillingPeriodComplete(ctx context.Context, enrollmentAccountID string, billingPeriodName string, filter string, top *int32, skiptoken string) (result MarketplacesListResultIterator, err error) { + result.page, err = client.ListByBillingPeriod(ctx, enrollmentAccountID, billingPeriodName, filter, top, skiptoken) + return +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/models.go b/services/consumption/mgmt/2018-03-31/consumption/models.go index 64d81eec3494..20f4318527cf 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/models.go +++ b/services/consumption/mgmt/2018-03-31/consumption/models.go @@ -27,6 +27,23 @@ import ( "net/http" ) +// BillingFrequency enumerates the values for billing frequency. +type BillingFrequency string + +const ( + // Month ... + Month BillingFrequency = "Month" + // Quarter ... + Quarter BillingFrequency = "Quarter" + // Year ... + Year BillingFrequency = "Year" +) + +// PossibleBillingFrequencyValues returns an array of possible values for the BillingFrequency const type. +func PossibleBillingFrequencyValues() []BillingFrequency { + return []BillingFrequency{Month, Quarter, Year} +} + // CategoryType enumerates the values for category type. type CategoryType string @@ -91,6 +108,151 @@ func PossibleTimeGrainTypeValues() []TimeGrainType { return []TimeGrainType{Annually, Monthly, Quarterly} } +// Balance a balance resource. +type Balance struct { + autorest.Response `json:"-"` + *BalanceProperties `json:"properties,omitempty"` + // ID - Resource Id. + ID *string `json:"id,omitempty"` + // Name - Resource name. + Name *string `json:"name,omitempty"` + // Type - Resource type. + Type *string `json:"type,omitempty"` + // Tags - Resource tags. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for Balance. +func (b Balance) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if b.BalanceProperties != nil { + objectMap["properties"] = b.BalanceProperties + } + if b.ID != nil { + objectMap["id"] = b.ID + } + if b.Name != nil { + objectMap["name"] = b.Name + } + if b.Type != nil { + objectMap["type"] = b.Type + } + if b.Tags != nil { + objectMap["tags"] = b.Tags + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Balance struct. +func (b *Balance) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var balanceProperties BalanceProperties + err = json.Unmarshal(*v, &balanceProperties) + if err != nil { + return err + } + b.BalanceProperties = &balanceProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + b.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + b.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + b.Type = &typeVar + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + b.Tags = tags + } + } + } + + return nil +} + +// BalanceProperties the properties of the balance. +type BalanceProperties struct { + // Currency - The ISO currency in which the meter is charged, for example, USD. + Currency *string `json:"currency,omitempty"` + // BeginningBalance - The beginning balance for the billing period. + BeginningBalance *decimal.Decimal `json:"beginningBalance,omitempty"` + // EndingBalance - The ending balance for the billing period (for open periods this will be updated daily). + EndingBalance *decimal.Decimal `json:"endingBalance,omitempty"` + // NewPurchases - Total new purchase amount. + NewPurchases *decimal.Decimal `json:"newPurchases,omitempty"` + // Adjustments - Total adjustment amount. + Adjustments *decimal.Decimal `json:"adjustments,omitempty"` + // Utilized - Total Commitment usage. + Utilized *decimal.Decimal `json:"utilized,omitempty"` + // ServiceOverage - Overage for Azure services. + ServiceOverage *decimal.Decimal `json:"serviceOverage,omitempty"` + // ChargesBilledSeparately - Charges Billed separately. + ChargesBilledSeparately *decimal.Decimal `json:"chargesBilledSeparately,omitempty"` + // TotalOverage - serviceOverage + chargesBilledSeparately. + TotalOverage *decimal.Decimal `json:"totalOverage,omitempty"` + // TotalUsage - Azure service commitment + total Overage. + TotalUsage *decimal.Decimal `json:"totalUsage,omitempty"` + // AzureMarketplaceServiceCharges - Total charges for Azure Marketplace. + AzureMarketplaceServiceCharges *decimal.Decimal `json:"azureMarketplaceServiceCharges,omitempty"` + // BillingFrequency - The billing frequency. Possible values include: 'Month', 'Quarter', 'Year' + BillingFrequency BillingFrequency `json:"billingFrequency,omitempty"` + // PriceHidden - Price is hidden or not. + PriceHidden *bool `json:"priceHidden,omitempty"` + // NewPurchasesDetails - List of new purchases. + NewPurchasesDetails *[]BalancePropertiesNewPurchasesDetailsItem `json:"newPurchasesDetails,omitempty"` + // AdjustmentDetails - List of Adjustments (Promo credit, SIE credit etc.). + AdjustmentDetails *[]BalancePropertiesAdjustmentDetailsItem `json:"adjustmentDetails,omitempty"` +} + +// BalancePropertiesAdjustmentDetailsItem ... +type BalancePropertiesAdjustmentDetailsItem struct { + // Name - the name of new adjustment. + Name *string `json:"name,omitempty"` + // Value - the value of new adjustment. + Value *decimal.Decimal `json:"value,omitempty"` +} + +// BalancePropertiesNewPurchasesDetailsItem ... +type BalancePropertiesNewPurchasesDetailsItem struct { + // Name - the name of new purchase. + Name *string `json:"name,omitempty"` + // Value - the value of new purchase. + Value *decimal.Decimal `json:"value,omitempty"` +} + // Budget a budget resource. type Budget struct { autorest.Response `json:"-"` diff --git a/services/consumption/mgmt/2018-03-31/consumption/tags.go b/services/consumption/mgmt/2018-03-31/consumption/tags.go index 1e08ebe220f2..8289530e6925 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/tags.go +++ b/services/consumption/mgmt/2018-03-31/consumption/tags.go @@ -42,7 +42,7 @@ func NewTagsClientWithBaseURI(baseURI string, subscriptionID string) TagsClient // Get get all available tag keys for a billing account. // Parameters: -// billingAccountID - azure Billing Account ID. +// billingAccountID - billingAccount ID func (client TagsClient) Get(ctx context.Context, billingAccountID string) (result Tags, err error) { req, err := client.GetPreparer(ctx, billingAccountID) if err != nil { diff --git a/services/consumption/mgmt/2018-03-31/consumption/usagedetails.go b/services/consumption/mgmt/2018-03-31/consumption/usagedetails.go index 3a98a7791224..f1afc09a11c6 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/usagedetails.go +++ b/services/consumption/mgmt/2018-03-31/consumption/usagedetails.go @@ -41,8 +41,8 @@ func NewUsageDetailsClientWithBaseURI(baseURI string, subscriptionID string) Usa return UsageDetailsClient{NewWithBaseURI(baseURI, subscriptionID)} } -// List lists the usage details for a scope by billing period. Usage details are available via this API only for May 1, -// 2014 or later. +// List lists the usage details for a scope by current billing period. Usage details are available via this API only +// for May 1, 2014 or later. // Parameters: // expand - may be used to expand the properties/additionalProperties or properties/meterDetails within a list // of usage details. By default, these fields are not included when listing usage details. @@ -54,7 +54,7 @@ func NewUsageDetailsClientWithBaseURI(baseURI string, subscriptionID string) Usa // contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that // specifies a starting point to use for subsequent calls. // top - may be used to limit the number of results to the most recent N usageDetails. -// apply - oData apply expression to aggregatie usageDetails by tags or (tags and properties/usageStart) +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) func (client UsageDetailsClient) List(ctx context.Context, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultPage, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: top, @@ -178,7 +178,7 @@ func (client UsageDetailsClient) ListComplete(ctx context.Context, expand string // time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', // 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a key // value pair string where key and value is separated by a colon (:). -// apply - oData apply expression to aggregatie usageDetails by tags or (tags and properties/usageStart) for +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) for // specified billing period // skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response // contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that diff --git a/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbybillingaccount.go b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbybillingaccount.go new file mode 100644 index 000000000000..c04755baa916 --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbybillingaccount.go @@ -0,0 +1,302 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// UsageDetailsByBillingAccountClient is the consumption management client provides access to consumption resources for +// Azure Enterprise Subscriptions. +type UsageDetailsByBillingAccountClient struct { + BaseClient +} + +// NewUsageDetailsByBillingAccountClient creates an instance of the UsageDetailsByBillingAccountClient client. +func NewUsageDetailsByBillingAccountClient(subscriptionID string) UsageDetailsByBillingAccountClient { + return NewUsageDetailsByBillingAccountClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewUsageDetailsByBillingAccountClientWithBaseURI creates an instance of the UsageDetailsByBillingAccountClient +// client. +func NewUsageDetailsByBillingAccountClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsByBillingAccountClient { + return UsageDetailsByBillingAccountClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists the usage details by billingAccountId for a scope by current billing period. Usage details are available +// via this API only for May 1, 2014 or later. +// Parameters: +// billingAccountID - billingAccount ID +// expand - may be used to expand the properties/additionalProperties or properties/meterDetails within a list +// of usage details. By default, these fields are not included when listing usage details. +// filter - may be used to filter usageDetails by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName, properties/instanceId or tags. The filter supports +// 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a +// key value pair string where key and value is separated by a colon (:). +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +// top - may be used to limit the number of results to the most recent N usageDetails. +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) +func (client UsageDetailsByBillingAccountClient) List(ctx context.Context, billingAccountID string, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.UsageDetailsByBillingAccountClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, billingAccountID, expand, filter, skiptoken, top, apply) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.udlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "List", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client UsageDetailsByBillingAccountClient) ListPreparer(ctx context.Context, billingAccountID string, expand string, filter string, skiptoken string, top *int32, apply string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingAccountId": autorest.Encode("path", billingAccountID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/usageDetails", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client UsageDetailsByBillingAccountClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client UsageDetailsByBillingAccountClient) ListResponder(resp *http.Response) (result UsageDetailsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client UsageDetailsByBillingAccountClient) listNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsByBillingAccountClient) ListComplete(ctx context.Context, billingAccountID string, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.List(ctx, billingAccountID, expand, filter, skiptoken, top, apply) + return +} + +// ListByBillingPeriod lists the usage details based on billingAccountId for a scope by billing period. Usage details +// are available via this API only for May 1, 2014 or later. +// Parameters: +// billingAccountID - billingAccount ID +// billingPeriodName - billing Period Name. +// expand - may be used to expand the properties/additionalProperties or properties/meterDetails within a list +// of usage details. By default, these fields are not included when listing usage details. +// filter - may be used to filter usageDetails by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a key +// value pair string where key and value is separated by a colon (:). +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) for +// specified billing period +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +// top - may be used to limit the number of results to the most recent N usageDetails. +func (client UsageDetailsByBillingAccountClient) ListByBillingPeriod(ctx context.Context, billingAccountID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.UsageDetailsByBillingAccountClient", "ListByBillingPeriod", err.Error()) + } + + result.fn = client.listByBillingPeriodNextResults + req, err := client.ListByBillingPeriodPreparer(ctx, billingAccountID, billingPeriodName, expand, filter, apply, skiptoken, top) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "ListByBillingPeriod", nil, "Failure preparing request") + return + } + + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.udlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "ListByBillingPeriod", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "ListByBillingPeriod", resp, "Failure responding to request") + } + + return +} + +// ListByBillingPeriodPreparer prepares the ListByBillingPeriod request. +func (client UsageDetailsByBillingAccountClient) ListByBillingPeriodPreparer(ctx context.Context, billingAccountID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingAccountId": autorest.Encode("path", billingAccountID), + "billingPeriodName": autorest.Encode("path", billingPeriodName), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/usageDetails", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByBillingPeriodSender sends the ListByBillingPeriod request. The method will close the +// http.Response Body if it receives an error. +func (client UsageDetailsByBillingAccountClient) ListByBillingPeriodSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByBillingPeriodResponder handles the response to the ListByBillingPeriod request. The method always +// closes the http.Response Body. +func (client UsageDetailsByBillingAccountClient) ListByBillingPeriodResponder(resp *http.Response) (result UsageDetailsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByBillingPeriodNextResults retrieves the next set of results, if any. +func (client UsageDetailsByBillingAccountClient) listByBillingPeriodNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "listByBillingPeriodNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "listByBillingPeriodNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByBillingAccountClient", "listByBillingPeriodNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByBillingPeriodComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsByBillingAccountClient) ListByBillingPeriodComplete(ctx context.Context, billingAccountID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.ListByBillingPeriod(ctx, billingAccountID, billingPeriodName, expand, filter, apply, skiptoken, top) + return +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbydepartment.go b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbydepartment.go new file mode 100644 index 000000000000..205dbdecd23a --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbydepartment.go @@ -0,0 +1,301 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// UsageDetailsByDepartmentClient is the consumption management client provides access to consumption resources for +// Azure Enterprise Subscriptions. +type UsageDetailsByDepartmentClient struct { + BaseClient +} + +// NewUsageDetailsByDepartmentClient creates an instance of the UsageDetailsByDepartmentClient client. +func NewUsageDetailsByDepartmentClient(subscriptionID string) UsageDetailsByDepartmentClient { + return NewUsageDetailsByDepartmentClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewUsageDetailsByDepartmentClientWithBaseURI creates an instance of the UsageDetailsByDepartmentClient client. +func NewUsageDetailsByDepartmentClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsByDepartmentClient { + return UsageDetailsByDepartmentClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists the usage details by departmentId for a scope by current billing period. Usage details are available via +// this API only for May 1, 2014 or later. +// Parameters: +// departmentID - department ID +// expand - may be used to expand the properties/additionalProperties or properties/meterDetails within a list +// of usage details. By default, these fields are not included when listing usage details. +// filter - may be used to filter usageDetails by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName, properties/instanceId or tags. The filter supports +// 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a +// key value pair string where key and value is separated by a colon (:). +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +// top - may be used to limit the number of results to the most recent N usageDetails. +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) +func (client UsageDetailsByDepartmentClient) List(ctx context.Context, departmentID string, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.UsageDetailsByDepartmentClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, departmentID, expand, filter, skiptoken, top, apply) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.udlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "List", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client UsageDetailsByDepartmentClient) ListPreparer(ctx context.Context, departmentID string, expand string, filter string, skiptoken string, top *int32, apply string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "departmentId": autorest.Encode("path", departmentID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/departments/{departmentId}/providers/Microsoft.Consumption/usageDetails", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client UsageDetailsByDepartmentClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client UsageDetailsByDepartmentClient) ListResponder(resp *http.Response) (result UsageDetailsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client UsageDetailsByDepartmentClient) listNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsByDepartmentClient) ListComplete(ctx context.Context, departmentID string, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.List(ctx, departmentID, expand, filter, skiptoken, top, apply) + return +} + +// ListByBillingPeriod lists the usage details based on departmentId for a scope by billing period. Usage details are +// available via this API only for May 1, 2014 or later. +// Parameters: +// departmentID - department ID +// billingPeriodName - billing Period Name. +// expand - may be used to expand the properties/additionalProperties or properties/meterDetails within a list +// of usage details. By default, these fields are not included when listing usage details. +// filter - may be used to filter usageDetails by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a key +// value pair string where key and value is separated by a colon (:). +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) for +// specified billing period +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +// top - may be used to limit the number of results to the most recent N usageDetails. +func (client UsageDetailsByDepartmentClient) ListByBillingPeriod(ctx context.Context, departmentID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.UsageDetailsByDepartmentClient", "ListByBillingPeriod", err.Error()) + } + + result.fn = client.listByBillingPeriodNextResults + req, err := client.ListByBillingPeriodPreparer(ctx, departmentID, billingPeriodName, expand, filter, apply, skiptoken, top) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "ListByBillingPeriod", nil, "Failure preparing request") + return + } + + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.udlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "ListByBillingPeriod", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "ListByBillingPeriod", resp, "Failure responding to request") + } + + return +} + +// ListByBillingPeriodPreparer prepares the ListByBillingPeriod request. +func (client UsageDetailsByDepartmentClient) ListByBillingPeriodPreparer(ctx context.Context, departmentID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingPeriodName": autorest.Encode("path", billingPeriodName), + "departmentId": autorest.Encode("path", departmentID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/departments/{departmentId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/usageDetails", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByBillingPeriodSender sends the ListByBillingPeriod request. The method will close the +// http.Response Body if it receives an error. +func (client UsageDetailsByDepartmentClient) ListByBillingPeriodSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByBillingPeriodResponder handles the response to the ListByBillingPeriod request. The method always +// closes the http.Response Body. +func (client UsageDetailsByDepartmentClient) ListByBillingPeriodResponder(resp *http.Response) (result UsageDetailsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByBillingPeriodNextResults retrieves the next set of results, if any. +func (client UsageDetailsByDepartmentClient) listByBillingPeriodNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "listByBillingPeriodNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "listByBillingPeriodNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByDepartmentClient", "listByBillingPeriodNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByBillingPeriodComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsByDepartmentClient) ListByBillingPeriodComplete(ctx context.Context, departmentID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.ListByBillingPeriod(ctx, departmentID, billingPeriodName, expand, filter, apply, skiptoken, top) + return +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbyenrollmentaccount.go b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbyenrollmentaccount.go new file mode 100644 index 000000000000..26aef9a0795f --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbyenrollmentaccount.go @@ -0,0 +1,302 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/validation" + "net/http" +) + +// UsageDetailsByEnrollmentAccountClient is the consumption management client provides access to consumption resources +// for Azure Enterprise Subscriptions. +type UsageDetailsByEnrollmentAccountClient struct { + BaseClient +} + +// NewUsageDetailsByEnrollmentAccountClient creates an instance of the UsageDetailsByEnrollmentAccountClient client. +func NewUsageDetailsByEnrollmentAccountClient(subscriptionID string) UsageDetailsByEnrollmentAccountClient { + return NewUsageDetailsByEnrollmentAccountClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewUsageDetailsByEnrollmentAccountClientWithBaseURI creates an instance of the UsageDetailsByEnrollmentAccountClient +// client. +func NewUsageDetailsByEnrollmentAccountClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsByEnrollmentAccountClient { + return UsageDetailsByEnrollmentAccountClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists the usage details by enrollmentAccountId for a scope by current billing period. Usage details are +// available via this API only for May 1, 2014 or later. +// Parameters: +// enrollmentAccountID - enrollmentAccount ID +// expand - may be used to expand the properties/additionalProperties or properties/meterDetails within a list +// of usage details. By default, these fields are not included when listing usage details. +// filter - may be used to filter usageDetails by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName, properties/instanceId or tags. The filter supports +// 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a +// key value pair string where key and value is separated by a colon (:). +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +// top - may be used to limit the number of results to the most recent N usageDetails. +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) +func (client UsageDetailsByEnrollmentAccountClient) List(ctx context.Context, enrollmentAccountID string, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.UsageDetailsByEnrollmentAccountClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, enrollmentAccountID, expand, filter, skiptoken, top, apply) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.udlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "List", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client UsageDetailsByEnrollmentAccountClient) ListPreparer(ctx context.Context, enrollmentAccountID string, expand string, filter string, skiptoken string, top *int32, apply string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "enrollmentAccountId": autorest.Encode("path", enrollmentAccountID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/enrollmentAccounts/{enrollmentAccountId}/providers/Microsoft.Consumption/usageDetails", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client UsageDetailsByEnrollmentAccountClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client UsageDetailsByEnrollmentAccountClient) ListResponder(resp *http.Response) (result UsageDetailsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client UsageDetailsByEnrollmentAccountClient) listNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsByEnrollmentAccountClient) ListComplete(ctx context.Context, enrollmentAccountID string, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.List(ctx, enrollmentAccountID, expand, filter, skiptoken, top, apply) + return +} + +// ListByBillingPeriod lists the usage details based on enrollmentAccountId for a scope by billing period. Usage +// details are available via this API only for May 1, 2014 or later. +// Parameters: +// enrollmentAccountID - enrollmentAccount ID +// billingPeriodName - billing Period Name. +// expand - may be used to expand the properties/additionalProperties or properties/meterDetails within a list +// of usage details. By default, these fields are not included when listing usage details. +// filter - may be used to filter usageDetails by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a key +// value pair string where key and value is separated by a colon (:). +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) for +// specified billing period +// skiptoken - skiptoken is only used if a previous operation returned a partial result. If a previous response +// contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that +// specifies a starting point to use for subsequent calls. +// top - may be used to limit the number of results to the most recent N usageDetails. +func (client UsageDetailsByEnrollmentAccountClient) ListByBillingPeriod(ctx context.Context, enrollmentAccountID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultPage, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: top, + Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: 1000, Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.UsageDetailsByEnrollmentAccountClient", "ListByBillingPeriod", err.Error()) + } + + result.fn = client.listByBillingPeriodNextResults + req, err := client.ListByBillingPeriodPreparer(ctx, enrollmentAccountID, billingPeriodName, expand, filter, apply, skiptoken, top) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "ListByBillingPeriod", nil, "Failure preparing request") + return + } + + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.udlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "ListByBillingPeriod", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "ListByBillingPeriod", resp, "Failure responding to request") + } + + return +} + +// ListByBillingPeriodPreparer prepares the ListByBillingPeriod request. +func (client UsageDetailsByEnrollmentAccountClient) ListByBillingPeriodPreparer(ctx context.Context, enrollmentAccountID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingPeriodName": autorest.Encode("path", billingPeriodName), + "enrollmentAccountId": autorest.Encode("path", enrollmentAccountID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Billing/enrollmentAccounts/{enrollmentAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/usageDetails", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByBillingPeriodSender sends the ListByBillingPeriod request. The method will close the +// http.Response Body if it receives an error. +func (client UsageDetailsByEnrollmentAccountClient) ListByBillingPeriodSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByBillingPeriodResponder handles the response to the ListByBillingPeriod request. The method always +// closes the http.Response Body. +func (client UsageDetailsByEnrollmentAccountClient) ListByBillingPeriodResponder(resp *http.Response) (result UsageDetailsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByBillingPeriodNextResults retrieves the next set of results, if any. +func (client UsageDetailsByEnrollmentAccountClient) listByBillingPeriodNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "listByBillingPeriodNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByBillingPeriodSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "listByBillingPeriodNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByBillingPeriodResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsByEnrollmentAccountClient", "listByBillingPeriodNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByBillingPeriodComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsByEnrollmentAccountClient) ListByBillingPeriodComplete(ctx context.Context, enrollmentAccountID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.ListByBillingPeriod(ctx, enrollmentAccountID, billingPeriodName, expand, filter, apply, skiptoken, top) + return +} diff --git a/services/consumption/mgmt/2018-05-31/consumption/client.go b/services/consumption/mgmt/2018-05-31/consumption/client.go new file mode 100644 index 000000000000..1bd8c604a8f5 --- /dev/null +++ b/services/consumption/mgmt/2018-05-31/consumption/client.go @@ -0,0 +1,51 @@ +// Package consumption implements the Azure ARM Consumption service API version 2018-05-31. +// +// Consumption management client provides access to consumption resources for Azure Enterprise Subscriptions. +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "github.com/Azure/go-autorest/autorest" +) + +const ( + // DefaultBaseURI is the default URI used for the service Consumption + DefaultBaseURI = "https://management.azure.com" +) + +// BaseClient is the base client for Consumption. +type BaseClient struct { + autorest.Client + BaseURI string + SubscriptionID string +} + +// New creates an instance of the BaseClient client. +func New(subscriptionID string) BaseClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewWithBaseURI creates an instance of the BaseClient client. +func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID: subscriptionID, + } +} diff --git a/services/consumption/mgmt/2018-05-31/consumption/forecasts.go b/services/consumption/mgmt/2018-05-31/consumption/forecasts.go new file mode 100644 index 000000000000..1f3303f0cf37 --- /dev/null +++ b/services/consumption/mgmt/2018-05-31/consumption/forecasts.go @@ -0,0 +1,110 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// ForecastsClient is the consumption management client provides access to consumption resources for Azure Enterprise +// Subscriptions. +type ForecastsClient struct { + BaseClient +} + +// NewForecastsClient creates an instance of the ForecastsClient client. +func NewForecastsClient(subscriptionID string) ForecastsClient { + return NewForecastsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewForecastsClientWithBaseURI creates an instance of the ForecastsClient client. +func NewForecastsClientWithBaseURI(baseURI string, subscriptionID string) ForecastsClient { + return ForecastsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists the forecast charges by subscriptionId. +// Parameters: +// filter - may be used to filter forecasts by properties/usageDate (Utc time), properties/chargeType or +// properties/grain. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support +// 'ne', 'or', or 'not'. +func (client ForecastsClient) List(ctx context.Context, filter string) (result ForecastsListResult, err error) { + req, err := client.ListPreparer(ctx, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.ForecastsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.ForecastsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.ForecastsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client ForecastsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-05-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/forecasts", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client ForecastsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ForecastsClient) ListResponder(resp *http.Response) (result ForecastsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/consumption/mgmt/2018-05-31/consumption/models.go b/services/consumption/mgmt/2018-05-31/consumption/models.go new file mode 100644 index 000000000000..9b5909d7c724 --- /dev/null +++ b/services/consumption/mgmt/2018-05-31/consumption/models.go @@ -0,0 +1,366 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "encoding/json" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/to" + "github.com/shopspring/decimal" + "net/http" +) + +// Bound enumerates the values for bound. +type Bound string + +const ( + // Lower ... + Lower Bound = "Lower" + // Upper ... + Upper Bound = "Upper" +) + +// PossibleBoundValues returns an array of possible values for the Bound const type. +func PossibleBoundValues() []Bound { + return []Bound{Lower, Upper} +} + +// ChargeType enumerates the values for charge type. +type ChargeType string + +const ( + // ChargeTypeActual ... + ChargeTypeActual ChargeType = "Actual" + // ChargeTypeForecast ... + ChargeTypeForecast ChargeType = "Forecast" +) + +// PossibleChargeTypeValues returns an array of possible values for the ChargeType const type. +func PossibleChargeTypeValues() []ChargeType { + return []ChargeType{ChargeTypeActual, ChargeTypeForecast} +} + +// Grain enumerates the values for grain. +type Grain string + +const ( + // Daily ... + Daily Grain = "Daily" + // Monthly ... + Monthly Grain = "Monthly" + // Yearly ... + Yearly Grain = "Yearly" +) + +// PossibleGrainValues returns an array of possible values for the Grain const type. +func PossibleGrainValues() []Grain { + return []Grain{Daily, Monthly, Yearly} +} + +// ErrorDetails the details of the error. +type ErrorDetails struct { + // Code - Error code. + Code *string `json:"code,omitempty"` + // Message - Error message indicating why the operation failed. + Message *string `json:"message,omitempty"` +} + +// ErrorResponse error response indicates that the service is not able to process the incoming request. The reason +// is provided in the error message. +type ErrorResponse struct { + // Error - The details of the error. + Error *ErrorDetails `json:"error,omitempty"` +} + +// Forecast a forecast resource. +type Forecast struct { + *ForecastProperties `json:"properties,omitempty"` + // ID - Resource Id. + ID *string `json:"id,omitempty"` + // Name - Resource name. + Name *string `json:"name,omitempty"` + // Type - Resource type. + Type *string `json:"type,omitempty"` + // Tags - Resource tags. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for Forecast. +func (f Forecast) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if f.ForecastProperties != nil { + objectMap["properties"] = f.ForecastProperties + } + if f.ID != nil { + objectMap["id"] = f.ID + } + if f.Name != nil { + objectMap["name"] = f.Name + } + if f.Type != nil { + objectMap["type"] = f.Type + } + if f.Tags != nil { + objectMap["tags"] = f.Tags + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Forecast struct. +func (f *Forecast) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var forecastProperties ForecastProperties + err = json.Unmarshal(*v, &forecastProperties) + if err != nil { + return err + } + f.ForecastProperties = &forecastProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + f.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + f.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + f.Type = &typeVar + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + f.Tags = tags + } + } + } + + return nil +} + +// ForecastProperties the properties of the forecast charge. +type ForecastProperties struct { + // UsageDate - The usage date of the forecast. + UsageDate *string `json:"usageDate,omitempty"` + // Grain - The granularity of forecast. Possible values include: 'Daily', 'Monthly', 'Yearly' + Grain Grain `json:"grain,omitempty"` + // Charge - The amount of charge + Charge *decimal.Decimal `json:"charge,omitempty"` + // Currency - The ISO currency in which the meter is charged, for example, USD. + Currency *string `json:"currency,omitempty"` + // ChargeType - The type of the charge. Could be actual or forecast. Possible values include: 'ChargeTypeActual', 'ChargeTypeForecast' + ChargeType ChargeType `json:"chargeType,omitempty"` + // ConfidenceLevels - The details about the forecast confidence levels. This is populated only when chargeType is Forecast. + ConfidenceLevels *[]ForecastPropertiesConfidenceLevelsItem `json:"confidenceLevels,omitempty"` +} + +// ForecastPropertiesConfidenceLevelsItem ... +type ForecastPropertiesConfidenceLevelsItem struct { + // Percentage - The percentage level of the confidence + Percentage *decimal.Decimal `json:"percentage,omitempty"` + // Bound - The boundary of the percentage, values could be 'Upper' or 'Lower'. Possible values include: 'Upper', 'Lower' + Bound Bound `json:"bound,omitempty"` + // Value - The amount of forecast within the percentage level + Value *decimal.Decimal `json:"value,omitempty"` +} + +// ForecastsListResult result of listing forecasts. It contains a list of available forecasts. +type ForecastsListResult struct { + autorest.Response `json:"-"` + // Value - The list of forecasts. + Value *[]Forecast `json:"value,omitempty"` +} + +// Operation a Consumption REST API operation. +type Operation struct { + // Name - Operation name: {provider}/{resource}/{operation}. + Name *string `json:"name,omitempty"` + // Display - The object that represents the operation. + Display *OperationDisplay `json:"display,omitempty"` +} + +// OperationDisplay the object that represents the operation. +type OperationDisplay struct { + // Provider - Service provider: Microsoft.Consumption. + Provider *string `json:"provider,omitempty"` + // Resource - Resource on which the operation is performed: UsageDetail, etc. + Resource *string `json:"resource,omitempty"` + // Operation - Operation type: Read, write, delete, etc. + Operation *string `json:"operation,omitempty"` +} + +// OperationListResult result of listing consumption operations. It contains a list of operations and a URL link to +// get the next set of results. +type OperationListResult struct { + autorest.Response `json:"-"` + // Value - List of consumption operations supported by the Microsoft.Consumption resource provider. + Value *[]Operation `json:"value,omitempty"` + // NextLink - URL to get the next set of operation list results if there are any. + NextLink *string `json:"nextLink,omitempty"` +} + +// OperationListResultIterator provides access to a complete listing of Operation values. +type OperationListResultIterator struct { + i int + page OperationListResultPage +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *OperationListResultIterator) Next() error { + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err := iter.page.Next() + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter OperationListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter OperationListResultIterator) Response() OperationListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter OperationListResultIterator) Value() Operation { + if !iter.page.NotDone() { + return Operation{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (olr OperationListResult) IsEmpty() bool { + return olr.Value == nil || len(*olr.Value) == 0 +} + +// operationListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (olr OperationListResult) operationListResultPreparer() (*http.Request, error) { + if olr.NextLink == nil || len(to.String(olr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(olr.NextLink))) +} + +// OperationListResultPage contains a page of Operation values. +type OperationListResultPage struct { + fn func(OperationListResult) (OperationListResult, error) + olr OperationListResult +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *OperationListResultPage) Next() error { + next, err := page.fn(page.olr) + if err != nil { + return err + } + page.olr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page OperationListResultPage) NotDone() bool { + return !page.olr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page OperationListResultPage) Response() OperationListResult { + return page.olr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page OperationListResultPage) Values() []Operation { + if page.olr.IsEmpty() { + return nil + } + return *page.olr.Value +} + +// Resource the Resource model definition. +type Resource struct { + // ID - Resource Id. + ID *string `json:"id,omitempty"` + // Name - Resource name. + Name *string `json:"name,omitempty"` + // Type - Resource type. + Type *string `json:"type,omitempty"` + // Tags - Resource tags. + Tags map[string]*string `json:"tags"` +} + +// MarshalJSON is the custom marshaler for Resource. +func (r Resource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if r.ID != nil { + objectMap["id"] = r.ID + } + if r.Name != nil { + objectMap["name"] = r.Name + } + if r.Type != nil { + objectMap["type"] = r.Type + } + if r.Tags != nil { + objectMap["tags"] = r.Tags + } + return json.Marshal(objectMap) +} diff --git a/services/consumption/mgmt/2018-05-31/consumption/operations.go b/services/consumption/mgmt/2018-05-31/consumption/operations.go new file mode 100644 index 000000000000..c615723fe112 --- /dev/null +++ b/services/consumption/mgmt/2018-05-31/consumption/operations.go @@ -0,0 +1,127 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// OperationsClient is the consumption management client provides access to consumption resources for Azure Enterprise +// Subscriptions. +type OperationsClient struct { + BaseClient +} + +// NewOperationsClient creates an instance of the OperationsClient client. +func NewOperationsClient(subscriptionID string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client. +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists all of the available consumption REST API operations. +func (client OperationsClient) List(ctx context.Context) (result OperationListResultPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.OperationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.olr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.OperationsClient", "List", resp, "Failure sending request") + return + } + + result.olr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.OperationsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + const APIVersion = "2018-05-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPath("/providers/Microsoft.Consumption/operations"), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client OperationsClient) listNextResults(lastResults OperationListResult) (result OperationListResult, err error) { + req, err := lastResults.operationListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.OperationsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.OperationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.OperationsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client OperationsClient) ListComplete(ctx context.Context) (result OperationListResultIterator, err error) { + result.page, err = client.List(ctx) + return +} diff --git a/services/consumption/mgmt/2018-05-31/consumption/version.go b/services/consumption/mgmt/2018-05-31/consumption/version.go new file mode 100644 index 000000000000..33df0efd909d --- /dev/null +++ b/services/consumption/mgmt/2018-05-31/consumption/version.go @@ -0,0 +1,30 @@ +package consumption + +import "github.com/Azure/azure-sdk-for-go/version" + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +// UserAgent returns the UserAgent string to use when sending http.Requests. +func UserAgent() string { + return "Azure-SDK-For-Go/" + version.Number + " consumption/2018-05-31" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +}