diff --git a/profiles/preview/consumption/mgmt/consumption/models.go b/profiles/preview/consumption/mgmt/consumption/models.go index 8ebf23e92c2f..44d31b948cee 100644 --- a/profiles/preview/consumption/mgmt/consumption/models.go +++ b/profiles/preview/consumption/mgmt/consumption/models.go @@ -29,7 +29,19 @@ const ( type BaseClient = original.BaseClient type CostTagsClient = original.CostTagsClient +type GetBalancesByBillingAccountClient = original.GetBalancesByBillingAccountClient type MarketplacesClient = original.MarketplacesClient +type MarketplacesByBillingAccountClient = original.MarketplacesByBillingAccountClient +type MarketplacesByDepartmentClient = original.MarketplacesByDepartmentClient +type MarketplacesByEnrollmentAccountsClient = original.MarketplacesByEnrollmentAccountsClient +type BillingFrequency = original.BillingFrequency + +const ( + Month BillingFrequency = original.Month + Quarter BillingFrequency = original.Quarter + Year BillingFrequency = original.Year +) + type CategoryType = original.CategoryType const ( @@ -60,6 +72,10 @@ const ( Quarterly TimeGrainType = original.Quarterly ) +type Balance = original.Balance +type BalanceProperties = original.BalanceProperties +type BalancePropertiesAdjustmentDetailsItem = original.BalancePropertiesAdjustmentDetailsItem +type BalancePropertiesNewPurchasesDetailsItem = original.BalancePropertiesNewPurchasesDetailsItem type Budget = original.Budget type BudgetProperties = original.BudgetProperties type BudgetsListResult = original.BudgetsListResult @@ -121,6 +137,9 @@ type ReservationsDetailsClient = original.ReservationsDetailsClient type ReservationsSummariesClient = original.ReservationsSummariesClient type TagsClient = original.TagsClient type UsageDetailsClient = original.UsageDetailsClient +type UsageDetailsByBillingAccountClient = original.UsageDetailsByBillingAccountClient +type UsageDetailsByDepartmentClient = original.UsageDetailsByDepartmentClient +type UsageDetailsByEnrollmentAccountClient = original.UsageDetailsByEnrollmentAccountClient func NewBudgetsClient(subscriptionID string) BudgetsClient { return original.NewBudgetsClient(subscriptionID) @@ -140,12 +159,39 @@ func NewCostTagsClient(subscriptionID string) CostTagsClient { func NewCostTagsClientWithBaseURI(baseURI string, subscriptionID string) CostTagsClient { return original.NewCostTagsClientWithBaseURI(baseURI, subscriptionID) } +func NewGetBalancesByBillingAccountClient(subscriptionID string) GetBalancesByBillingAccountClient { + return original.NewGetBalancesByBillingAccountClient(subscriptionID) +} +func NewGetBalancesByBillingAccountClientWithBaseURI(baseURI string, subscriptionID string) GetBalancesByBillingAccountClient { + return original.NewGetBalancesByBillingAccountClientWithBaseURI(baseURI, subscriptionID) +} func NewMarketplacesClient(subscriptionID string) MarketplacesClient { return original.NewMarketplacesClient(subscriptionID) } func NewMarketplacesClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesClient { return original.NewMarketplacesClientWithBaseURI(baseURI, subscriptionID) } +func NewMarketplacesByBillingAccountClient(subscriptionID string) MarketplacesByBillingAccountClient { + return original.NewMarketplacesByBillingAccountClient(subscriptionID) +} +func NewMarketplacesByBillingAccountClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesByBillingAccountClient { + return original.NewMarketplacesByBillingAccountClientWithBaseURI(baseURI, subscriptionID) +} +func NewMarketplacesByDepartmentClient(subscriptionID string) MarketplacesByDepartmentClient { + return original.NewMarketplacesByDepartmentClient(subscriptionID) +} +func NewMarketplacesByDepartmentClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesByDepartmentClient { + return original.NewMarketplacesByDepartmentClientWithBaseURI(baseURI, subscriptionID) +} +func NewMarketplacesByEnrollmentAccountsClient(subscriptionID string) MarketplacesByEnrollmentAccountsClient { + return original.NewMarketplacesByEnrollmentAccountsClient(subscriptionID) +} +func NewMarketplacesByEnrollmentAccountsClientWithBaseURI(baseURI string, subscriptionID string) MarketplacesByEnrollmentAccountsClient { + return original.NewMarketplacesByEnrollmentAccountsClientWithBaseURI(baseURI, subscriptionID) +} +func PossibleBillingFrequencyValues() []BillingFrequency { + return original.PossibleBillingFrequencyValues() +} func PossibleCategoryTypeValues() []CategoryType { return original.PossibleCategoryTypeValues() } @@ -200,6 +246,24 @@ func NewUsageDetailsClient(subscriptionID string) UsageDetailsClient { func NewUsageDetailsClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsClient { return original.NewUsageDetailsClientWithBaseURI(baseURI, subscriptionID) } +func NewUsageDetailsByBillingAccountClient(subscriptionID string) UsageDetailsByBillingAccountClient { + return original.NewUsageDetailsByBillingAccountClient(subscriptionID) +} +func NewUsageDetailsByBillingAccountClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsByBillingAccountClient { + return original.NewUsageDetailsByBillingAccountClientWithBaseURI(baseURI, subscriptionID) +} +func NewUsageDetailsByDepartmentClient(subscriptionID string) UsageDetailsByDepartmentClient { + return original.NewUsageDetailsByDepartmentClient(subscriptionID) +} +func NewUsageDetailsByDepartmentClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsByDepartmentClient { + return original.NewUsageDetailsByDepartmentClientWithBaseURI(baseURI, subscriptionID) +} +func NewUsageDetailsByEnrollmentAccountClient(subscriptionID string) UsageDetailsByEnrollmentAccountClient { + return original.NewUsageDetailsByEnrollmentAccountClient(subscriptionID) +} +func NewUsageDetailsByEnrollmentAccountClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsByEnrollmentAccountClient { + return original.NewUsageDetailsByEnrollmentAccountClientWithBaseURI(baseURI, subscriptionID) +} func UserAgent() string { return original.UserAgent() + " profiles/preview" } diff --git a/profiles/preview/preview/consumption/mgmt/consumption/models.go b/profiles/preview/preview/consumption/mgmt/consumption/models.go new file mode 100644 index 000000000000..22abd92da3c2 --- /dev/null +++ b/profiles/preview/preview/consumption/mgmt/consumption/models.go @@ -0,0 +1,92 @@ +// +build go1.9 + +// Copyright 2018 Microsoft Corporation +// +// 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. + +// This code was auto-generated by: +// github.com/Azure/azure-sdk-for-go/tools/profileBuilder + +package consumption + +import original "github.com/Azure/azure-sdk-for-go/services/preview/consumption/mgmt/2017-12-30-preview/consumption" + +type BudgetsClient = original.BudgetsClient + +const ( + DefaultBaseURI = original.DefaultBaseURI +) + +type BaseClient = original.BaseClient +type OperatorType = original.OperatorType + +const ( + EqualTo OperatorType = original.EqualTo + GreaterThan OperatorType = original.GreaterThan + GreaterThanOrEqualTo OperatorType = original.GreaterThanOrEqualTo +) + +type TimeGrainType = original.TimeGrainType + +const ( + Annually TimeGrainType = original.Annually + Monthly TimeGrainType = original.Monthly + Quarterly TimeGrainType = original.Quarterly +) + +type Budget = original.Budget +type BudgetProperties = original.BudgetProperties +type BudgetsListResult = original.BudgetsListResult +type BudgetTimePeriod = original.BudgetTimePeriod +type CurrentSpend = original.CurrentSpend +type ErrorDetails = original.ErrorDetails +type ErrorResponse = original.ErrorResponse +type Notification = original.Notification +type Operation = original.Operation +type OperationDisplay = original.OperationDisplay +type OperationListResult = original.OperationListResult +type OperationListResultIterator = original.OperationListResultIterator +type OperationListResultPage = original.OperationListResultPage +type ProxyResource = original.ProxyResource +type OperationsClient = original.OperationsClient + +func NewBudgetsClient(subscriptionID string, name string) BudgetsClient { + return original.NewBudgetsClient(subscriptionID, name) +} +func NewBudgetsClientWithBaseURI(baseURI string, subscriptionID string, name string) BudgetsClient { + return original.NewBudgetsClientWithBaseURI(baseURI, subscriptionID, name) +} +func New(subscriptionID string, name string) BaseClient { + return original.New(subscriptionID, name) +} +func NewWithBaseURI(baseURI string, subscriptionID string, name string) BaseClient { + return original.NewWithBaseURI(baseURI, subscriptionID, name) +} +func PossibleOperatorTypeValues() []OperatorType { + return original.PossibleOperatorTypeValues() +} +func PossibleTimeGrainTypeValues() []TimeGrainType { + return original.PossibleTimeGrainTypeValues() +} +func NewOperationsClient(subscriptionID string, name string) OperationsClient { + return original.NewOperationsClient(subscriptionID, name) +} +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string, name string) OperationsClient { + return original.NewOperationsClientWithBaseURI(baseURI, subscriptionID, name) +} +func UserAgent() string { + return original.UserAgent() + " profiles/preview" +} +func Version() string { + return original.Version() +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/client.go b/services/consumption/mgmt/2018-03-31/consumption/client.go index 8fdda610a9f5..516be563f9f3 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. +// +// billingAccountID is 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 25a5a49397b6..d7539bf8fd4b 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/costtags.go +++ b/services/consumption/mgmt/2018-03-31/consumption/costtags.go @@ -44,8 +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. // -// billingAccountID is azure Billing Account ID. parameters is parameters supplied to the Create cost tags -// operation. +// billingAccountID is billingAccount ID parameters is 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) if err != nil { @@ -83,7 +82,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 +110,7 @@ func (client CostTagsClient) CreateOrUpdateResponder(resp *http.Response) (resul // Get get cost tags for a billing account. // -// billingAccountID is azure Billing Account ID. +// billingAccountID is 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 +147,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..1273590cd8ca --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/getbalancesbybillingaccount.go @@ -0,0 +1,107 @@ +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. +// +// billingAccountID is billingAccount ID billingPeriodName is 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 e6691954ac3e..5e820d331f95 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. // // filter is 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..7fa89b23b077 --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbybillingaccount.go @@ -0,0 +1,278 @@ +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. +// +// billingAccountID is billingAccount ID filter is 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 is may be used to limit the number of results to the most recent N +// marketplaces. skiptoken is 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. +// +// billingAccountID is billingAccount ID billingPeriodName is billing Period Name. filter is 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 is may be used to limit the number of results to the +// most recent N marketplaces. skiptoken is 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..4c4a707374a7 --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbydepartment.go @@ -0,0 +1,277 @@ +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. +// +// departmentID is department ID filter is 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 is may be used to limit the number of results to the most recent N marketplaces. skiptoken is 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. +// +// departmentID is department ID billingPeriodName is billing Period Name. filter is 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 is may be used to limit the number of results to the +// most recent N marketplaces. skiptoken is 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..6925cc8d448c --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/marketplacesbyenrollmentaccounts.go @@ -0,0 +1,278 @@ +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. +// +// enrollmentAccountID is enrollmentAccount ID filter is 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 is may be used to limit the number of results to the most recent N +// marketplaces. skiptoken is 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. +// +// enrollmentAccountID is enrollmentAccount ID billingPeriodName is billing Period Name. filter is 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 is may be used to limit the +// number of results to the most recent N marketplaces. skiptoken is 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 f596521984f0..be0eecf33a9c 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. // -// billingAccountID is azure Billing Account ID. +// billingAccountID is 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 ebfb7ffdbec5..db420052e7b8 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. // // expand is 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 is may be used to @@ -53,7 +53,7 @@ func NewUsageDetailsClientWithBaseURI(baseURI string, subscriptionID string) Usa // 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 is may be used to limit the number of results to the most recent N usageDetails. apply is oData apply -// expression to aggregatie usageDetails by tags or (tags and properties/usageStart) +// 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, @@ -176,7 +176,7 @@ func (client UsageDetailsClient) ListComplete(ctx context.Context, expand string // 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 is oData apply -// expression to aggregatie usageDetails by tags or (tags and properties/usageStart) for specified billing period +// expression to aggregate usageDetails by tags or (tags and properties/usageStart) for specified billing period // skiptoken is 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 is may be used to limit the number of results to the most 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..8f774a0196ae --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbybillingaccount.go @@ -0,0 +1,298 @@ +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. +// +// billingAccountID is billingAccount ID expand is 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 is 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 is +// 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 is may be used to limit the number of results to the most recent N +// usageDetails. apply is 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. +// +// billingAccountID is billingAccount ID billingPeriodName is billing Period Name. expand is 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 is 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 is oData apply expression to aggregate usageDetails by tags or (tags and +// properties/usageStart) for specified billing period skiptoken is 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 is 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..ea9e261d0395 --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbydepartment.go @@ -0,0 +1,297 @@ +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. +// +// departmentID is department ID expand is 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 is 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 is +// 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 is may be used to limit the number of results to the most recent N +// usageDetails. apply is 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. +// +// departmentID is department ID billingPeriodName is billing Period Name. expand is 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 is 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 is oData apply expression to aggregate usageDetails by tags or (tags and +// properties/usageStart) for specified billing period skiptoken is 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 is 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..ffd71a6023d4 --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/usagedetailsbyenrollmentaccount.go @@ -0,0 +1,298 @@ +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. +// +// enrollmentAccountID is enrollmentAccount ID expand is 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 is 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 is +// 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 is may be used to limit the number of results to the most recent N +// usageDetails. apply is 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. +// +// enrollmentAccountID is enrollmentAccount ID billingPeriodName is billing Period Name. expand is 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 is 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 is oData apply expression to aggregate usageDetails by tags or (tags and +// properties/usageStart) for specified billing period skiptoken is 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 is 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/preview/consumption/mgmt/2017-04-24-preview/consumption/client.go b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/client.go new file mode 100644 index 000000000000..849987da08d6 --- /dev/null +++ b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/client.go @@ -0,0 +1,53 @@ +// Package consumption implements the Azure ARM Consumption service API version 2017-04-24-preview. +// +// Consumption management client provides access to consumption resources for Azure Web-Direct subscriptions. Other +// subscription types which were not purchased directly through the Azure web portal are not supported through this +// preview API. +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/preview/consumption/mgmt/2017-04-24-preview/consumption/models.go b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/models.go new file mode 100644 index 000000000000..a57b0eb426f2 --- /dev/null +++ b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/models.go @@ -0,0 +1,495 @@ +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/date" + "github.com/Azure/go-autorest/autorest/to" + "github.com/shopspring/decimal" + "net/http" +) + +// 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"` + // Target - The target of the particular error. + Target *string `json:"target,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"` +} + +// MeterDetails the properties of the meter detail. +type MeterDetails struct { + // MeterName - The name of the meter, within the given meter category + MeterName *string `json:"meterName,omitempty"` + // MeterCategory - The category of the meter, for example, 'Cloud services', 'Networking', etc.. + MeterCategory *string `json:"meterCategory,omitempty"` + // MeterSubCategory - The subcategory of the meter, for example, 'A6 Cloud services', 'ExpressRoute (IXP)', etc.. + MeterSubCategory *string `json:"meterSubCategory,omitempty"` + // Unit - The unit in which the meter consumption is charged, for example, 'Hours', 'GB', etc. + Unit *string `json:"unit,omitempty"` + // MeterLocation - The location in which the Azure service is available. + MeterLocation *string `json:"meterLocation,omitempty"` + // TotalIncludedQuantity - The total included quantity associated with the offer. + TotalIncludedQuantity *decimal.Decimal `json:"totalIncludedQuantity,omitempty"` + // PretaxStandardRate - The pretax listing price. + PretaxStandardRate *decimal.Decimal `json:"pretaxStandardRate,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) +} + +// UsageDetail an usage detail resource. +type UsageDetail struct { + *UsageDetailProperties `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 UsageDetail. +func (ud UsageDetail) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if ud.UsageDetailProperties != nil { + objectMap["properties"] = ud.UsageDetailProperties + } + if ud.ID != nil { + objectMap["id"] = ud.ID + } + if ud.Name != nil { + objectMap["name"] = ud.Name + } + if ud.Type != nil { + objectMap["type"] = ud.Type + } + if ud.Tags != nil { + objectMap["tags"] = ud.Tags + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for UsageDetail struct. +func (ud *UsageDetail) 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 usageDetailProperties UsageDetailProperties + err = json.Unmarshal(*v, &usageDetailProperties) + if err != nil { + return err + } + ud.UsageDetailProperties = &usageDetailProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + ud.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + ud.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + ud.Type = &typeVar + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + ud.Tags = tags + } + } + } + + return nil +} + +// UsageDetailProperties the properties of the usage detail. +type UsageDetailProperties struct { + // BillingPeriodID - The id of the billing period resource that the usage belongs to. + BillingPeriodID *string `json:"billingPeriodId,omitempty"` + // InvoiceID - The id of the invoice resource that the usage belongs to. + InvoiceID *string `json:"invoiceId,omitempty"` + // UsageStart - The start of the date time range covered by the usage detail. + UsageStart *date.Time `json:"usageStart,omitempty"` + // UsageEnd - The end of the date time range covered by the usage detail. + UsageEnd *date.Time `json:"usageEnd,omitempty"` + // InstanceName - The name of the resource instance that the usage is about. + InstanceName *string `json:"instanceName,omitempty"` + // InstanceID - The uri of the resource instance that the usage is about. + InstanceID *string `json:"instanceId,omitempty"` + // InstanceLocation - The location of the resource instance that the usage is about. + InstanceLocation *string `json:"instanceLocation,omitempty"` + // Currency - The ISO currency in which the meter is charged, for example, USD. + Currency *string `json:"currency,omitempty"` + // UsageQuantity - The quantity of usage. + UsageQuantity *decimal.Decimal `json:"usageQuantity,omitempty"` + // BillableQuantity - The billable usage quantity. + BillableQuantity *decimal.Decimal `json:"billableQuantity,omitempty"` + // PretaxCost - The amount of cost before tax. + PretaxCost *decimal.Decimal `json:"pretaxCost,omitempty"` + // IsEstimated - The estimated usage is subject to change. + IsEstimated *bool `json:"isEstimated,omitempty"` + // MeterID - The meter id. + MeterID *string `json:"meterId,omitempty"` + // MeterDetails - The details about the meter. By default this is not populated, unless it's specified in $expand. + MeterDetails *MeterDetails `json:"meterDetails,omitempty"` + // AdditionalProperties - The list of key/value pairs for the additional properties, in the format 'key':'value' where key = the field name, and value = the field value. By default this is not populated, unless it's specified in $expand. + AdditionalProperties map[string]*string `json:"additionalProperties"` +} + +// MarshalJSON is the custom marshaler for UsageDetailProperties. +func (UDP UsageDetailProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if UDP.BillingPeriodID != nil { + objectMap["billingPeriodId"] = UDP.BillingPeriodID + } + if UDP.InvoiceID != nil { + objectMap["invoiceId"] = UDP.InvoiceID + } + if UDP.UsageStart != nil { + objectMap["usageStart"] = UDP.UsageStart + } + if UDP.UsageEnd != nil { + objectMap["usageEnd"] = UDP.UsageEnd + } + if UDP.InstanceName != nil { + objectMap["instanceName"] = UDP.InstanceName + } + if UDP.InstanceID != nil { + objectMap["instanceId"] = UDP.InstanceID + } + if UDP.InstanceLocation != nil { + objectMap["instanceLocation"] = UDP.InstanceLocation + } + if UDP.Currency != nil { + objectMap["currency"] = UDP.Currency + } + if UDP.UsageQuantity != nil { + objectMap["usageQuantity"] = UDP.UsageQuantity + } + if UDP.BillableQuantity != nil { + objectMap["billableQuantity"] = UDP.BillableQuantity + } + if UDP.PretaxCost != nil { + objectMap["pretaxCost"] = UDP.PretaxCost + } + if UDP.IsEstimated != nil { + objectMap["isEstimated"] = UDP.IsEstimated + } + if UDP.MeterID != nil { + objectMap["meterId"] = UDP.MeterID + } + if UDP.MeterDetails != nil { + objectMap["meterDetails"] = UDP.MeterDetails + } + if UDP.AdditionalProperties != nil { + objectMap["additionalProperties"] = UDP.AdditionalProperties + } + return json.Marshal(objectMap) +} + +// UsageDetailsListResult result of listing usage details. It contains a list of available usage details in reverse +// chronological order by billing period. +type UsageDetailsListResult struct { + autorest.Response `json:"-"` + // Value - The list of usage details. + Value *[]UsageDetail `json:"value,omitempty"` + // NextLink - The link (url) to the next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// UsageDetailsListResultIterator provides access to a complete listing of UsageDetail values. +type UsageDetailsListResultIterator struct { + i int + page UsageDetailsListResultPage +} + +// 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 *UsageDetailsListResultIterator) 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 UsageDetailsListResultIterator) 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 UsageDetailsListResultIterator) Response() UsageDetailsListResult { + 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 UsageDetailsListResultIterator) Value() UsageDetail { + if !iter.page.NotDone() { + return UsageDetail{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (udlr UsageDetailsListResult) IsEmpty() bool { + return udlr.Value == nil || len(*udlr.Value) == 0 +} + +// usageDetailsListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (udlr UsageDetailsListResult) usageDetailsListResultPreparer() (*http.Request, error) { + if udlr.NextLink == nil || len(to.String(udlr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(udlr.NextLink))) +} + +// UsageDetailsListResultPage contains a page of UsageDetail values. +type UsageDetailsListResultPage struct { + fn func(UsageDetailsListResult) (UsageDetailsListResult, error) + udlr UsageDetailsListResult +} + +// 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 *UsageDetailsListResultPage) Next() error { + next, err := page.fn(page.udlr) + if err != nil { + return err + } + page.udlr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page UsageDetailsListResultPage) NotDone() bool { + return !page.udlr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page UsageDetailsListResultPage) Response() UsageDetailsListResult { + return page.udlr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page UsageDetailsListResultPage) Values() []UsageDetail { + if page.udlr.IsEmpty() { + return nil + } + return *page.udlr.Value +} diff --git a/services/preview/consumption/mgmt/2017-04-24-preview/consumption/operations.go b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/operations.go new file mode 100644 index 000000000000..5ed8be73fc11 --- /dev/null +++ b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/operations.go @@ -0,0 +1,128 @@ +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 Web-Direct +// subscriptions. Other subscription types which were not purchased directly through the Azure web portal are not +// supported through this preview API. +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 = "2017-04-24-preview" + 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/preview/consumption/mgmt/2017-04-24-preview/consumption/usagedetails.go b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/usagedetails.go new file mode 100644 index 000000000000..37dded9de42f --- /dev/null +++ b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/usagedetails.go @@ -0,0 +1,166 @@ +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" +) + +// UsageDetailsClient is the consumption management client provides access to consumption resources for Azure +// Web-Direct subscriptions. Other subscription types which were not purchased directly through the Azure web portal +// are not supported through this preview API. +type UsageDetailsClient struct { + BaseClient +} + +// NewUsageDetailsClient creates an instance of the UsageDetailsClient client. +func NewUsageDetailsClient(subscriptionID string) UsageDetailsClient { + return NewUsageDetailsClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewUsageDetailsClientWithBaseURI creates an instance of the UsageDetailsClient client. +func NewUsageDetailsClientWithBaseURI(baseURI string, subscriptionID string) UsageDetailsClient { + return UsageDetailsClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List lists the usage details for a scope in reverse chronological order by billing period. Usage details are +// available via this API only for January 1, 2017 or later. +// +// scope is the scope of the usage details. The scope can be '/subscriptions/{subscriptionId}' for a subscription, +// or '/subscriptions/{subscriptionId}/providers/Microsoft.Billing/invoices/{invoiceName}' for an invoice or +// '/subscriptions/{subscriptionId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}' for a billing +// perdiod. expand is may be used to expand the additionalProperties or meterDetails property within a list of +// usage details. By default, these fields are not included when listing usage details. filter is may be used to +// filter usageDetails by usageEnd (Utc time). The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does +// not currently support 'ne', 'or', or 'not'. skiptoken is 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 is may be used to +// limit the number of results to the most recent N usageDetails. +func (client UsageDetailsClient) List(ctx context.Context, scope string, expand string, filter 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.UsageDetailsClient", "List", err.Error()) + } + + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, scope, expand, filter, skiptoken, top) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "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.UsageDetailsClient", "List", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client UsageDetailsClient) ListPreparer(ctx context.Context, scope string, expand string, filter string, skiptoken string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "scope": scope, + } + + const APIVersion = "2017-04-24-preview" + 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) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/{scope}/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 UsageDetailsClient) 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 UsageDetailsClient) 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 UsageDetailsClient) listNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "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.UsageDetailsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsClient) ListComplete(ctx context.Context, scope string, expand string, filter string, skiptoken string, top *int32) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.List(ctx, scope, expand, filter, skiptoken, top) + return +} diff --git a/services/preview/consumption/mgmt/2017-04-24-preview/consumption/version.go b/services/preview/consumption/mgmt/2017-04-24-preview/consumption/version.go new file mode 100644 index 000000000000..e86c52cc30ba --- /dev/null +++ b/services/preview/consumption/mgmt/2017-04-24-preview/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/2017-04-24-preview" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +} diff --git a/services/preview/consumption/mgmt/2017-12-30-preview/consumption/budgets.go b/services/preview/consumption/mgmt/2017-12-30-preview/consumption/budgets.go new file mode 100644 index 000000000000..0be7ba16788d --- /dev/null +++ b/services/preview/consumption/mgmt/2017-12-30-preview/consumption/budgets.go @@ -0,0 +1,309 @@ +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" +) + +// BudgetsClient is the consumption management client provides access to consumption resources for Azure Enterprise +// Subscriptions. +type BudgetsClient struct { + BaseClient +} + +// NewBudgetsClient creates an instance of the BudgetsClient client. +func NewBudgetsClient(subscriptionID string, name string) BudgetsClient { + return NewBudgetsClientWithBaseURI(DefaultBaseURI, subscriptionID, name) +} + +// NewBudgetsClientWithBaseURI creates an instance of the BudgetsClient client. +func NewBudgetsClientWithBaseURI(baseURI string, subscriptionID string, name string) BudgetsClient { + return BudgetsClient{NewWithBaseURI(baseURI, subscriptionID, name)} +} + +// CreateOrUpdate the operation to create or update a budget. Update operation 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 is parameters supplied to the Create Budget operation. +func (client BudgetsClient) CreateOrUpdate(ctx context.Context, parameters Budget) (result Budget, err error) { + if err := validation.Validate([]validation.Validation{ + {TargetValue: parameters, + Constraints: []validation.Constraint{{Target: "parameters.BudgetProperties", Name: validation.Null, Rule: false, + Chain: []validation.Constraint{{Target: "parameters.BudgetProperties.Category", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.BudgetProperties.Amount", Name: validation.Null, Rule: true, Chain: nil}, + {Target: "parameters.BudgetProperties.TimePeriod", Name: validation.Null, Rule: true, + Chain: []validation.Constraint{{Target: "parameters.BudgetProperties.TimePeriod.StartDate", Name: validation.Null, Rule: true, Chain: nil}}}, + }}}}}); err != nil { + return result, validation.NewError("consumption.BudgetsClient", "CreateOrUpdate", err.Error()) + } + + req, err := client.CreateOrUpdatePreparer(ctx, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "CreateOrUpdate", nil, "Failure preparing request") + return + } + + resp, err := client.CreateOrUpdateSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "CreateOrUpdate", resp, "Failure sending request") + return + } + + result, err = client.CreateOrUpdateResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "CreateOrUpdate", resp, "Failure responding to request") + } + + return +} + +// CreateOrUpdatePreparer prepares the CreateOrUpdate request. +func (client BudgetsClient) CreateOrUpdatePreparer(ctx context.Context, parameters Budget) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "name": autorest.Encode("path", client.Name), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-12-30-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/budgets/{name}", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the +// http.Response Body if it receives an error. +func (client BudgetsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always +// closes the http.Response Body. +func (client BudgetsClient) CreateOrUpdateResponder(resp *http.Response) (result Budget, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// Delete the operation to delete a budget. +func (client BudgetsClient) Delete(ctx context.Context) (result autorest.Response, err error) { + req, err := client.DeletePreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "Delete", nil, "Failure preparing request") + return + } + + resp, err := client.DeleteSender(req) + if err != nil { + result.Response = resp + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "Delete", resp, "Failure sending request") + return + } + + result, err = client.DeleteResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "Delete", resp, "Failure responding to request") + } + + return +} + +// DeletePreparer prepares the Delete request. +func (client BudgetsClient) DeletePreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "name": autorest.Encode("path", client.Name), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-12-30-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsDelete(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/budgets/{name}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// DeleteSender sends the Delete request. The method will close the +// http.Response Body if it receives an error. +func (client BudgetsClient) DeleteSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// DeleteResponder handles the response to the Delete request. The method always +// closes the http.Response Body. +func (client BudgetsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByClosing()) + result.Response = resp + return +} + +// Get gets the budget for a subscription by budget name. +func (client BudgetsClient) Get(ctx context.Context) (result Budget, err error) { + req, err := client.GetPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "Get", nil, "Failure preparing request") + return + } + + resp, err := client.GetSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "Get", resp, "Failure sending request") + return + } + + result, err = client.GetResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "Get", resp, "Failure responding to request") + } + + return +} + +// GetPreparer prepares the Get request. +func (client BudgetsClient) GetPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "name": autorest.Encode("path", client.Name), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-12-30-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/budgets/{name}", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetSender sends the Get request. The method will close the +// http.Response Body if it receives an error. +func (client BudgetsClient) GetSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// GetResponder handles the response to the Get request. The method always +// closes the http.Response Body. +func (client BudgetsClient) GetResponder(resp *http.Response) (result Budget, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// List lists all budgets for a subscription. +func (client BudgetsClient) List(ctx context.Context) (result BudgetsListResult, err error) { + req, err := client.ListPreparer(ctx) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "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.BudgetsClient", "List", resp, "Failure sending request") + return + } + + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.BudgetsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client BudgetsClient) ListPreparer(ctx context.Context) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2017-12-30-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/budgets", 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 BudgetsClient) 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 BudgetsClient) ListResponder(resp *http.Response) (result BudgetsListResult, 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/preview/consumption/mgmt/2017-12-30-preview/consumption/client.go b/services/preview/consumption/mgmt/2017-12-30-preview/consumption/client.go new file mode 100644 index 000000000000..cd11d29834cf --- /dev/null +++ b/services/preview/consumption/mgmt/2017-12-30-preview/consumption/client.go @@ -0,0 +1,53 @@ +// Package consumption implements the Azure ARM Consumption service API version 2017-12-30-preview. +// +// 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 + Name string +} + +// New creates an instance of the BaseClient client. +func New(subscriptionID string, name string) BaseClient { + return NewWithBaseURI(DefaultBaseURI, subscriptionID, name) +} + +// NewWithBaseURI creates an instance of the BaseClient client. +func NewWithBaseURI(baseURI string, subscriptionID string, name string) BaseClient { + return BaseClient{ + Client: autorest.NewClientWithUserAgent(UserAgent()), + BaseURI: baseURI, + SubscriptionID: subscriptionID, + Name: name, + } +} diff --git a/services/preview/consumption/mgmt/2017-12-30-preview/consumption/models.go b/services/preview/consumption/mgmt/2017-12-30-preview/consumption/models.go new file mode 100644 index 000000000000..812704dd1c21 --- /dev/null +++ b/services/preview/consumption/mgmt/2017-12-30-preview/consumption/models.go @@ -0,0 +1,381 @@ +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/date" + "github.com/Azure/go-autorest/autorest/to" + "github.com/shopspring/decimal" + "net/http" +) + +// OperatorType enumerates the values for operator type. +type OperatorType string + +const ( + // EqualTo ... + EqualTo OperatorType = "EqualTo" + // GreaterThan ... + GreaterThan OperatorType = "GreaterThan" + // GreaterThanOrEqualTo ... + GreaterThanOrEqualTo OperatorType = "GreaterThanOrEqualTo" +) + +// PossibleOperatorTypeValues returns an array of possible values for the OperatorType const type. +func PossibleOperatorTypeValues() []OperatorType { + return []OperatorType{EqualTo, GreaterThan, GreaterThanOrEqualTo} +} + +// TimeGrainType enumerates the values for time grain type. +type TimeGrainType string + +const ( + // Annually ... + Annually TimeGrainType = "Annually" + // Monthly ... + Monthly TimeGrainType = "Monthly" + // Quarterly ... + Quarterly TimeGrainType = "Quarterly" +) + +// PossibleTimeGrainTypeValues returns an array of possible values for the TimeGrainType const type. +func PossibleTimeGrainTypeValues() []TimeGrainType { + return []TimeGrainType{Annually, Monthly, Quarterly} +} + +// Budget a budget resource. +type Budget struct { + autorest.Response `json:"-"` + *BudgetProperties `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"` + // ETag - eTag of the resource. To handle concurrent update scenarion, this field will be used to determine whether the user is updating the latest version or not. + ETag *string `json:"eTag,omitempty"` +} + +// MarshalJSON is the custom marshaler for Budget. +func (b Budget) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if b.BudgetProperties != nil { + objectMap["properties"] = b.BudgetProperties + } + 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.ETag != nil { + objectMap["eTag"] = b.ETag + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for Budget struct. +func (b *Budget) 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 budgetProperties BudgetProperties + err = json.Unmarshal(*v, &budgetProperties) + if err != nil { + return err + } + b.BudgetProperties = &budgetProperties + } + 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 "eTag": + if v != nil { + var eTag string + err = json.Unmarshal(*v, &eTag) + if err != nil { + return err + } + b.ETag = &eTag + } + } + } + + return nil +} + +// BudgetProperties the properties of the budget. +type BudgetProperties struct { + // Category - The category of the budget, whether the budget tracks cost or something else. + Category *string `json:"category,omitempty"` + // Amount - The total amount of cost to track with the budget + Amount *decimal.Decimal `json:"amount,omitempty"` + // TimeGrain - The time covered by a budget. Tracking of the amount will be reset based on the time grain. Possible values include: 'Monthly', 'Quarterly', 'Annually' + TimeGrain TimeGrainType `json:"timeGrain,omitempty"` + // TimePeriod - Has start and end date of the budget. The start date must be first of the month and should be less than the end date. Budget start date must be on or after June 1, 2017. Future start date should not be more than three months. Past start date should be selected within the timegrain preiod. There are no restrictions on the end date. + TimePeriod *BudgetTimePeriod `json:"timePeriod,omitempty"` + // CurrentSpend - The current amount of cost which is being tracked for a budget. + CurrentSpend *CurrentSpend `json:"currentSpend,omitempty"` + // Notifications - Dictionary of notifications associated with the budget. Budget can have up to five notifications. + Notifications map[string]*Notification `json:"notifications"` +} + +// MarshalJSON is the custom marshaler for BudgetProperties. +func (bp BudgetProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if bp.Category != nil { + objectMap["category"] = bp.Category + } + if bp.Amount != nil { + objectMap["amount"] = bp.Amount + } + if bp.TimeGrain != "" { + objectMap["timeGrain"] = bp.TimeGrain + } + if bp.TimePeriod != nil { + objectMap["timePeriod"] = bp.TimePeriod + } + if bp.CurrentSpend != nil { + objectMap["currentSpend"] = bp.CurrentSpend + } + if bp.Notifications != nil { + objectMap["notifications"] = bp.Notifications + } + return json.Marshal(objectMap) +} + +// BudgetsListResult result of listing budgets. It contains a list of available budgets in the scope provided. +type BudgetsListResult struct { + autorest.Response `json:"-"` + // Value - The list of budgets. + Value *[]Budget `json:"value,omitempty"` +} + +// BudgetTimePeriod the start and end date for a budget. +type BudgetTimePeriod struct { + // StartDate - The start date for the budget. + StartDate *date.Time `json:"startDate,omitempty"` + // EndDate - The end date for the budget. If not provided, we default this to 10 years from the start date. + EndDate *date.Time `json:"endDate,omitempty"` +} + +// CurrentSpend the current amount of cost which is being tracked for a budget. +type CurrentSpend struct { + // Amount - The total amount of cost which is being tracked by the budget. + Amount *decimal.Decimal `json:"amount,omitempty"` + // Unit - The unit of measure for the budget amount. + Unit *string `json:"unit,omitempty"` +} + +// 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"` +} + +// Notification the notification associated with a budget. +type Notification struct { + // Enabled - The notification is enabled or not. + Enabled *bool `json:"enabled,omitempty"` + // Operator - The comparison operator. Possible values include: 'EqualTo', 'GreaterThan', 'GreaterThanOrEqualTo' + Operator OperatorType `json:"operator,omitempty"` + // Threshold - Threshold value associated with a notification. Notification is sent when the cost exceeded the threshold. It is always percent and has to be between 0 and 1000. + Threshold *decimal.Decimal `json:"threshold,omitempty"` + // ContactEmails - Email addresses to send the budget notification to when the threshold is exceeded. + ContactEmails *[]string `json:"contactEmails,omitempty"` + // ContactRoles - Contact roles to send the budget notification to when the threshold is exceeded. + ContactRoles *[]string `json:"contactRoles,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 +} + +// ProxyResource the Resource model definition. +type ProxyResource 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"` + // ETag - eTag of the resource. To handle concurrent update scenarion, this field will be used to determine whether the user is updating the latest version or not. + ETag *string `json:"eTag,omitempty"` +} diff --git a/services/preview/consumption/mgmt/2017-12-30-preview/consumption/operations.go b/services/preview/consumption/mgmt/2017-12-30-preview/consumption/operations.go new file mode 100644 index 000000000000..09f533cbf419 --- /dev/null +++ b/services/preview/consumption/mgmt/2017-12-30-preview/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, name string) OperationsClient { + return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID, name) +} + +// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client. +func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string, name string) OperationsClient { + return OperationsClient{NewWithBaseURI(baseURI, subscriptionID, name)} +} + +// 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 = "2017-12-30-preview" + 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/preview/consumption/mgmt/2017-12-30-preview/consumption/version.go b/services/preview/consumption/mgmt/2017-12-30-preview/consumption/version.go new file mode 100644 index 000000000000..b48a7deccdcf --- /dev/null +++ b/services/preview/consumption/mgmt/2017-12-30-preview/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/2017-12-30-preview" +} + +// Version returns the semantic version (see http://semver.org) of the client. +func Version() string { + return version.Number +}