diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/CHANGELOG.md b/sdk/resourcemanager/costmanagement/armcostmanagement/CHANGELOG.md new file mode 100644 index 000000000000..6e36ac184e16 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## 0.1.0 (2021-11-29) diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/LICENSE.txt b/sdk/resourcemanager/costmanagement/armcostmanagement/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Microsoft Corporation. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/README.md b/sdk/resourcemanager/costmanagement/armcostmanagement/README.md new file mode 100644 index 000000000000..23bb081be2eb --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/README.md @@ -0,0 +1,75 @@ +# Azure Costmanagement Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement) + +The `armcostmanagement` module provides operations for working with Azure Costmanagement. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/costmanagement/armcostmanagement) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.13 or above + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Costmanagement module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Costmanagement. The `azidentity` module provides facilities for various ways of authenticating with Azure including client/secret, certificate, managed identity, and more. + +```go +cred, err := azidentity.NewDefaultAzureCredential(nil) +``` + +For more information on authentication, please see the documentation for `azidentity` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity). + +## Clients + +Azure Costmanagement modules consist of one or more clients. A client groups a set of related APIs, providing access to its functionality within the specified subscription. Create one or more clients to access the APIs you require using your credential. + +```go +client := armcostmanagement.(, cred, nil) +``` + +You can use `ClientOptions` in package `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` to set endpoint to connect with public and sovereign clouds as well as Azure Stack. For more information, please see the documentation for `azcore` at [pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore). + +```go +options = arm.ClientOptions{ + Host: arm.AzureChina, +} +client := armcostmanagement.(, cred, &options) +``` + +## Provide Feedback + +If you encounter bugs or have suggestions, please +[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Costmanagement` label. + +# Contributing + +This project welcomes contributions and suggestions. Most contributions require +you to agree to a Contributor License Agreement (CLA) declaring that you have +the right to, and actually do, grant us the rights to use your contribution. +For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). + +When you submit a pull request, a CLA-bot will automatically determine whether +you need to provide a CLA and decorate the PR appropriately (e.g., label, +comment). Simply follow the instructions provided by the bot. You will only +need to do this once across all repos using our CLA. + +This project has adopted the +[Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information, see the +[Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any +additional questions or comments. \ No newline at end of file diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/autorest.md b/sdk/resourcemanager/costmanagement/armcostmanagement/autorest.md new file mode 100644 index 000000000000..ef52a3e79ea7 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/autorest.md @@ -0,0 +1,13 @@ +### AutoRest Configuration + +> see https://aka.ms/autorest + +``` yaml +azure-arm: true +require: +- /home/vsts/work/1/s/azure-rest-api-specs/specification/cost-management/resource-manager/readme.md +- /home/vsts/work/1/s/azure-rest-api-specs/specification/cost-management/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 0.1.0 + +``` \ No newline at end of file diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/build.go b/sdk/resourcemanager/costmanagement/armcostmanagement/build.go new file mode 100644 index 000000000000..f0e44c786866 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/build.go @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file enables 'go generate' to regenerate this specific SDK +//go:generate pwsh.exe ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate resourcemanager/costmanagement/armcostmanagement + +package armcostmanagement diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/ci.yml b/sdk/resourcemanager/costmanagement/armcostmanagement/ci.yml new file mode 100644 index 000000000000..d9786f5d3406 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/ci.yml @@ -0,0 +1,27 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/costmanagement/armcostmanagement/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/costmanagement/armcostmanagement/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'resourcemanager/costmanagement/armcostmanagement' diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/go.mod b/sdk/resourcemanager/costmanagement/armcostmanagement/go.mod new file mode 100644 index 000000000000..5f2b5b8c5e08 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/go.mod @@ -0,0 +1,8 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement + +go 1.16 + +require ( + github.com/Azure/azure-sdk-for-go v59.4.0+incompatible + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 +) diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/go.sum b/sdk/resourcemanager/costmanagement/armcostmanagement/go.sum new file mode 100644 index 000000000000..aa6cc05eede2 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/go.sum @@ -0,0 +1,37 @@ +github.com/Azure/azure-sdk-for-go v59.4.0+incompatible h1:gDA8odnngdNd3KYHL2NoK1j9vpWBgEnFSjKKLpkC8Aw= +github.com/Azure/azure-sdk-for-go v59.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 h1:KQgdWmEOmaJKxaUUZwHAYh12t+b+ZJf8q3friycK1kA= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0/go.mod h1:ZPW/Z0kLCTdDZaDbYTetxc9Cxl/2lNqxYHYNOF2bti0= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1 h1:BUYIbDf/mMZ8945v3QkG3OuqGVyS4Iek0AOLwdRAYoc= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/go_mod_tidy_hack.go b/sdk/resourcemanager/costmanagement/armcostmanagement/go_mod_tidy_hack.go new file mode 100644 index 000000000000..27dbe6ddb55f --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/go_mod_tidy_hack.go @@ -0,0 +1,13 @@ +//go:build modhack +// +build modhack + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file, and the github.com/Azure/azure-sdk-for-go import, won't actually become part of +// the resultant binary. + +package armcostmanagement + +// Necessary for safely adding multi-module repo. See: https://github.com/golang/go/wiki/Modules#is-it-possible-to-add-a-module-to-a-multi-module-repository +import _ "github.com/Azure/azure-sdk-for-go" diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_alerts_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_alerts_client.go new file mode 100644 index 000000000000..423b79e28f5a --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_alerts_client.go @@ -0,0 +1,267 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// AlertsClient contains the methods for the Alerts group. +// Don't use this type directly, use NewAlertsClient() instead. +type AlertsClient struct { + ep string + pl runtime.Pipeline +} + +// NewAlertsClient creates a new instance of AlertsClient with the specified values. +func NewAlertsClient(credential azcore.TokenCredential, options *arm.ClientOptions) *AlertsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &AlertsClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// Dismiss - Dismisses the specified alert +// If the operation fails it returns the *ErrorResponse error type. +func (client *AlertsClient) Dismiss(ctx context.Context, scope string, alertID string, parameters DismissAlertPayload, options *AlertsDismissOptions) (AlertsDismissResponse, error) { + req, err := client.dismissCreateRequest(ctx, scope, alertID, parameters, options) + if err != nil { + return AlertsDismissResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsDismissResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsDismissResponse{}, client.dismissHandleError(resp) + } + return client.dismissHandleResponse(resp) +} + +// dismissCreateRequest creates the Dismiss request. +func (client *AlertsClient) dismissCreateRequest(ctx context.Context, scope string, alertID string, parameters DismissAlertPayload, options *AlertsDismissOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/alerts/{alertId}" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + urlPath = strings.ReplaceAll(urlPath, "{alertId}", alertID) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// dismissHandleResponse handles the Dismiss response. +func (client *AlertsClient) dismissHandleResponse(resp *http.Response) (AlertsDismissResponse, error) { + result := AlertsDismissResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Alert); err != nil { + return AlertsDismissResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// dismissHandleError handles the Dismiss error response. +func (client *AlertsClient) dismissHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Gets the alert for the scope by alert ID. +// If the operation fails it returns the *ErrorResponse error type. +func (client *AlertsClient) Get(ctx context.Context, scope string, alertID string, options *AlertsGetOptions) (AlertsGetResponse, error) { + req, err := client.getCreateRequest(ctx, scope, alertID, options) + if err != nil { + return AlertsGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *AlertsClient) getCreateRequest(ctx context.Context, scope string, alertID string, options *AlertsGetOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/alerts/{alertId}" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + urlPath = strings.ReplaceAll(urlPath, "{alertId}", alertID) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *AlertsClient) getHandleResponse(resp *http.Response) (AlertsGetResponse, error) { + result := AlertsGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Alert); err != nil { + return AlertsGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *AlertsClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// List - Lists the alerts for scope defined. +// If the operation fails it returns the *ErrorResponse error type. +func (client *AlertsClient) List(ctx context.Context, scope string, options *AlertsListOptions) (AlertsListResponse, error) { + req, err := client.listCreateRequest(ctx, scope, options) + if err != nil { + return AlertsListResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsListResponse{}, client.listHandleError(resp) + } + return client.listHandleResponse(resp) +} + +// listCreateRequest creates the List request. +func (client *AlertsClient) listCreateRequest(ctx context.Context, scope string, options *AlertsListOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/alerts" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *AlertsClient) listHandleResponse(resp *http.Response) (AlertsListResponse, error) { + result := AlertsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertsResult); err != nil { + return AlertsListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *AlertsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListExternal - Lists the Alerts for external cloud provider type defined. +// If the operation fails it returns the *ErrorResponse error type. +func (client *AlertsClient) ListExternal(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string, options *AlertsListExternalOptions) (AlertsListExternalResponse, error) { + req, err := client.listExternalCreateRequest(ctx, externalCloudProviderType, externalCloudProviderID, options) + if err != nil { + return AlertsListExternalResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AlertsListExternalResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AlertsListExternalResponse{}, client.listExternalHandleError(resp) + } + return client.listExternalHandleResponse(resp) +} + +// listExternalCreateRequest creates the ListExternal request. +func (client *AlertsClient) listExternalCreateRequest(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string, options *AlertsListExternalOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/{externalCloudProviderType}/{externalCloudProviderId}/alerts" + if externalCloudProviderType == "" { + return nil, errors.New("parameter externalCloudProviderType cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{externalCloudProviderType}", url.PathEscape(string(externalCloudProviderType))) + if externalCloudProviderID == "" { + return nil, errors.New("parameter externalCloudProviderID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{externalCloudProviderId}", url.PathEscape(externalCloudProviderID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listExternalHandleResponse handles the ListExternal response. +func (client *AlertsClient) listExternalHandleResponse(resp *http.Response) (AlertsListExternalResponse, error) { + result := AlertsListExternalResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AlertsResult); err != nil { + return AlertsListExternalResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listExternalHandleError handles the ListExternal error response. +func (client *AlertsClient) listExternalHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_constants.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_constants.go new file mode 100644 index 000000000000..f9e1a1419e9f --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_constants.go @@ -0,0 +1,838 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +const ( + module = "armcostmanagement" + version = "v0.1.0" +) + +// AccumulatedType - Show costs accumulated over time. +type AccumulatedType string + +const ( + AccumulatedTypeFalse AccumulatedType = "false" + AccumulatedTypeTrue AccumulatedType = "true" +) + +// PossibleAccumulatedTypeValues returns the possible values for the AccumulatedType const type. +func PossibleAccumulatedTypeValues() []AccumulatedType { + return []AccumulatedType{ + AccumulatedTypeFalse, + AccumulatedTypeTrue, + } +} + +// ToPtr returns a *AccumulatedType pointing to the current value. +func (c AccumulatedType) ToPtr() *AccumulatedType { + return &c +} + +// AlertCategory - Alert category +type AlertCategory string + +const ( + AlertCategoryBilling AlertCategory = "Billing" + AlertCategoryCost AlertCategory = "Cost" + AlertCategorySystem AlertCategory = "System" + AlertCategoryUsage AlertCategory = "Usage" +) + +// PossibleAlertCategoryValues returns the possible values for the AlertCategory const type. +func PossibleAlertCategoryValues() []AlertCategory { + return []AlertCategory{ + AlertCategoryBilling, + AlertCategoryCost, + AlertCategorySystem, + AlertCategoryUsage, + } +} + +// ToPtr returns a *AlertCategory pointing to the current value. +func (c AlertCategory) ToPtr() *AlertCategory { + return &c +} + +// AlertCriteria - Criteria that triggered alert +type AlertCriteria string + +const ( + AlertCriteriaCostThresholdExceeded AlertCriteria = "CostThresholdExceeded" + AlertCriteriaCreditThresholdApproaching AlertCriteria = "CreditThresholdApproaching" + AlertCriteriaCreditThresholdReached AlertCriteria = "CreditThresholdReached" + AlertCriteriaCrossCloudCollectionError AlertCriteria = "CrossCloudCollectionError" + AlertCriteriaCrossCloudNewDataAvailable AlertCriteria = "CrossCloudNewDataAvailable" + AlertCriteriaForecastCostThresholdExceeded AlertCriteria = "ForecastCostThresholdExceeded" + AlertCriteriaForecastUsageThresholdExceeded AlertCriteria = "ForecastUsageThresholdExceeded" + AlertCriteriaGeneralThresholdError AlertCriteria = "GeneralThresholdError" + AlertCriteriaInvoiceDueDateApproaching AlertCriteria = "InvoiceDueDateApproaching" + AlertCriteriaInvoiceDueDateReached AlertCriteria = "InvoiceDueDateReached" + AlertCriteriaMultiCurrency AlertCriteria = "MultiCurrency" + AlertCriteriaQuotaThresholdApproaching AlertCriteria = "QuotaThresholdApproaching" + AlertCriteriaQuotaThresholdReached AlertCriteria = "QuotaThresholdReached" + AlertCriteriaUsageThresholdExceeded AlertCriteria = "UsageThresholdExceeded" +) + +// PossibleAlertCriteriaValues returns the possible values for the AlertCriteria const type. +func PossibleAlertCriteriaValues() []AlertCriteria { + return []AlertCriteria{ + AlertCriteriaCostThresholdExceeded, + AlertCriteriaCreditThresholdApproaching, + AlertCriteriaCreditThresholdReached, + AlertCriteriaCrossCloudCollectionError, + AlertCriteriaCrossCloudNewDataAvailable, + AlertCriteriaForecastCostThresholdExceeded, + AlertCriteriaForecastUsageThresholdExceeded, + AlertCriteriaGeneralThresholdError, + AlertCriteriaInvoiceDueDateApproaching, + AlertCriteriaInvoiceDueDateReached, + AlertCriteriaMultiCurrency, + AlertCriteriaQuotaThresholdApproaching, + AlertCriteriaQuotaThresholdReached, + AlertCriteriaUsageThresholdExceeded, + } +} + +// ToPtr returns a *AlertCriteria pointing to the current value. +func (c AlertCriteria) ToPtr() *AlertCriteria { + return &c +} + +// AlertOperator - operator used to compare currentSpend with amount +type AlertOperator string + +const ( + AlertOperatorEqualTo AlertOperator = "EqualTo" + AlertOperatorGreaterThan AlertOperator = "GreaterThan" + AlertOperatorGreaterThanOrEqualTo AlertOperator = "GreaterThanOrEqualTo" + AlertOperatorLessThan AlertOperator = "LessThan" + AlertOperatorLessThanOrEqualTo AlertOperator = "LessThanOrEqualTo" + AlertOperatorNone AlertOperator = "None" +) + +// PossibleAlertOperatorValues returns the possible values for the AlertOperator const type. +func PossibleAlertOperatorValues() []AlertOperator { + return []AlertOperator{ + AlertOperatorEqualTo, + AlertOperatorGreaterThan, + AlertOperatorGreaterThanOrEqualTo, + AlertOperatorLessThan, + AlertOperatorLessThanOrEqualTo, + AlertOperatorNone, + } +} + +// ToPtr returns a *AlertOperator pointing to the current value. +func (c AlertOperator) ToPtr() *AlertOperator { + return &c +} + +// AlertSource - Source of alert +type AlertSource string + +const ( + AlertSourcePreset AlertSource = "Preset" + AlertSourceUser AlertSource = "User" +) + +// PossibleAlertSourceValues returns the possible values for the AlertSource const type. +func PossibleAlertSourceValues() []AlertSource { + return []AlertSource{ + AlertSourcePreset, + AlertSourceUser, + } +} + +// ToPtr returns a *AlertSource pointing to the current value. +func (c AlertSource) ToPtr() *AlertSource { + return &c +} + +// AlertStatus - alert status +type AlertStatus string + +const ( + AlertStatusActive AlertStatus = "Active" + AlertStatusDismissed AlertStatus = "Dismissed" + AlertStatusNone AlertStatus = "None" + AlertStatusOverridden AlertStatus = "Overridden" + AlertStatusResolved AlertStatus = "Resolved" +) + +// PossibleAlertStatusValues returns the possible values for the AlertStatus const type. +func PossibleAlertStatusValues() []AlertStatus { + return []AlertStatus{ + AlertStatusActive, + AlertStatusDismissed, + AlertStatusNone, + AlertStatusOverridden, + AlertStatusResolved, + } +} + +// ToPtr returns a *AlertStatus pointing to the current value. +func (c AlertStatus) ToPtr() *AlertStatus { + return &c +} + +// AlertTimeGrainType - Type of timegrain cadence +type AlertTimeGrainType string + +const ( + AlertTimeGrainTypeAnnually AlertTimeGrainType = "Annually" + AlertTimeGrainTypeBillingAnnual AlertTimeGrainType = "BillingAnnual" + AlertTimeGrainTypeBillingMonth AlertTimeGrainType = "BillingMonth" + AlertTimeGrainTypeBillingQuarter AlertTimeGrainType = "BillingQuarter" + AlertTimeGrainTypeMonthly AlertTimeGrainType = "Monthly" + AlertTimeGrainTypeNone AlertTimeGrainType = "None" + AlertTimeGrainTypeQuarterly AlertTimeGrainType = "Quarterly" +) + +// PossibleAlertTimeGrainTypeValues returns the possible values for the AlertTimeGrainType const type. +func PossibleAlertTimeGrainTypeValues() []AlertTimeGrainType { + return []AlertTimeGrainType{ + AlertTimeGrainTypeAnnually, + AlertTimeGrainTypeBillingAnnual, + AlertTimeGrainTypeBillingMonth, + AlertTimeGrainTypeBillingQuarter, + AlertTimeGrainTypeMonthly, + AlertTimeGrainTypeNone, + AlertTimeGrainTypeQuarterly, + } +} + +// ToPtr returns a *AlertTimeGrainType pointing to the current value. +func (c AlertTimeGrainType) ToPtr() *AlertTimeGrainType { + return &c +} + +// AlertType - type of alert +type AlertType string + +const ( + AlertTypeBudget AlertType = "Budget" + AlertTypeBudgetForecast AlertType = "BudgetForecast" + AlertTypeCredit AlertType = "Credit" + AlertTypeGeneral AlertType = "General" + AlertTypeInvoice AlertType = "Invoice" + AlertTypeQuota AlertType = "Quota" + AlertTypeXCloud AlertType = "xCloud" +) + +// PossibleAlertTypeValues returns the possible values for the AlertType const type. +func PossibleAlertTypeValues() []AlertType { + return []AlertType{ + AlertTypeBudget, + AlertTypeBudgetForecast, + AlertTypeCredit, + AlertTypeGeneral, + AlertTypeInvoice, + AlertTypeQuota, + AlertTypeXCloud, + } +} + +// ToPtr returns a *AlertType pointing to the current value. +func (c AlertType) ToPtr() *AlertType { + return &c +} + +// ChartType - Chart type of the main view in Cost Analysis. Required. +type ChartType string + +const ( + ChartTypeArea ChartType = "Area" + ChartTypeGroupedColumn ChartType = "GroupedColumn" + ChartTypeLine ChartType = "Line" + ChartTypeStackedColumn ChartType = "StackedColumn" + ChartTypeTable ChartType = "Table" +) + +// PossibleChartTypeValues returns the possible values for the ChartType const type. +func PossibleChartTypeValues() []ChartType { + return []ChartType{ + ChartTypeArea, + ChartTypeGroupedColumn, + ChartTypeLine, + ChartTypeStackedColumn, + ChartTypeTable, + } +} + +// ToPtr returns a *ChartType pointing to the current value. +func (c ChartType) ToPtr() *ChartType { + return &c +} + +// ExecutionStatus - The last known status of the export execution. +type ExecutionStatus string + +const ( + ExecutionStatusCompleted ExecutionStatus = "Completed" + ExecutionStatusDataNotAvailable ExecutionStatus = "DataNotAvailable" + ExecutionStatusFailed ExecutionStatus = "Failed" + ExecutionStatusInProgress ExecutionStatus = "InProgress" + ExecutionStatusNewDataNotAvailable ExecutionStatus = "NewDataNotAvailable" + ExecutionStatusQueued ExecutionStatus = "Queued" + ExecutionStatusTimeout ExecutionStatus = "Timeout" +) + +// PossibleExecutionStatusValues returns the possible values for the ExecutionStatus const type. +func PossibleExecutionStatusValues() []ExecutionStatus { + return []ExecutionStatus{ + ExecutionStatusCompleted, + ExecutionStatusDataNotAvailable, + ExecutionStatusFailed, + ExecutionStatusInProgress, + ExecutionStatusNewDataNotAvailable, + ExecutionStatusQueued, + ExecutionStatusTimeout, + } +} + +// ToPtr returns a *ExecutionStatus pointing to the current value. +func (c ExecutionStatus) ToPtr() *ExecutionStatus { + return &c +} + +// ExecutionType - The type of the export execution. +type ExecutionType string + +const ( + ExecutionTypeOnDemand ExecutionType = "OnDemand" + ExecutionTypeScheduled ExecutionType = "Scheduled" +) + +// PossibleExecutionTypeValues returns the possible values for the ExecutionType const type. +func PossibleExecutionTypeValues() []ExecutionType { + return []ExecutionType{ + ExecutionTypeOnDemand, + ExecutionTypeScheduled, + } +} + +// ToPtr returns a *ExecutionType pointing to the current value. +func (c ExecutionType) ToPtr() *ExecutionType { + return &c +} + +// ExportType - The type of the export. Note that 'Usage' is equivalent to 'ActualCost' and is applicable to exports that do not yet provide data for charges +// or amortization for service reservations. +type ExportType string + +const ( + ExportTypeActualCost ExportType = "ActualCost" + ExportTypeAmortizedCost ExportType = "AmortizedCost" + ExportTypeUsage ExportType = "Usage" +) + +// PossibleExportTypeValues returns the possible values for the ExportType const type. +func PossibleExportTypeValues() []ExportType { + return []ExportType{ + ExportTypeActualCost, + ExportTypeAmortizedCost, + ExportTypeUsage, + } +} + +// ToPtr returns a *ExportType pointing to the current value. +func (c ExportType) ToPtr() *ExportType { + return &c +} + +type ExternalCloudProviderType string + +const ( + ExternalCloudProviderTypeExternalBillingAccounts ExternalCloudProviderType = "externalBillingAccounts" + ExternalCloudProviderTypeExternalSubscriptions ExternalCloudProviderType = "externalSubscriptions" +) + +// PossibleExternalCloudProviderTypeValues returns the possible values for the ExternalCloudProviderType const type. +func PossibleExternalCloudProviderTypeValues() []ExternalCloudProviderType { + return []ExternalCloudProviderType{ + ExternalCloudProviderTypeExternalBillingAccounts, + ExternalCloudProviderTypeExternalSubscriptions, + } +} + +// ToPtr returns a *ExternalCloudProviderType pointing to the current value. +func (c ExternalCloudProviderType) ToPtr() *ExternalCloudProviderType { + return &c +} + +// ForecastTimeframeType - The time frame for pulling data for the forecast. If custom, then a specific time period must be provided. +type ForecastTimeframeType string + +const ( + ForecastTimeframeTypeBillingMonthToDate ForecastTimeframeType = "BillingMonthToDate" + ForecastTimeframeTypeCustom ForecastTimeframeType = "Custom" + ForecastTimeframeTypeMonthToDate ForecastTimeframeType = "MonthToDate" + ForecastTimeframeTypeTheLastBillingMonth ForecastTimeframeType = "TheLastBillingMonth" + ForecastTimeframeTypeTheLastMonth ForecastTimeframeType = "TheLastMonth" + ForecastTimeframeTypeWeekToDate ForecastTimeframeType = "WeekToDate" +) + +// PossibleForecastTimeframeTypeValues returns the possible values for the ForecastTimeframeType const type. +func PossibleForecastTimeframeTypeValues() []ForecastTimeframeType { + return []ForecastTimeframeType{ + ForecastTimeframeTypeBillingMonthToDate, + ForecastTimeframeTypeCustom, + ForecastTimeframeTypeMonthToDate, + ForecastTimeframeTypeTheLastBillingMonth, + ForecastTimeframeTypeTheLastMonth, + ForecastTimeframeTypeWeekToDate, + } +} + +// ToPtr returns a *ForecastTimeframeType pointing to the current value. +func (c ForecastTimeframeType) ToPtr() *ForecastTimeframeType { + return &c +} + +// ForecastType - The type of the forecast. +type ForecastType string + +const ( + ForecastTypeActualCost ForecastType = "ActualCost" + ForecastTypeAmortizedCost ForecastType = "AmortizedCost" + ForecastTypeUsage ForecastType = "Usage" +) + +// PossibleForecastTypeValues returns the possible values for the ForecastType const type. +func PossibleForecastTypeValues() []ForecastType { + return []ForecastType{ + ForecastTypeActualCost, + ForecastTypeAmortizedCost, + ForecastTypeUsage, + } +} + +// ToPtr returns a *ForecastType pointing to the current value. +func (c ForecastType) ToPtr() *ForecastType { + return &c +} + +// FormatType - The format of the export being delivered. Currently only 'Csv' is supported. +type FormatType string + +const ( + FormatTypeCSV FormatType = "Csv" +) + +// PossibleFormatTypeValues returns the possible values for the FormatType const type. +func PossibleFormatTypeValues() []FormatType { + return []FormatType{ + FormatTypeCSV, + } +} + +// ToPtr returns a *FormatType pointing to the current value. +func (c FormatType) ToPtr() *FormatType { + return &c +} + +// FunctionType - The name of the aggregation function to use. +type FunctionType string + +const ( + FunctionTypeSum FunctionType = "Sum" +) + +// PossibleFunctionTypeValues returns the possible values for the FunctionType const type. +func PossibleFunctionTypeValues() []FunctionType { + return []FunctionType{ + FunctionTypeSum, + } +} + +// ToPtr returns a *FunctionType pointing to the current value. +func (c FunctionType) ToPtr() *FunctionType { + return &c +} + +// GenerateDetailedCostReportMetricType - The type of the detailed report. By default ActualCost is provided +type GenerateDetailedCostReportMetricType string + +const ( + GenerateDetailedCostReportMetricTypeActualCost GenerateDetailedCostReportMetricType = "ActualCost" + GenerateDetailedCostReportMetricTypeAmortizedCost GenerateDetailedCostReportMetricType = "AmortizedCost" +) + +// PossibleGenerateDetailedCostReportMetricTypeValues returns the possible values for the GenerateDetailedCostReportMetricType const type. +func PossibleGenerateDetailedCostReportMetricTypeValues() []GenerateDetailedCostReportMetricType { + return []GenerateDetailedCostReportMetricType{ + GenerateDetailedCostReportMetricTypeActualCost, + GenerateDetailedCostReportMetricTypeAmortizedCost, + } +} + +// ToPtr returns a *GenerateDetailedCostReportMetricType pointing to the current value. +func (c GenerateDetailedCostReportMetricType) ToPtr() *GenerateDetailedCostReportMetricType { + return &c +} + +// GranularityType - The granularity of rows in the export. Currently only 'Daily' is supported. +type GranularityType string + +const ( + GranularityTypeDaily GranularityType = "Daily" +) + +// PossibleGranularityTypeValues returns the possible values for the GranularityType const type. +func PossibleGranularityTypeValues() []GranularityType { + return []GranularityType{ + GranularityTypeDaily, + } +} + +// ToPtr returns a *GranularityType pointing to the current value. +func (c GranularityType) ToPtr() *GranularityType { + return &c +} + +// KpiType - KPI type (Forecast, Budget). +type KpiType string + +const ( + KpiTypeBudget KpiType = "Budget" + KpiTypeForecast KpiType = "Forecast" +) + +// PossibleKpiTypeValues returns the possible values for the KpiType const type. +func PossibleKpiTypeValues() []KpiType { + return []KpiType{ + KpiTypeBudget, + KpiTypeForecast, + } +} + +// ToPtr returns a *KpiType pointing to the current value. +func (c KpiType) ToPtr() *KpiType { + return &c +} + +// MetricType - Metric to use when displaying costs. +type MetricType string + +const ( + MetricTypeAHUB MetricType = "AHUB" + MetricTypeActualCost MetricType = "ActualCost" + MetricTypeAmortizedCost MetricType = "AmortizedCost" +) + +// PossibleMetricTypeValues returns the possible values for the MetricType const type. +func PossibleMetricTypeValues() []MetricType { + return []MetricType{ + MetricTypeAHUB, + MetricTypeActualCost, + MetricTypeAmortizedCost, + } +} + +// ToPtr returns a *MetricType pointing to the current value. +func (c MetricType) ToPtr() *MetricType { + return &c +} + +// OperationStatusType - The status of the long running operation. +type OperationStatusType string + +const ( + OperationStatusTypeCompleted OperationStatusType = "Completed" + OperationStatusTypeFailed OperationStatusType = "Failed" + OperationStatusTypeInProgress OperationStatusType = "InProgress" + OperationStatusTypeNoDataFound OperationStatusType = "NoDataFound" + OperationStatusTypeQueued OperationStatusType = "Queued" + OperationStatusTypeReadyToDownload OperationStatusType = "ReadyToDownload" + OperationStatusTypeTimedOut OperationStatusType = "TimedOut" +) + +// PossibleOperationStatusTypeValues returns the possible values for the OperationStatusType const type. +func PossibleOperationStatusTypeValues() []OperationStatusType { + return []OperationStatusType{ + OperationStatusTypeCompleted, + OperationStatusTypeFailed, + OperationStatusTypeInProgress, + OperationStatusTypeNoDataFound, + OperationStatusTypeQueued, + OperationStatusTypeReadyToDownload, + OperationStatusTypeTimedOut, + } +} + +// ToPtr returns a *OperationStatusType pointing to the current value. +func (c OperationStatusType) ToPtr() *OperationStatusType { + return &c +} + +// OperatorType - The operator to use for comparison. +type OperatorType string + +const ( + OperatorTypeContains OperatorType = "Contains" + OperatorTypeIn OperatorType = "In" +) + +// PossibleOperatorTypeValues returns the possible values for the OperatorType const type. +func PossibleOperatorTypeValues() []OperatorType { + return []OperatorType{ + OperatorTypeContains, + OperatorTypeIn, + } +} + +// ToPtr returns a *OperatorType pointing to the current value. +func (c OperatorType) ToPtr() *OperatorType { + return &c +} + +// PivotType - Data type to show in view. +type PivotType string + +const ( + PivotTypeDimension PivotType = "Dimension" + PivotTypeTagKey PivotType = "TagKey" +) + +// PossiblePivotTypeValues returns the possible values for the PivotType const type. +func PossiblePivotTypeValues() []PivotType { + return []PivotType{ + PivotTypeDimension, + PivotTypeTagKey, + } +} + +// ToPtr returns a *PivotType pointing to the current value. +func (c PivotType) ToPtr() *PivotType { + return &c +} + +// QueryColumnType - The type of the column in the export. +type QueryColumnType string + +const ( + QueryColumnTypeDimension QueryColumnType = "Dimension" + QueryColumnTypeTag QueryColumnType = "Tag" +) + +// PossibleQueryColumnTypeValues returns the possible values for the QueryColumnType const type. +func PossibleQueryColumnTypeValues() []QueryColumnType { + return []QueryColumnType{ + QueryColumnTypeDimension, + QueryColumnTypeTag, + } +} + +// ToPtr returns a *QueryColumnType pointing to the current value. +func (c QueryColumnType) ToPtr() *QueryColumnType { + return &c +} + +// QueryOperatorType - The operator to use for comparison. +type QueryOperatorType string + +const ( + QueryOperatorTypeIn QueryOperatorType = "In" +) + +// PossibleQueryOperatorTypeValues returns the possible values for the QueryOperatorType const type. +func PossibleQueryOperatorTypeValues() []QueryOperatorType { + return []QueryOperatorType{ + QueryOperatorTypeIn, + } +} + +// ToPtr returns a *QueryOperatorType pointing to the current value. +func (c QueryOperatorType) ToPtr() *QueryOperatorType { + return &c +} + +// RecurrenceType - The schedule recurrence. +type RecurrenceType string + +const ( + RecurrenceTypeAnnually RecurrenceType = "Annually" + RecurrenceTypeDaily RecurrenceType = "Daily" + RecurrenceTypeMonthly RecurrenceType = "Monthly" + RecurrenceTypeWeekly RecurrenceType = "Weekly" +) + +// PossibleRecurrenceTypeValues returns the possible values for the RecurrenceType const type. +func PossibleRecurrenceTypeValues() []RecurrenceType { + return []RecurrenceType{ + RecurrenceTypeAnnually, + RecurrenceTypeDaily, + RecurrenceTypeMonthly, + RecurrenceTypeWeekly, + } +} + +// ToPtr returns a *RecurrenceType pointing to the current value. +func (c RecurrenceType) ToPtr() *RecurrenceType { + return &c +} + +// ReportConfigColumnType - The type of the column in the report. +type ReportConfigColumnType string + +const ( + ReportConfigColumnTypeDimension ReportConfigColumnType = "Dimension" + ReportConfigColumnTypeTag ReportConfigColumnType = "Tag" +) + +// PossibleReportConfigColumnTypeValues returns the possible values for the ReportConfigColumnType const type. +func PossibleReportConfigColumnTypeValues() []ReportConfigColumnType { + return []ReportConfigColumnType{ + ReportConfigColumnTypeDimension, + ReportConfigColumnTypeTag, + } +} + +// ToPtr returns a *ReportConfigColumnType pointing to the current value. +func (c ReportConfigColumnType) ToPtr() *ReportConfigColumnType { + return &c +} + +// ReportConfigSortingDirection - Direction of sort. +type ReportConfigSortingDirection string + +const ( + ReportConfigSortingDirectionAscending ReportConfigSortingDirection = "Ascending" + ReportConfigSortingDirectionDescending ReportConfigSortingDirection = "Descending" +) + +// PossibleReportConfigSortingDirectionValues returns the possible values for the ReportConfigSortingDirection const type. +func PossibleReportConfigSortingDirectionValues() []ReportConfigSortingDirection { + return []ReportConfigSortingDirection{ + ReportConfigSortingDirectionAscending, + ReportConfigSortingDirectionDescending, + } +} + +// ToPtr returns a *ReportConfigSortingDirection pointing to the current value. +func (c ReportConfigSortingDirection) ToPtr() *ReportConfigSortingDirection { + return &c +} + +// ReportGranularityType - The granularity of rows in the report. +type ReportGranularityType string + +const ( + ReportGranularityTypeDaily ReportGranularityType = "Daily" + ReportGranularityTypeMonthly ReportGranularityType = "Monthly" +) + +// PossibleReportGranularityTypeValues returns the possible values for the ReportGranularityType const type. +func PossibleReportGranularityTypeValues() []ReportGranularityType { + return []ReportGranularityType{ + ReportGranularityTypeDaily, + ReportGranularityTypeMonthly, + } +} + +// ToPtr returns a *ReportGranularityType pointing to the current value. +func (c ReportGranularityType) ToPtr() *ReportGranularityType { + return &c +} + +// ReportTimeframeType - The time frame for pulling data for the report. If custom, then a specific time period must be provided. +type ReportTimeframeType string + +const ( + ReportTimeframeTypeCustom ReportTimeframeType = "Custom" + ReportTimeframeTypeMonthToDate ReportTimeframeType = "MonthToDate" + ReportTimeframeTypeWeekToDate ReportTimeframeType = "WeekToDate" + ReportTimeframeTypeYearToDate ReportTimeframeType = "YearToDate" +) + +// PossibleReportTimeframeTypeValues returns the possible values for the ReportTimeframeType const type. +func PossibleReportTimeframeTypeValues() []ReportTimeframeType { + return []ReportTimeframeType{ + ReportTimeframeTypeCustom, + ReportTimeframeTypeMonthToDate, + ReportTimeframeTypeWeekToDate, + ReportTimeframeTypeYearToDate, + } +} + +// ToPtr returns a *ReportTimeframeType pointing to the current value. +func (c ReportTimeframeType) ToPtr() *ReportTimeframeType { + return &c +} + +// ReportType - The type of the report. Usage represents actual usage, forecast represents forecasted data and UsageAndForecast represents both usage and +// forecasted data. Actual usage and forecasted data can be +// differentiated based on dates. +type ReportType string + +const ( + ReportTypeUsage ReportType = "Usage" +) + +// PossibleReportTypeValues returns the possible values for the ReportType const type. +func PossibleReportTypeValues() []ReportType { + return []ReportType{ + ReportTypeUsage, + } +} + +// ToPtr returns a *ReportType pointing to the current value. +func (c ReportType) ToPtr() *ReportType { + return &c +} + +// StatusType - The status of the export's schedule. If 'Inactive', the export's schedule is paused. +type StatusType string + +const ( + StatusTypeActive StatusType = "Active" + StatusTypeInactive StatusType = "Inactive" +) + +// PossibleStatusTypeValues returns the possible values for the StatusType const type. +func PossibleStatusTypeValues() []StatusType { + return []StatusType{ + StatusTypeActive, + StatusTypeInactive, + } +} + +// ToPtr returns a *StatusType pointing to the current value. +func (c StatusType) ToPtr() *StatusType { + return &c +} + +// TimeframeType - The time frame for pulling data for the export. If custom, then a specific time period must be provided. +type TimeframeType string + +const ( + TimeframeTypeBillingMonthToDate TimeframeType = "BillingMonthToDate" + TimeframeTypeCustom TimeframeType = "Custom" + TimeframeTypeMonthToDate TimeframeType = "MonthToDate" + TimeframeTypeTheLastBillingMonth TimeframeType = "TheLastBillingMonth" + TimeframeTypeTheLastMonth TimeframeType = "TheLastMonth" + TimeframeTypeWeekToDate TimeframeType = "WeekToDate" +) + +// PossibleTimeframeTypeValues returns the possible values for the TimeframeType const type. +func PossibleTimeframeTypeValues() []TimeframeType { + return []TimeframeType{ + TimeframeTypeBillingMonthToDate, + TimeframeTypeCustom, + TimeframeTypeMonthToDate, + TimeframeTypeTheLastBillingMonth, + TimeframeTypeTheLastMonth, + TimeframeTypeWeekToDate, + } +} + +// ToPtr returns a *TimeframeType pointing to the current value. +func (c TimeframeType) ToPtr() *TimeframeType { + return &c +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_dimensions_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_dimensions_client.go new file mode 100644 index 000000000000..7be777a0a08d --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_dimensions_client.go @@ -0,0 +1,182 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strconv" + "strings" +) + +// DimensionsClient contains the methods for the Dimensions group. +// Don't use this type directly, use NewDimensionsClient() instead. +type DimensionsClient struct { + ep string + pl runtime.Pipeline +} + +// NewDimensionsClient creates a new instance of DimensionsClient with the specified values. +func NewDimensionsClient(credential azcore.TokenCredential, options *arm.ClientOptions) *DimensionsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &DimensionsClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// ByExternalCloudProviderType - Lists the dimensions by the external cloud provider type. +// If the operation fails it returns the *ErrorResponse error type. +func (client *DimensionsClient) ByExternalCloudProviderType(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string, options *DimensionsByExternalCloudProviderTypeOptions) (DimensionsByExternalCloudProviderTypeResponse, error) { + req, err := client.byExternalCloudProviderTypeCreateRequest(ctx, externalCloudProviderType, externalCloudProviderID, options) + if err != nil { + return DimensionsByExternalCloudProviderTypeResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return DimensionsByExternalCloudProviderTypeResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return DimensionsByExternalCloudProviderTypeResponse{}, client.byExternalCloudProviderTypeHandleError(resp) + } + return client.byExternalCloudProviderTypeHandleResponse(resp) +} + +// byExternalCloudProviderTypeCreateRequest creates the ByExternalCloudProviderType request. +func (client *DimensionsClient) byExternalCloudProviderTypeCreateRequest(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string, options *DimensionsByExternalCloudProviderTypeOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/{externalCloudProviderType}/{externalCloudProviderId}/dimensions" + if externalCloudProviderType == "" { + return nil, errors.New("parameter externalCloudProviderType cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{externalCloudProviderType}", url.PathEscape(string(externalCloudProviderType))) + if externalCloudProviderID == "" { + return nil, errors.New("parameter externalCloudProviderID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{externalCloudProviderId}", url.PathEscape(externalCloudProviderID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + if options != nil && options.Filter != nil { + reqQP.Set("$filter", *options.Filter) + } + if options != nil && options.Expand != nil { + reqQP.Set("$expand", *options.Expand) + } + if options != nil && options.Skiptoken != nil { + reqQP.Set("$skiptoken", *options.Skiptoken) + } + if options != nil && options.Top != nil { + reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// byExternalCloudProviderTypeHandleResponse handles the ByExternalCloudProviderType response. +func (client *DimensionsClient) byExternalCloudProviderTypeHandleResponse(resp *http.Response) (DimensionsByExternalCloudProviderTypeResponse, error) { + result := DimensionsByExternalCloudProviderTypeResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.DimensionsListResult); err != nil { + return DimensionsByExternalCloudProviderTypeResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// byExternalCloudProviderTypeHandleError handles the ByExternalCloudProviderType error response. +func (client *DimensionsClient) byExternalCloudProviderTypeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// List - Lists the dimensions by the defined scope. +// If the operation fails it returns the *ErrorResponse error type. +func (client *DimensionsClient) List(ctx context.Context, scope string, options *DimensionsListOptions) (DimensionsListResponse, error) { + req, err := client.listCreateRequest(ctx, scope, options) + if err != nil { + return DimensionsListResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return DimensionsListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return DimensionsListResponse{}, client.listHandleError(resp) + } + return client.listHandleResponse(resp) +} + +// listCreateRequest creates the List request. +func (client *DimensionsClient) listCreateRequest(ctx context.Context, scope string, options *DimensionsListOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/dimensions" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + if options != nil && options.Filter != nil { + reqQP.Set("$filter", *options.Filter) + } + if options != nil && options.Expand != nil { + reqQP.Set("$expand", *options.Expand) + } + if options != nil && options.Skiptoken != nil { + reqQP.Set("$skiptoken", *options.Skiptoken) + } + if options != nil && options.Top != nil { + reqQP.Set("$top", strconv.FormatInt(int64(*options.Top), 10)) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *DimensionsClient) listHandleResponse(resp *http.Response) (DimensionsListResponse, error) { + result := DimensionsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.DimensionsListResult); err != nil { + return DimensionsListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *DimensionsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_exports_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_exports_client.go new file mode 100644 index 000000000000..11e702035e94 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_exports_client.go @@ -0,0 +1,376 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// ExportsClient contains the methods for the Exports group. +// Don't use this type directly, use NewExportsClient() instead. +type ExportsClient struct { + ep string + pl runtime.Pipeline +} + +// NewExportsClient creates a new instance of ExportsClient with the specified values. +func NewExportsClient(credential azcore.TokenCredential, options *arm.ClientOptions) *ExportsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &ExportsClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// CreateOrUpdate - The operation to create or update a export. Update operation requires latest eTag to be set in the request. You may obtain the latest +// eTag by performing a get operation. Create operation does not +// require eTag. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ExportsClient) CreateOrUpdate(ctx context.Context, scope string, exportName string, parameters Export, options *ExportsCreateOrUpdateOptions) (ExportsCreateOrUpdateResponse, error) { + req, err := client.createOrUpdateCreateRequest(ctx, scope, exportName, parameters, options) + if err != nil { + return ExportsCreateOrUpdateResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ExportsCreateOrUpdateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return ExportsCreateOrUpdateResponse{}, client.createOrUpdateHandleError(resp) + } + return client.createOrUpdateHandleResponse(resp) +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *ExportsClient) createOrUpdateCreateRequest(ctx context.Context, scope string, exportName string, parameters Export, options *ExportsCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/exports/{exportName}" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + if exportName == "" { + return nil, errors.New("parameter exportName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{exportName}", url.PathEscape(exportName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleResponse handles the CreateOrUpdate response. +func (client *ExportsClient) createOrUpdateHandleResponse(resp *http.Response) (ExportsCreateOrUpdateResponse, error) { + result := ExportsCreateOrUpdateResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Export); err != nil { + return ExportsCreateOrUpdateResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// createOrUpdateHandleError handles the CreateOrUpdate error response. +func (client *ExportsClient) createOrUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Delete - The operation to delete a export. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ExportsClient) Delete(ctx context.Context, scope string, exportName string, options *ExportsDeleteOptions) (ExportsDeleteResponse, error) { + req, err := client.deleteCreateRequest(ctx, scope, exportName, options) + if err != nil { + return ExportsDeleteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ExportsDeleteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ExportsDeleteResponse{}, client.deleteHandleError(resp) + } + return ExportsDeleteResponse{RawResponse: resp}, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *ExportsClient) deleteCreateRequest(ctx context.Context, scope string, exportName string, options *ExportsDeleteOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/exports/{exportName}" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + if exportName == "" { + return nil, errors.New("parameter exportName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{exportName}", url.PathEscape(exportName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *ExportsClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Execute - The operation to execute an export. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ExportsClient) Execute(ctx context.Context, scope string, exportName string, options *ExportsExecuteOptions) (ExportsExecuteResponse, error) { + req, err := client.executeCreateRequest(ctx, scope, exportName, options) + if err != nil { + return ExportsExecuteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ExportsExecuteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ExportsExecuteResponse{}, client.executeHandleError(resp) + } + return ExportsExecuteResponse{RawResponse: resp}, nil +} + +// executeCreateRequest creates the Execute request. +func (client *ExportsClient) executeCreateRequest(ctx context.Context, scope string, exportName string, options *ExportsExecuteOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/exports/{exportName}/run" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + if exportName == "" { + return nil, errors.New("parameter exportName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{exportName}", url.PathEscape(exportName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// executeHandleError handles the Execute error response. +func (client *ExportsClient) executeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - The operation to get the export for the defined scope by export name. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ExportsClient) Get(ctx context.Context, scope string, exportName string, options *ExportsGetOptions) (ExportsGetResponse, error) { + req, err := client.getCreateRequest(ctx, scope, exportName, options) + if err != nil { + return ExportsGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ExportsGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ExportsGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ExportsClient) getCreateRequest(ctx context.Context, scope string, exportName string, options *ExportsGetOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/exports/{exportName}" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + if exportName == "" { + return nil, errors.New("parameter exportName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{exportName}", url.PathEscape(exportName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + if options != nil && options.Expand != nil { + reqQP.Set("$expand", *options.Expand) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ExportsClient) getHandleResponse(resp *http.Response) (ExportsGetResponse, error) { + result := ExportsGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Export); err != nil { + return ExportsGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *ExportsClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetExecutionHistory - The operation to get the execution history of an export for the defined scope and export name. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ExportsClient) GetExecutionHistory(ctx context.Context, scope string, exportName string, options *ExportsGetExecutionHistoryOptions) (ExportsGetExecutionHistoryResponse, error) { + req, err := client.getExecutionHistoryCreateRequest(ctx, scope, exportName, options) + if err != nil { + return ExportsGetExecutionHistoryResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ExportsGetExecutionHistoryResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ExportsGetExecutionHistoryResponse{}, client.getExecutionHistoryHandleError(resp) + } + return client.getExecutionHistoryHandleResponse(resp) +} + +// getExecutionHistoryCreateRequest creates the GetExecutionHistory request. +func (client *ExportsClient) getExecutionHistoryCreateRequest(ctx context.Context, scope string, exportName string, options *ExportsGetExecutionHistoryOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/exports/{exportName}/runHistory" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + if exportName == "" { + return nil, errors.New("parameter exportName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{exportName}", url.PathEscape(exportName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getExecutionHistoryHandleResponse handles the GetExecutionHistory response. +func (client *ExportsClient) getExecutionHistoryHandleResponse(resp *http.Response) (ExportsGetExecutionHistoryResponse, error) { + result := ExportsGetExecutionHistoryResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ExportExecutionListResult); err != nil { + return ExportsGetExecutionHistoryResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getExecutionHistoryHandleError handles the GetExecutionHistory error response. +func (client *ExportsClient) getExecutionHistoryHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// List - The operation to list all exports at the given scope. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ExportsClient) List(ctx context.Context, scope string, options *ExportsListOptions) (ExportsListResponse, error) { + req, err := client.listCreateRequest(ctx, scope, options) + if err != nil { + return ExportsListResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ExportsListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ExportsListResponse{}, client.listHandleError(resp) + } + return client.listHandleResponse(resp) +} + +// listCreateRequest creates the List request. +func (client *ExportsClient) listCreateRequest(ctx context.Context, scope string, options *ExportsListOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/exports" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + if options != nil && options.Expand != nil { + reqQP.Set("$expand", *options.Expand) + } + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *ExportsClient) listHandleResponse(resp *http.Response) (ExportsListResponse, error) { + result := ExportsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ExportListResult); err != nil { + return ExportsListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *ExportsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_forecast_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_forecast_client.go new file mode 100644 index 000000000000..de2798683b4d --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_forecast_client.go @@ -0,0 +1,163 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// ForecastClient contains the methods for the Forecast group. +// Don't use this type directly, use NewForecastClient() instead. +type ForecastClient struct { + ep string + pl runtime.Pipeline +} + +// NewForecastClient creates a new instance of ForecastClient with the specified values. +func NewForecastClient(credential azcore.TokenCredential, options *arm.ClientOptions) *ForecastClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &ForecastClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// ExternalCloudProviderUsage - Lists the forecast charges for external cloud provider type defined. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ForecastClient) ExternalCloudProviderUsage(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string, parameters ForecastDefinition, options *ForecastExternalCloudProviderUsageOptions) (ForecastExternalCloudProviderUsageResponse, error) { + req, err := client.externalCloudProviderUsageCreateRequest(ctx, externalCloudProviderType, externalCloudProviderID, parameters, options) + if err != nil { + return ForecastExternalCloudProviderUsageResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ForecastExternalCloudProviderUsageResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ForecastExternalCloudProviderUsageResponse{}, client.externalCloudProviderUsageHandleError(resp) + } + return client.externalCloudProviderUsageHandleResponse(resp) +} + +// externalCloudProviderUsageCreateRequest creates the ExternalCloudProviderUsage request. +func (client *ForecastClient) externalCloudProviderUsageCreateRequest(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string, parameters ForecastDefinition, options *ForecastExternalCloudProviderUsageOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/{externalCloudProviderType}/{externalCloudProviderId}/forecast" + if externalCloudProviderType == "" { + return nil, errors.New("parameter externalCloudProviderType cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{externalCloudProviderType}", url.PathEscape(string(externalCloudProviderType))) + if externalCloudProviderID == "" { + return nil, errors.New("parameter externalCloudProviderID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{externalCloudProviderId}", url.PathEscape(externalCloudProviderID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.Filter != nil { + reqQP.Set("$filter", *options.Filter) + } + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// externalCloudProviderUsageHandleResponse handles the ExternalCloudProviderUsage response. +func (client *ForecastClient) externalCloudProviderUsageHandleResponse(resp *http.Response) (ForecastExternalCloudProviderUsageResponse, error) { + result := ForecastExternalCloudProviderUsageResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.QueryResult); err != nil { + return ForecastExternalCloudProviderUsageResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// externalCloudProviderUsageHandleError handles the ExternalCloudProviderUsage error response. +func (client *ForecastClient) externalCloudProviderUsageHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Usage - Lists the forecast charges for scope defined. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ForecastClient) Usage(ctx context.Context, scope string, parameters ForecastDefinition, options *ForecastUsageOptions) (ForecastUsageResponse, error) { + req, err := client.usageCreateRequest(ctx, scope, parameters, options) + if err != nil { + return ForecastUsageResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ForecastUsageResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return ForecastUsageResponse{}, client.usageHandleError(resp) + } + return client.usageHandleResponse(resp) +} + +// usageCreateRequest creates the Usage request. +func (client *ForecastClient) usageCreateRequest(ctx context.Context, scope string, parameters ForecastDefinition, options *ForecastUsageOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/forecast" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + if options != nil && options.Filter != nil { + reqQP.Set("$filter", *options.Filter) + } + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// usageHandleResponse handles the Usage response. +func (client *ForecastClient) usageHandleResponse(resp *http.Response) (ForecastUsageResponse, error) { + result := ForecastUsageResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.QueryResult); err != nil { + return ForecastUsageResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// usageHandleError handles the Usage error response. +func (client *ForecastClient) usageHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreport_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreport_client.go new file mode 100644 index 000000000000..b57b5ed7f6c1 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreport_client.go @@ -0,0 +1,113 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "strings" +) + +// GenerateDetailedCostReportClient contains the methods for the GenerateDetailedCostReport group. +// Don't use this type directly, use NewGenerateDetailedCostReportClient() instead. +type GenerateDetailedCostReportClient struct { + ep string + pl runtime.Pipeline +} + +// NewGenerateDetailedCostReportClient creates a new instance of GenerateDetailedCostReportClient with the specified values. +func NewGenerateDetailedCostReportClient(credential azcore.TokenCredential, options *arm.ClientOptions) *GenerateDetailedCostReportClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &GenerateDetailedCostReportClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// BeginCreateOperation - Generates the detailed cost report for provided date range, billing period(Only enterprise customers) or Invoice Id asynchronously +// at a certain scope. Call returns a 202 with header +// Azure-Consumption-AsyncOperation providing a link to the operation created. A call on the operation will provide the status and if the operation is completed +// the blob file where generated detailed +// cost report is being stored. +// If the operation fails it returns the *GenerateDetailedCostReportErrorResponse error type. +func (client *GenerateDetailedCostReportClient) BeginCreateOperation(ctx context.Context, scope string, parameters GenerateDetailedCostReportDefinition, options *GenerateDetailedCostReportBeginCreateOperationOptions) (GenerateDetailedCostReportCreateOperationPollerResponse, error) { + resp, err := client.createOperation(ctx, scope, parameters, options) + if err != nil { + return GenerateDetailedCostReportCreateOperationPollerResponse{}, err + } + result := GenerateDetailedCostReportCreateOperationPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("GenerateDetailedCostReportClient.CreateOperation", "location", resp, client.pl, client.createOperationHandleError) + if err != nil { + return GenerateDetailedCostReportCreateOperationPollerResponse{}, err + } + result.Poller = &GenerateDetailedCostReportCreateOperationPoller{ + pt: pt, + } + return result, nil +} + +// CreateOperation - Generates the detailed cost report for provided date range, billing period(Only enterprise customers) or Invoice Id asynchronously +// at a certain scope. Call returns a 202 with header +// Azure-Consumption-AsyncOperation providing a link to the operation created. A call on the operation will provide the status and if the operation is completed +// the blob file where generated detailed +// cost report is being stored. +// If the operation fails it returns the *GenerateDetailedCostReportErrorResponse error type. +func (client *GenerateDetailedCostReportClient) createOperation(ctx context.Context, scope string, parameters GenerateDetailedCostReportDefinition, options *GenerateDetailedCostReportBeginCreateOperationOptions) (*http.Response, error) { + req, err := client.createOperationCreateRequest(ctx, scope, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.createOperationHandleError(resp) + } + return resp, nil +} + +// createOperationCreateRequest creates the CreateOperation request. +func (client *GenerateDetailedCostReportClient) createOperationCreateRequest(ctx context.Context, scope string, parameters GenerateDetailedCostReportDefinition, options *GenerateDetailedCostReportBeginCreateOperationOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/generateDetailedCostReport" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOperationHandleError handles the CreateOperation error response. +func (client *GenerateDetailedCostReportClient) createOperationHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := GenerateDetailedCostReportErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreportoperationresults_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreportoperationresults_client.go new file mode 100644 index 000000000000..071c939a6328 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreportoperationresults_client.go @@ -0,0 +1,100 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// GenerateDetailedCostReportOperationResultsClient contains the methods for the GenerateDetailedCostReportOperationResults group. +// Don't use this type directly, use NewGenerateDetailedCostReportOperationResultsClient() instead. +type GenerateDetailedCostReportOperationResultsClient struct { + ep string + pl runtime.Pipeline +} + +// NewGenerateDetailedCostReportOperationResultsClient creates a new instance of GenerateDetailedCostReportOperationResultsClient with the specified values. +func NewGenerateDetailedCostReportOperationResultsClient(credential azcore.TokenCredential, options *arm.ClientOptions) *GenerateDetailedCostReportOperationResultsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &GenerateDetailedCostReportOperationResultsClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// Get - Get the result of the specified operation. This link is provided in the GenerateDetailedCostReport creation request response header. +// If the operation fails it returns the *ErrorResponse error type. +func (client *GenerateDetailedCostReportOperationResultsClient) Get(ctx context.Context, operationID string, scope string, options *GenerateDetailedCostReportOperationResultsGetOptions) (GenerateDetailedCostReportOperationResultsGetResponse, error) { + req, err := client.getCreateRequest(ctx, operationID, scope, options) + if err != nil { + return GenerateDetailedCostReportOperationResultsGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return GenerateDetailedCostReportOperationResultsGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return GenerateDetailedCostReportOperationResultsGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *GenerateDetailedCostReportOperationResultsClient) getCreateRequest(ctx context.Context, operationID string, scope string, options *GenerateDetailedCostReportOperationResultsGetOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/operationResults/{operationId}" + if operationID == "" { + return nil, errors.New("parameter operationID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID)) + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *GenerateDetailedCostReportOperationResultsClient) getHandleResponse(resp *http.Response) (GenerateDetailedCostReportOperationResultsGetResponse, error) { + result := GenerateDetailedCostReportOperationResultsGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.GenerateDetailedCostReportOperationResult); err != nil { + return GenerateDetailedCostReportOperationResultsGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *GenerateDetailedCostReportOperationResultsClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreportoperationstatus_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreportoperationstatus_client.go new file mode 100644 index 000000000000..b9a1c70e7b73 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_generatedetailedcostreportoperationstatus_client.go @@ -0,0 +1,100 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// GenerateDetailedCostReportOperationStatusClient contains the methods for the GenerateDetailedCostReportOperationStatus group. +// Don't use this type directly, use NewGenerateDetailedCostReportOperationStatusClient() instead. +type GenerateDetailedCostReportOperationStatusClient struct { + ep string + pl runtime.Pipeline +} + +// NewGenerateDetailedCostReportOperationStatusClient creates a new instance of GenerateDetailedCostReportOperationStatusClient with the specified values. +func NewGenerateDetailedCostReportOperationStatusClient(credential azcore.TokenCredential, options *arm.ClientOptions) *GenerateDetailedCostReportOperationStatusClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &GenerateDetailedCostReportOperationStatusClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// Get - Get the status of the specified operation. This link is provided in the GenerateDetailedCostReport creation request response header. +// If the operation fails it returns the *ErrorResponse error type. +func (client *GenerateDetailedCostReportOperationStatusClient) Get(ctx context.Context, operationID string, scope string, options *GenerateDetailedCostReportOperationStatusGetOptions) (GenerateDetailedCostReportOperationStatusGetResponse, error) { + req, err := client.getCreateRequest(ctx, operationID, scope, options) + if err != nil { + return GenerateDetailedCostReportOperationStatusGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return GenerateDetailedCostReportOperationStatusGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return GenerateDetailedCostReportOperationStatusGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *GenerateDetailedCostReportOperationStatusClient) getCreateRequest(ctx context.Context, operationID string, scope string, options *GenerateDetailedCostReportOperationStatusGetOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/operationStatus/{operationId}" + if operationID == "" { + return nil, errors.New("parameter operationID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{operationId}", url.PathEscape(operationID)) + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *GenerateDetailedCostReportOperationStatusClient) getHandleResponse(resp *http.Response) (GenerateDetailedCostReportOperationStatusGetResponse, error) { + result := GenerateDetailedCostReportOperationStatusGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.GenerateDetailedCostReportOperationStatuses); err != nil { + return GenerateDetailedCostReportOperationStatusGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *GenerateDetailedCostReportOperationStatusClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_models.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_models.go new file mode 100644 index 000000000000..a476fdbeccca --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_models.go @@ -0,0 +1,1779 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "encoding/json" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "time" +) + +// Alert - An individual alert. +type Alert struct { + ProxyResource + // Alert properties. + Properties *AlertProperties `json:"properties,omitempty"` +} + +// AlertProperties - Alert properties. +type AlertProperties struct { + // dateTime in which alert was closed + CloseTime *string `json:"closeTime,omitempty"` + + // related budget + CostEntityID *string `json:"costEntityId,omitempty"` + + // dateTime in which alert was created + CreationTime *string `json:"creationTime,omitempty"` + + // defines the type of alert + Definition *AlertPropertiesDefinition `json:"definition,omitempty"` + + // Alert description + Description *string `json:"description,omitempty"` + + // Alert details + Details *AlertPropertiesDetails `json:"details,omitempty"` + + // dateTime in which alert was last modified + ModificationTime *string `json:"modificationTime,omitempty"` + + // Source of alert + Source *AlertSource `json:"source,omitempty"` + + // alert status + Status *AlertStatus `json:"status,omitempty"` + + // dateTime in which the alert status was last modified + StatusModificationTime *string `json:"statusModificationTime,omitempty"` + + // User who last modified the alert + StatusModificationUserName *string `json:"statusModificationUserName,omitempty"` +} + +// AlertPropertiesDefinition - defines the type of alert +type AlertPropertiesDefinition struct { + // Alert category + Category *AlertCategory `json:"category,omitempty"` + + // Criteria that triggered alert + Criteria *AlertCriteria `json:"criteria,omitempty"` + + // type of alert + Type *AlertType `json:"type,omitempty"` +} + +// AlertPropertiesDetails - Alert details +type AlertPropertiesDetails struct { + // budget threshold amount + Amount *float64 `json:"amount,omitempty"` + + // list of emails to contact + ContactEmails []*string `json:"contactEmails,omitempty"` + + // list of action groups to broadcast to + ContactGroups []*string `json:"contactGroups,omitempty"` + + // list of contact roles + ContactRoles []*string `json:"contactRoles,omitempty"` + + // current spend + CurrentSpend *float64 `json:"currentSpend,omitempty"` + + // array of meters to filter by + MeterFilter []interface{} `json:"meterFilter,omitempty"` + + // operator used to compare currentSpend with amount + Operator *AlertOperator `json:"operator,omitempty"` + + // overriding alert + OverridingAlert *string `json:"overridingAlert,omitempty"` + + // datetime of periodStartDate + PeriodStartDate *string `json:"periodStartDate,omitempty"` + + // array of resources to filter by + ResourceFilter []interface{} `json:"resourceFilter,omitempty"` + + // array of resourceGroups to filter by + ResourceGroupFilter []interface{} `json:"resourceGroupFilter,omitempty"` + + // tags to filter by + TagFilter map[string]interface{} `json:"tagFilter,omitempty"` + + // notification threshold percentage as a decimal which activated this alert + Threshold *float64 `json:"threshold,omitempty"` + + // Type of timegrain cadence + TimeGrainType *AlertTimeGrainType `json:"timeGrainType,omitempty"` + + // notificationId that triggered this alert + TriggeredBy *string `json:"triggeredBy,omitempty"` + + // unit of currency being used + Unit *string `json:"unit,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertPropertiesDetails. +func (a AlertPropertiesDetails) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "amount", a.Amount) + populate(objectMap, "contactEmails", a.ContactEmails) + populate(objectMap, "contactGroups", a.ContactGroups) + populate(objectMap, "contactRoles", a.ContactRoles) + populate(objectMap, "currentSpend", a.CurrentSpend) + populate(objectMap, "meterFilter", a.MeterFilter) + populate(objectMap, "operator", a.Operator) + populate(objectMap, "overridingAlert", a.OverridingAlert) + populate(objectMap, "periodStartDate", a.PeriodStartDate) + populate(objectMap, "resourceFilter", a.ResourceFilter) + populate(objectMap, "resourceGroupFilter", a.ResourceGroupFilter) + populate(objectMap, "tagFilter", a.TagFilter) + populate(objectMap, "threshold", a.Threshold) + populate(objectMap, "timeGrainType", a.TimeGrainType) + populate(objectMap, "triggeredBy", a.TriggeredBy) + populate(objectMap, "unit", a.Unit) + return json.Marshal(objectMap) +} + +// AlertsDismissOptions contains the optional parameters for the Alerts.Dismiss method. +type AlertsDismissOptions struct { + // placeholder for future optional parameters +} + +// AlertsGetOptions contains the optional parameters for the Alerts.Get method. +type AlertsGetOptions struct { + // placeholder for future optional parameters +} + +// AlertsListExternalOptions contains the optional parameters for the Alerts.ListExternal method. +type AlertsListExternalOptions struct { + // placeholder for future optional parameters +} + +// AlertsListOptions contains the optional parameters for the Alerts.List method. +type AlertsListOptions struct { + // placeholder for future optional parameters +} + +// AlertsResult - Result of alerts. +type AlertsResult struct { + // READ-ONLY; URL to get the next set of alerts results if there are any. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; List of alerts. + Value []*Alert `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type AlertsResult. +func (a AlertsResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", a.NextLink) + populate(objectMap, "value", a.Value) + return json.Marshal(objectMap) +} + +// CommonExportProperties - The common properties of the export. +type CommonExportProperties struct { + // REQUIRED; Has the definition for the export. + Definition *ExportDefinition `json:"definition,omitempty"` + + // REQUIRED; Has delivery information for the export. + DeliveryInfo *ExportDeliveryInfo `json:"deliveryInfo,omitempty"` + + // The format of the export being delivered. Currently only 'Csv' is supported. + Format *FormatType `json:"format,omitempty"` + + // If set to true, exported data will be partitioned by size and placed in a blob directory together with a manifest file. Note: this option is currently + // available only for modern commerce scopes. + PartitionData *bool `json:"partitionData,omitempty"` + + // If requested, has the most recent execution history for the export. + RunHistory *ExportExecutionListResult `json:"runHistory,omitempty"` + + // READ-ONLY; If the export has an active schedule, provides an estimate of the next execution time. + NextRunTimeEstimate *time.Time `json:"nextRunTimeEstimate,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type CommonExportProperties. +func (c CommonExportProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + c.marshalInternal(objectMap) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type CommonExportProperties. +func (c *CommonExportProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + return c.unmarshalInternal(rawMsg) +} + +func (c CommonExportProperties) marshalInternal(objectMap map[string]interface{}) { + populate(objectMap, "definition", c.Definition) + populate(objectMap, "deliveryInfo", c.DeliveryInfo) + populate(objectMap, "format", c.Format) + populateTimeRFC3339(objectMap, "nextRunTimeEstimate", c.NextRunTimeEstimate) + populate(objectMap, "partitionData", c.PartitionData) + populate(objectMap, "runHistory", c.RunHistory) +} + +func (c *CommonExportProperties) unmarshalInternal(rawMsg map[string]json.RawMessage) error { + for key, val := range rawMsg { + var err error + switch key { + case "definition": + err = unpopulate(val, &c.Definition) + delete(rawMsg, key) + case "deliveryInfo": + err = unpopulate(val, &c.DeliveryInfo) + delete(rawMsg, key) + case "format": + err = unpopulate(val, &c.Format) + delete(rawMsg, key) + case "nextRunTimeEstimate": + err = unpopulateTimeRFC3339(val, &c.NextRunTimeEstimate) + delete(rawMsg, key) + case "partitionData": + err = unpopulate(val, &c.PartitionData) + delete(rawMsg, key) + case "runHistory": + err = unpopulate(val, &c.RunHistory) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// Dimension - List of Dimension. +type Dimension struct { + Resource + // Dimension properties. + Properties *DimensionProperties `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type Dimension. +func (d Dimension) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + d.Resource.marshalInternal(objectMap) + populate(objectMap, "properties", d.Properties) + return json.Marshal(objectMap) +} + +// DimensionProperties - Dimension properties. +type DimensionProperties struct { + // Dimension data. + Data []*string `json:"data,omitempty"` + + // READ-ONLY; Dimension category. + Category *string `json:"category,omitempty" azure:"ro"` + + // READ-ONLY; Dimension description. + Description *string `json:"description,omitempty" azure:"ro"` + + // READ-ONLY; Filter enabled. + FilterEnabled *bool `json:"filterEnabled,omitempty" azure:"ro"` + + // READ-ONLY; Grouping enabled. + GroupingEnabled *bool `json:"groupingEnabled,omitempty" azure:"ro"` + + // READ-ONLY; The link (url) to the next page of results. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; Total number of data for the dimension. + Total *int32 `json:"total,omitempty" azure:"ro"` + + // READ-ONLY; Usage end. + UsageEnd *time.Time `json:"usageEnd,omitempty" azure:"ro"` + + // READ-ONLY; Usage start. + UsageStart *time.Time `json:"usageStart,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type DimensionProperties. +func (d DimensionProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "category", d.Category) + populate(objectMap, "data", d.Data) + populate(objectMap, "description", d.Description) + populate(objectMap, "filterEnabled", d.FilterEnabled) + populate(objectMap, "groupingEnabled", d.GroupingEnabled) + populate(objectMap, "nextLink", d.NextLink) + populate(objectMap, "total", d.Total) + populateTimeRFC3339(objectMap, "usageEnd", d.UsageEnd) + populateTimeRFC3339(objectMap, "usageStart", d.UsageStart) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DimensionProperties. +func (d *DimensionProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "category": + err = unpopulate(val, &d.Category) + delete(rawMsg, key) + case "data": + err = unpopulate(val, &d.Data) + delete(rawMsg, key) + case "description": + err = unpopulate(val, &d.Description) + delete(rawMsg, key) + case "filterEnabled": + err = unpopulate(val, &d.FilterEnabled) + delete(rawMsg, key) + case "groupingEnabled": + err = unpopulate(val, &d.GroupingEnabled) + delete(rawMsg, key) + case "nextLink": + err = unpopulate(val, &d.NextLink) + delete(rawMsg, key) + case "total": + err = unpopulate(val, &d.Total) + delete(rawMsg, key) + case "usageEnd": + err = unpopulateTimeRFC3339(val, &d.UsageEnd) + delete(rawMsg, key) + case "usageStart": + err = unpopulateTimeRFC3339(val, &d.UsageStart) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// DimensionsByExternalCloudProviderTypeOptions contains the optional parameters for the Dimensions.ByExternalCloudProviderType method. +type DimensionsByExternalCloudProviderTypeOptions struct { + // May be used to expand the properties/data within a dimension category. By default, data is not included when listing dimensions. + Expand *string + // May be used to filter dimensions by properties/category, properties/usageStart, properties/usageEnd. Supported operators are 'eq','lt', 'gt', 'le', 'ge'. + Filter *string + // 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. + Skiptoken *string + // May be used to limit the number of results to the most recent N dimension data. + Top *int32 +} + +// DimensionsListOptions contains the optional parameters for the Dimensions.List method. +type DimensionsListOptions struct { + // May be used to expand the properties/data within a dimension category. By default, data is not included when listing dimensions. + Expand *string + // May be used to filter dimensions by properties/category, properties/usageStart, properties/usageEnd. Supported operators are 'eq','lt', 'gt', 'le', 'ge'. + Filter *string + // 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. + Skiptoken *string + // May be used to limit the number of results to the most recent N dimension data. + Top *int32 +} + +// DimensionsListResult - Result of listing dimensions. It contains a list of available dimensions. +type DimensionsListResult struct { + // READ-ONLY; The list of dimensions. + Value []*Dimension `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type DimensionsListResult. +func (d DimensionsListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "value", d.Value) + return json.Marshal(objectMap) +} + +// DismissAlertPayload - The request payload to update an alert +type DismissAlertPayload struct { + // Alert properties. + Properties *AlertProperties `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type DismissAlertPayload. +func (d DismissAlertPayload) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "properties", d.Properties) + return json.Marshal(objectMap) +} + +// DownloadURL - The URL to download the generated report. +type DownloadURL struct { + // The URL to download the generated report. + DownloadURL *string `json:"downloadUrl,omitempty"` + + // The time at which report URL becomes invalid/expires in UTC e.g. 2020-12-08T05:55:59.4394737Z. + ValidTill *time.Time `json:"validTill,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type DownloadURL. +func (d DownloadURL) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "downloadUrl", d.DownloadURL) + populateTimeRFC3339(objectMap, "validTill", d.ValidTill) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type DownloadURL. +func (d *DownloadURL) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "downloadUrl": + err = unpopulate(val, &d.DownloadURL) + delete(rawMsg, key) + case "validTill": + err = unpopulateTimeRFC3339(val, &d.ValidTill) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ErrorDetails - The details of the error. +type ErrorDetails struct { + // READ-ONLY; Error code. + Code *string `json:"code,omitempty" azure:"ro"` + + // READ-ONLY; Error message indicating why the operation failed. + Message *string `json:"message,omitempty" azure:"ro"` +} + +// ErrorResponse - Error response indicates that the service is not able to process the incoming request. The reason is provided in the error message. +// Some Error responses: +// * 429 TooManyRequests - Request is throttled. Retry after waiting for the time specified in the "x-ms-ratelimit-microsoft.consumption-retry-after" header. +// +// +// * 503 ServiceUnavailable - Service is temporarily unavailable. Retry after waiting for the time specified in the "Retry-After" header. +// Implements the error and azcore.HTTPResponse interfaces. +type ErrorResponse struct { + raw string + // The details of the error. + InnerError *ErrorDetails `json:"error,omitempty"` +} + +// Error implements the error interface for type ErrorResponse. +// The contents of the error text are not contractual and subject to change. +func (e ErrorResponse) Error() string { + return e.raw +} + +// Export - An export resource. +type Export struct { + ProxyResource + // The properties of the export. + Properties *ExportProperties `json:"properties,omitempty"` +} + +// ExportDataset - The definition for data in the export. +type ExportDataset struct { + // The export dataset configuration. + Configuration *ExportDatasetConfiguration `json:"configuration,omitempty"` + + // The granularity of rows in the export. Currently only 'Daily' is supported. + Granularity *GranularityType `json:"granularity,omitempty"` +} + +// ExportDatasetConfiguration - The export dataset configuration. Allows columns to be selected for the export. If not provided then the export will include +// all available columns. +type ExportDatasetConfiguration struct { + // Array of column names to be included in the export. If not provided then the export will include all available columns. The available columns can vary + // by customer channel (see examples). + Columns []*string `json:"columns,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ExportDatasetConfiguration. +func (e ExportDatasetConfiguration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "columns", e.Columns) + return json.Marshal(objectMap) +} + +// ExportDefinition - The definition of an export. +type ExportDefinition struct { + // REQUIRED; The time frame for pulling data for the export. If custom, then a specific time period must be provided. + Timeframe *TimeframeType `json:"timeframe,omitempty"` + + // REQUIRED; The type of the export. Note that 'Usage' is equivalent to 'ActualCost' and is applicable to exports that do not yet provide data for charges + // or amortization for service reservations. + Type *ExportType `json:"type,omitempty"` + + // The definition for data in the export. + DataSet *ExportDataset `json:"dataSet,omitempty"` + + // Has time period for pulling data for the export. + TimePeriod *ExportTimePeriod `json:"timePeriod,omitempty"` +} + +// ExportDeliveryDestination - This represents the blob storage account location where exports of costs will be delivered. There are two ways to configure +// the destination. The approach recommended for most customers is to specify +// the resourceId of the storage account. This requires a one-time registration of the account's subscription with the Microsoft.CostManagementExports resource +// provider in order to give Azure Cost +// Management services access to the storage. When creating an export in the Azure portal this registration is performed automatically but API users may +// need to register the subscription explicitly (for +// more information see https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-supported-services ). Another way to configure the +// destination is available ONLY to Partners with a +// Microsoft Partner Agreement plan who are global admins of their billing account. These Partners, instead of specifying the resourceId of a storage account, +// can specify the storage account name along +// with a SAS token for the account. This allows exports of costs to a storage account in any tenant. The SAS token should be created for the blob service +// with Service/Container/Object resource types and +// with Read/Write/Delete/List/Add/Create permissions (for more information see https://docs.microsoft.com/en-us/azure/cost-management-billing/costs/export-cost-data-storage-account-sas-key +// ). +type ExportDeliveryDestination struct { + // REQUIRED; The name of the container where exports will be uploaded. If the container does not exist it will be created. + Container *string `json:"container,omitempty"` + + // The resource id of the storage account where exports will be delivered. This is not required if a sasToken and storageAccount are specified. + ResourceID *string `json:"resourceId,omitempty"` + + // The name of the directory where exports will be uploaded. + RootFolderPath *string `json:"rootFolderPath,omitempty"` + + // A SAS token for the storage account. For a restricted set of Azure customers this together with storageAccount can be specified instead of resourceId. + // Note: the value returned by the API for this + // property will always be obfuscated. Returning this same obfuscated value will not result in the SAS token being updated. To update this value a new SAS + // token must be specified. + SasToken *string `json:"sasToken,omitempty"` + + // The storage account where exports will be uploaded. For a restricted set of Azure customers this together with sasToken can be specified instead of resourceId. + StorageAccount *string `json:"storageAccount,omitempty"` +} + +// ExportDeliveryInfo - The delivery information associated with a export. +type ExportDeliveryInfo struct { + // REQUIRED; Has destination for the export being delivered. + Destination *ExportDeliveryDestination `json:"destination,omitempty"` +} + +// ExportExecution - An export execution. +type ExportExecution struct { + ProxyResource + // The properties of the export execution. + Properties *ExportExecutionProperties `json:"properties,omitempty"` +} + +// ExportExecutionListResult - Result of listing the execution history of an export. +type ExportExecutionListResult struct { + // READ-ONLY; A list of export executions. + Value []*ExportExecution `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ExportExecutionListResult. +func (e ExportExecutionListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "value", e.Value) + return json.Marshal(objectMap) +} + +// ExportExecutionProperties - The properties of the export execution. +type ExportExecutionProperties struct { + // The details of any error. + Error *ErrorDetails `json:"error,omitempty"` + + // The type of the export execution. + ExecutionType *ExecutionType `json:"executionType,omitempty"` + + // The name of the exported file. + FileName *string `json:"fileName,omitempty"` + + // The time when the export execution finished. + ProcessingEndTime *time.Time `json:"processingEndTime,omitempty"` + + // The time when export was picked up to be executed. + ProcessingStartTime *time.Time `json:"processingStartTime,omitempty"` + + // The export settings that were in effect for this execution. + RunSettings *CommonExportProperties `json:"runSettings,omitempty"` + + // The last known status of the export execution. + Status *ExecutionStatus `json:"status,omitempty"` + + // The identifier for the entity that executed the export. For OnDemand executions it is the user email. For scheduled executions it is 'System'. + SubmittedBy *string `json:"submittedBy,omitempty"` + + // The time when export was queued to be executed. + SubmittedTime *time.Time `json:"submittedTime,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ExportExecutionProperties. +func (e ExportExecutionProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "error", e.Error) + populate(objectMap, "executionType", e.ExecutionType) + populate(objectMap, "fileName", e.FileName) + populateTimeRFC3339(objectMap, "processingEndTime", e.ProcessingEndTime) + populateTimeRFC3339(objectMap, "processingStartTime", e.ProcessingStartTime) + populate(objectMap, "runSettings", e.RunSettings) + populate(objectMap, "status", e.Status) + populate(objectMap, "submittedBy", e.SubmittedBy) + populateTimeRFC3339(objectMap, "submittedTime", e.SubmittedTime) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExportExecutionProperties. +func (e *ExportExecutionProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "error": + err = unpopulate(val, &e.Error) + delete(rawMsg, key) + case "executionType": + err = unpopulate(val, &e.ExecutionType) + delete(rawMsg, key) + case "fileName": + err = unpopulate(val, &e.FileName) + delete(rawMsg, key) + case "processingEndTime": + err = unpopulateTimeRFC3339(val, &e.ProcessingEndTime) + delete(rawMsg, key) + case "processingStartTime": + err = unpopulateTimeRFC3339(val, &e.ProcessingStartTime) + delete(rawMsg, key) + case "runSettings": + err = unpopulate(val, &e.RunSettings) + delete(rawMsg, key) + case "status": + err = unpopulate(val, &e.Status) + delete(rawMsg, key) + case "submittedBy": + err = unpopulate(val, &e.SubmittedBy) + delete(rawMsg, key) + case "submittedTime": + err = unpopulateTimeRFC3339(val, &e.SubmittedTime) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ExportListResult - Result of listing exports. It contains a list of available exports in the scope provided. +type ExportListResult struct { + // READ-ONLY; The list of exports. + Value []*Export `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ExportListResult. +func (e ExportListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "value", e.Value) + return json.Marshal(objectMap) +} + +// ExportProperties - The properties of the export. +type ExportProperties struct { + CommonExportProperties + // Has schedule information for the export. + Schedule *ExportSchedule `json:"schedule,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ExportProperties. +func (e ExportProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + e.CommonExportProperties.marshalInternal(objectMap) + populate(objectMap, "schedule", e.Schedule) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExportProperties. +func (e *ExportProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "schedule": + err = unpopulate(val, &e.Schedule) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + if err := e.CommonExportProperties.unmarshalInternal(rawMsg); err != nil { + return err + } + return nil +} + +// ExportRecurrencePeriod - The start and end date for recurrence schedule. +type ExportRecurrencePeriod struct { + // REQUIRED; The start date of recurrence. + From *time.Time `json:"from,omitempty"` + + // The end date of recurrence. + To *time.Time `json:"to,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ExportRecurrencePeriod. +func (e ExportRecurrencePeriod) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populateTimeRFC3339(objectMap, "from", e.From) + populateTimeRFC3339(objectMap, "to", e.To) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExportRecurrencePeriod. +func (e *ExportRecurrencePeriod) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "from": + err = unpopulateTimeRFC3339(val, &e.From) + delete(rawMsg, key) + case "to": + err = unpopulateTimeRFC3339(val, &e.To) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ExportSchedule - The schedule associated with the export. +type ExportSchedule struct { + // The schedule recurrence. + Recurrence *RecurrenceType `json:"recurrence,omitempty"` + + // Has start and end date of the recurrence. The start date must be in future. If present, the end date must be greater than start date. + RecurrencePeriod *ExportRecurrencePeriod `json:"recurrencePeriod,omitempty"` + + // The status of the export's schedule. If 'Inactive', the export's schedule is paused. + Status *StatusType `json:"status,omitempty"` +} + +// ExportTimePeriod - The date range for data in the export. This should only be specified with timeFrame set to 'Custom'. The maximum date range is 3 months. +type ExportTimePeriod struct { + // REQUIRED; The start date for export data. + From *time.Time `json:"from,omitempty"` + + // REQUIRED; The end date for export data. + To *time.Time `json:"to,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ExportTimePeriod. +func (e ExportTimePeriod) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populateTimeRFC3339(objectMap, "from", e.From) + populateTimeRFC3339(objectMap, "to", e.To) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ExportTimePeriod. +func (e *ExportTimePeriod) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "from": + err = unpopulateTimeRFC3339(val, &e.From) + delete(rawMsg, key) + case "to": + err = unpopulateTimeRFC3339(val, &e.To) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ExportsCreateOrUpdateOptions contains the optional parameters for the Exports.CreateOrUpdate method. +type ExportsCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// ExportsDeleteOptions contains the optional parameters for the Exports.Delete method. +type ExportsDeleteOptions struct { + // placeholder for future optional parameters +} + +// ExportsExecuteOptions contains the optional parameters for the Exports.Execute method. +type ExportsExecuteOptions struct { + // placeholder for future optional parameters +} + +// ExportsGetExecutionHistoryOptions contains the optional parameters for the Exports.GetExecutionHistory method. +type ExportsGetExecutionHistoryOptions struct { + // placeholder for future optional parameters +} + +// ExportsGetOptions contains the optional parameters for the Exports.Get method. +type ExportsGetOptions struct { + // May be used to expand the properties within an export. Currently only 'runHistory' is supported and will return information for the last 10 executions + // of the export. + Expand *string +} + +// ExportsListOptions contains the optional parameters for the Exports.List method. +type ExportsListOptions struct { + // May be used to expand the properties within an export. Currently only 'runHistory' is supported and will return information for the last execution of + // each export. + Expand *string +} + +// ForecastDataset - The definition of data present in the forecast. +type ForecastDataset struct { + // Dictionary of aggregation expression to use in the forecast. The key of each item in the dictionary is the alias for the aggregated column. forecast + // can have up to 2 aggregation clauses. + Aggregation map[string]*QueryAggregation `json:"aggregation,omitempty"` + + // Has configuration information for the data in the export. The configuration will be ignored if aggregation and grouping are provided. + Configuration *QueryDatasetConfiguration `json:"configuration,omitempty"` + + // Has filter expression to use in the forecast. + Filter *QueryFilter `json:"filter,omitempty"` + + // The granularity of rows in the forecast. + Granularity *GranularityType `json:"granularity,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ForecastDataset. +func (f ForecastDataset) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "aggregation", f.Aggregation) + populate(objectMap, "configuration", f.Configuration) + populate(objectMap, "filter", f.Filter) + populate(objectMap, "granularity", f.Granularity) + return json.Marshal(objectMap) +} + +// ForecastDefinition - The definition of a forecast. +type ForecastDefinition struct { + // REQUIRED; Has definition for data in this forecast. + Dataset *ForecastDataset `json:"dataset,omitempty"` + + // REQUIRED; The time frame for pulling data for the forecast. If custom, then a specific time period must be provided. + Timeframe *ForecastTimeframeType `json:"timeframe,omitempty"` + + // REQUIRED; The type of the forecast. + Type *ForecastType `json:"type,omitempty"` + + // a boolean determining if actualCost will be included + IncludeActualCost *bool `json:"includeActualCost,omitempty"` + + // a boolean determining if FreshPartialCost will be included + IncludeFreshPartialCost *bool `json:"includeFreshPartialCost,omitempty"` + + // Has time period for pulling data for the forecast. + TimePeriod *QueryTimePeriod `json:"timePeriod,omitempty"` +} + +// ForecastExternalCloudProviderUsageOptions contains the optional parameters for the Forecast.ExternalCloudProviderUsage method. +type ForecastExternalCloudProviderUsageOptions struct { + // May be used to filter forecasts by properties/usageDate (Utc time), properties/chargeType or properties/grain. The filter supports 'eq', 'lt', 'gt', + // 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. + Filter *string +} + +// ForecastUsageOptions contains the optional parameters for the Forecast.Usage method. +type ForecastUsageOptions struct { + // May be used to filter forecasts by properties/usageDate (Utc time), properties/chargeType or properties/grain. The filter supports 'eq', 'lt', 'gt', + // 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. + Filter *string +} + +// GenerateDetailedCostReportBeginCreateOperationOptions contains the optional parameters for the GenerateDetailedCostReport.BeginCreateOperation method. +type GenerateDetailedCostReportBeginCreateOperationOptions struct { + // placeholder for future optional parameters +} + +// GenerateDetailedCostReportDefinition - The definition of a cost detailed report. +type GenerateDetailedCostReportDefinition struct { + // Billing Period in YearMonth(e.g. 202008) format. Only for legacy enterprise customers can use this. Can only have one of either timePeriod or invoiceId + // or billingPeriod parameters. If none provided + // current month cost is provided. + BillingPeriod *string `json:"billingPeriod,omitempty"` + + // Customer Id for Modern (Invoice Id and billing profile is also required for this). + CustomerID *string `json:"customerId,omitempty"` + + // Invoice Id for PayAsYouGo customers and Modern billing profile scope. Can only have one of either timePeriod or invoiceId or billingPeriod parameters. + // If none provided current month cost is provided. + InvoiceID *string `json:"invoiceId,omitempty"` + + // The type of the detailed report. By default ActualCost is provided + Metric *GenerateDetailedCostReportMetricType `json:"metric,omitempty"` + + // Has time period for pulling data for the cost detailed report. Can only have one of either timePeriod or invoiceId or billingPeriod parameters. If none + // provided current month cost is provided. + TimePeriod *GenerateDetailedCostReportTimePeriod `json:"timePeriod,omitempty"` +} + +// GenerateDetailedCostReportErrorResponse - Error response indicates that the service is not able to process the incoming request. The reason is provided +// in the error message. +// Some Error responses: +// * 413 Request Entity Too Large - Request is throttled. The amount of data required to fulfill the request exceeds the maximum size permitted of 2Gb. +// Please utilize our Exports feature instead. +// +// +// * 429 TooManyRequests - Request is throttled. Retry after waiting for the time specified in the "x-ms-ratelimit-microsoft.consumption-retry-after" header. +// +// +// * 503 ServiceUnavailable - Service is temporarily unavailable. Retry after waiting for the time specified in the "Retry-After" header. +// Implements the error and azcore.HTTPResponse interfaces. +type GenerateDetailedCostReportErrorResponse struct { + raw string + // The details of the error. + InnerError *ErrorDetails `json:"error,omitempty"` +} + +// Error implements the error interface for type GenerateDetailedCostReportErrorResponse. +// The contents of the error text are not contractual and subject to change. +func (e GenerateDetailedCostReportErrorResponse) Error() string { + return e.raw +} + +// GenerateDetailedCostReportOperationResult - The result of the long running operation for cost detailed report. +type GenerateDetailedCostReportOperationResult struct { + // The id of the long running operation. + ID *string `json:"id,omitempty"` + + // The name of the long running operation. + Name *string `json:"name,omitempty"` + + // The properties of the resource generated. + Properties *DownloadURL `json:"properties,omitempty"` + + // The type of the long running operation. + Type *string `json:"type,omitempty"` +} + +// GenerateDetailedCostReportOperationResultsGetOptions contains the optional parameters for the GenerateDetailedCostReportOperationResults.Get method. +type GenerateDetailedCostReportOperationResultsGetOptions struct { + // placeholder for future optional parameters +} + +// GenerateDetailedCostReportOperationStatusGetOptions contains the optional parameters for the GenerateDetailedCostReportOperationStatus.Get method. +type GenerateDetailedCostReportOperationStatusGetOptions struct { + // placeholder for future optional parameters +} + +// GenerateDetailedCostReportOperationStatuses - The status of the long running operation for cost detailed report. +type GenerateDetailedCostReportOperationStatuses struct { + // The details of the error. + Error *ErrorDetails `json:"error,omitempty"` + + // The id of the long running operation. + ID *string `json:"id,omitempty"` + + // The name of the long running operation. + Name *string `json:"name,omitempty"` + + // The properties of the resource generated. + Properties *DownloadURL `json:"properties,omitempty"` + + // The status of the long running operation. + Status *Status `json:"status,omitempty"` + + // The type of the long running operation. + Type *string `json:"type,omitempty"` +} + +// GenerateDetailedCostReportTimePeriod - The start and end date for pulling data for the cost detailed report. +type GenerateDetailedCostReportTimePeriod struct { + // REQUIRED; The end date to pull data to. example format 2020-03-15 + End *string `json:"end,omitempty"` + + // REQUIRED; The start date to pull data from. example format 2020-03-15 + Start *string `json:"start,omitempty"` +} + +// KpiProperties - Each KPI must contain a 'type' and 'enabled' key. +type KpiProperties struct { + // show the KPI in the UI? + Enabled *bool `json:"enabled,omitempty"` + + // ID of resource related to metric (budget). + ID *string `json:"id,omitempty"` + + // KPI type (Forecast, Budget). + Type *KpiType `json:"type,omitempty"` +} + +// Operation - A Cost management REST API operation. +type Operation struct { + // The object that represents the operation. + Display *OperationDisplay `json:"display,omitempty"` + + // READ-ONLY; Operation name: {provider}/{resource}/{operation}. + Name *string `json:"name,omitempty" azure:"ro"` +} + +// OperationDisplay - The object that represents the operation. +type OperationDisplay struct { + // READ-ONLY; Operation type: Read, write, delete, etc. + Operation *string `json:"operation,omitempty" azure:"ro"` + + // READ-ONLY; Service provider: Microsoft.CostManagement. + Provider *string `json:"provider,omitempty" azure:"ro"` + + // READ-ONLY; Resource on which the operation is performed: Dimensions, Query. + Resource *string `json:"resource,omitempty" azure:"ro"` +} + +// OperationListResult - Result of listing cost management operations. It contains a list of operations and a URL link to get the next set of results. +type OperationListResult struct { + // READ-ONLY; URL to get the next set of operation list results if there are any. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; List of cost management operations supported by the Microsoft.CostManagement resource provider. + Value []*Operation `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// OperationsListOptions contains the optional parameters for the Operations.List method. +type OperationsListOptions struct { + // placeholder for future optional parameters +} + +// PivotProperties - Each pivot must contain a 'type' and 'name'. +type PivotProperties struct { + // Data field to show in view. + Name *string `json:"name,omitempty"` + + // Data type to show in view. + Type *PivotType `json:"type,omitempty"` +} + +// ProxyResource - The Resource model definition. +type ProxyResource struct { + // eTag of the resource. To handle concurrent update scenario, this field will be used to determine whether the user is updating the latest version or not. + ETag *string `json:"eTag,omitempty"` + + // READ-ONLY; Resource Id. + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; Resource name. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; Resource type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// QueryAggregation - The aggregation expression to be used in the query. +type QueryAggregation struct { + // REQUIRED; The name of the aggregation function to use. + Function *FunctionType `json:"function,omitempty"` + + // REQUIRED; The name of the column to aggregate. + Name *string `json:"name,omitempty"` +} + +// QueryColumn properties +type QueryColumn struct { + // The name of column. + Name *string `json:"name,omitempty"` + + // The type of column. + Type *string `json:"type,omitempty"` +} + +// QueryComparisonExpression - The comparison expression to be used in the query. +type QueryComparisonExpression struct { + // REQUIRED; The name of the column to use in comparison. + Name *string `json:"name,omitempty"` + + // REQUIRED; The operator to use for comparison. + Operator *QueryOperatorType `json:"operator,omitempty"` + + // REQUIRED; Array of values to use for comparison + Values []*string `json:"values,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type QueryComparisonExpression. +func (q QueryComparisonExpression) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "name", q.Name) + populate(objectMap, "operator", q.Operator) + populate(objectMap, "values", q.Values) + return json.Marshal(objectMap) +} + +// QueryDataset - The definition of data present in the query. +type QueryDataset struct { + // Dictionary of aggregation expression to use in the query. The key of each item in the dictionary is the alias for the aggregated column. Query can have + // up to 2 aggregation clauses. + Aggregation map[string]*QueryAggregation `json:"aggregation,omitempty"` + + // Has configuration information for the data in the export. The configuration will be ignored if aggregation and grouping are provided. + Configuration *QueryDatasetConfiguration `json:"configuration,omitempty"` + + // The filter expression to use in the query. Please reference our Query API REST documentation for how to properly format the filter. + Filter *QueryFilter `json:"filter,omitempty"` + + // The granularity of rows in the query. + Granularity *GranularityType `json:"granularity,omitempty"` + + // Array of group by expression to use in the query. Query can have up to 2 group by clauses. + Grouping []*QueryGrouping `json:"grouping,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type QueryDataset. +func (q QueryDataset) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "aggregation", q.Aggregation) + populate(objectMap, "configuration", q.Configuration) + populate(objectMap, "filter", q.Filter) + populate(objectMap, "granularity", q.Granularity) + populate(objectMap, "grouping", q.Grouping) + return json.Marshal(objectMap) +} + +// QueryDatasetConfiguration - The configuration of dataset in the query. +type QueryDatasetConfiguration struct { + // Array of column names to be included in the query. Any valid query column name is allowed. If not provided, then query includes all columns. + Columns []*string `json:"columns,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type QueryDatasetConfiguration. +func (q QueryDatasetConfiguration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "columns", q.Columns) + return json.Marshal(objectMap) +} + +// QueryDefinition - The definition of a query. +type QueryDefinition struct { + // REQUIRED; Has definition for data in this query. + Dataset *QueryDataset `json:"dataset,omitempty"` + + // REQUIRED; The time frame for pulling data for the query. If custom, then a specific time period must be provided. + Timeframe *TimeframeType `json:"timeframe,omitempty"` + + // REQUIRED; The type of the query. + Type *ExportType `json:"type,omitempty"` + + // Has time period for pulling data for the query. + TimePeriod *QueryTimePeriod `json:"timePeriod,omitempty"` +} + +// QueryFilter - The filter expression to be used in the export. +type QueryFilter struct { + // The logical "AND" expression. Must have at least 2 items. + And []*QueryFilter `json:"and,omitempty"` + + // Has comparison expression for a dimension + Dimension *QueryComparisonExpression `json:"dimension,omitempty"` + + // The logical "NOT" expression. + Not *QueryFilter `json:"not,omitempty"` + + // The logical "OR" expression. Must have at least 2 items. + Or []*QueryFilter `json:"or,omitempty"` + + // Has comparison expression for a tag + Tag *QueryComparisonExpression `json:"tag,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type QueryFilter. +func (q QueryFilter) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "and", q.And) + populate(objectMap, "dimension", q.Dimension) + populate(objectMap, "not", q.Not) + populate(objectMap, "or", q.Or) + populate(objectMap, "tag", q.Tag) + return json.Marshal(objectMap) +} + +// QueryGrouping - The group by expression to be used in the query. +type QueryGrouping struct { + // REQUIRED; The name of the column to group. + Name *string `json:"name,omitempty"` + + // REQUIRED; Has type of the column to group. + Type *QueryColumnType `json:"type,omitempty"` +} + +// QueryProperties - Query properties +type QueryProperties struct { + // Array of columns + Columns []*QueryColumn `json:"columns,omitempty"` + + // The link (url) to the next page of results. + NextLink *string `json:"nextLink,omitempty"` + + // Array of rows + Rows [][]interface{} `json:"rows,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type QueryProperties. +func (q QueryProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "columns", q.Columns) + populate(objectMap, "nextLink", q.NextLink) + populate(objectMap, "rows", q.Rows) + return json.Marshal(objectMap) +} + +// QueryResult - Result of query. It contains all columns listed under groupings and aggregation. +type QueryResult struct { + Resource + // Query properties + Properties *QueryProperties `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type QueryResult. +func (q QueryResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + q.Resource.marshalInternal(objectMap) + populate(objectMap, "properties", q.Properties) + return json.Marshal(objectMap) +} + +// QueryTimePeriod - The start and end date for pulling data for the query. +type QueryTimePeriod struct { + // REQUIRED; The start date to pull data from. + From *time.Time `json:"from,omitempty"` + + // REQUIRED; The end date to pull data to. + To *time.Time `json:"to,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type QueryTimePeriod. +func (q QueryTimePeriod) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populateTimeRFC3339(objectMap, "from", q.From) + populateTimeRFC3339(objectMap, "to", q.To) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type QueryTimePeriod. +func (q *QueryTimePeriod) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "from": + err = unpopulateTimeRFC3339(val, &q.From) + delete(rawMsg, key) + case "to": + err = unpopulateTimeRFC3339(val, &q.To) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// QueryUsageByExternalCloudProviderTypeOptions contains the optional parameters for the Query.UsageByExternalCloudProviderType method. +type QueryUsageByExternalCloudProviderTypeOptions struct { + // placeholder for future optional parameters +} + +// QueryUsageOptions contains the optional parameters for the Query.Usage method. +type QueryUsageOptions struct { + // placeholder for future optional parameters +} + +// ReportConfigAggregation - The aggregation expression to be used in the report. +type ReportConfigAggregation struct { + // REQUIRED; The name of the aggregation function to use. + Function *FunctionType `json:"function,omitempty"` + + // REQUIRED; The name of the column to aggregate. + Name *string `json:"name,omitempty"` +} + +// ReportConfigComparisonExpression - The comparison expression to be used in the report. +type ReportConfigComparisonExpression struct { + // REQUIRED; The name of the column to use in comparison. + Name *string `json:"name,omitempty"` + + // REQUIRED; The operator to use for comparison. + Operator *OperatorType `json:"operator,omitempty"` + + // REQUIRED; Array of values to use for comparison + Values []*string `json:"values,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ReportConfigComparisonExpression. +func (r ReportConfigComparisonExpression) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "name", r.Name) + populate(objectMap, "operator", r.Operator) + populate(objectMap, "values", r.Values) + return json.Marshal(objectMap) +} + +// ReportConfigDataset - The definition of data present in the report. +type ReportConfigDataset struct { + // Dictionary of aggregation expression to use in the report. The key of each item in the dictionary is the alias for the aggregated column. Report can + // have up to 2 aggregation clauses. + Aggregation map[string]*ReportConfigAggregation `json:"aggregation,omitempty"` + + // Has configuration information for the data in the report. The configuration will be ignored if aggregation and grouping are provided. + Configuration *ReportConfigDatasetConfiguration `json:"configuration,omitempty"` + + // Has filter expression to use in the report. + Filter *ReportConfigFilter `json:"filter,omitempty"` + + // The granularity of rows in the report. + Granularity *ReportGranularityType `json:"granularity,omitempty"` + + // Array of group by expression to use in the report. Report can have up to 2 group by clauses. + Grouping []*ReportConfigGrouping `json:"grouping,omitempty"` + + // Array of order by expression to use in the report. + Sorting []*ReportConfigSorting `json:"sorting,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ReportConfigDataset. +func (r ReportConfigDataset) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "aggregation", r.Aggregation) + populate(objectMap, "configuration", r.Configuration) + populate(objectMap, "filter", r.Filter) + populate(objectMap, "granularity", r.Granularity) + populate(objectMap, "grouping", r.Grouping) + populate(objectMap, "sorting", r.Sorting) + return json.Marshal(objectMap) +} + +// ReportConfigDatasetConfiguration - The configuration of dataset in the report. +type ReportConfigDatasetConfiguration struct { + // Array of column names to be included in the report. Any valid report column name is allowed. If not provided, then report includes all columns. + Columns []*string `json:"columns,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ReportConfigDatasetConfiguration. +func (r ReportConfigDatasetConfiguration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "columns", r.Columns) + return json.Marshal(objectMap) +} + +// ReportConfigDefinition - The definition of a report config. +type ReportConfigDefinition struct { + // REQUIRED; The time frame for pulling data for the report. If custom, then a specific time period must be provided. + Timeframe *ReportTimeframeType `json:"timeframe,omitempty"` + + // REQUIRED; The type of the report. Usage represents actual usage, forecast represents forecasted data and UsageAndForecast represents both usage and forecasted + // data. Actual usage and forecasted data can be + // differentiated based on dates. + Type *ReportType `json:"type,omitempty"` + + // Has definition for data in this report config. + DataSet *ReportConfigDataset `json:"dataSet,omitempty"` + + // If true, report includes monetary commitment. + IncludeMonetaryCommitment *bool `json:"includeMonetaryCommitment,omitempty"` + + // Has time period for pulling data for the report. + TimePeriod *ReportConfigTimePeriod `json:"timePeriod,omitempty"` +} + +// ReportConfigFilter - The filter expression to be used in the report. +type ReportConfigFilter struct { + // The logical "AND" expression. Must have at least 2 items. + And []*ReportConfigFilter `json:"and,omitempty"` + + // Has comparison expression for a dimension + Dimension *ReportConfigComparisonExpression `json:"dimension,omitempty"` + + // The logical "NOT" expression. + Not *ReportConfigFilter `json:"not,omitempty"` + + // The logical "OR" expression. Must have at least 2 items. + Or []*ReportConfigFilter `json:"or,omitempty"` + + // Has comparison expression for a tag + Tag *ReportConfigComparisonExpression `json:"tag,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ReportConfigFilter. +func (r ReportConfigFilter) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "and", r.And) + populate(objectMap, "dimension", r.Dimension) + populate(objectMap, "not", r.Not) + populate(objectMap, "or", r.Or) + populate(objectMap, "tag", r.Tag) + return json.Marshal(objectMap) +} + +// ReportConfigGrouping - The group by expression to be used in the report. +type ReportConfigGrouping struct { + // REQUIRED; The name of the column to group. This version supports subscription lowest possible grain. + Name *string `json:"name,omitempty"` + + // REQUIRED; Has type of the column to group. + Type *ReportConfigColumnType `json:"type,omitempty"` +} + +// ReportConfigSorting - The order by expression to be used in the report. +type ReportConfigSorting struct { + // REQUIRED; The name of the column to sort. + Name *string `json:"name,omitempty"` + + // Direction of sort. + Direction *ReportConfigSortingDirection `json:"direction,omitempty"` +} + +// ReportConfigTimePeriod - The start and end date for pulling data for the report. +type ReportConfigTimePeriod struct { + // REQUIRED; The start date to pull data from. + From *time.Time `json:"from,omitempty"` + + // REQUIRED; The end date to pull data to. + To *time.Time `json:"to,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ReportConfigTimePeriod. +func (r ReportConfigTimePeriod) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populateTimeRFC3339(objectMap, "from", r.From) + populateTimeRFC3339(objectMap, "to", r.To) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ReportConfigTimePeriod. +func (r *ReportConfigTimePeriod) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "from": + err = unpopulateTimeRFC3339(val, &r.From) + delete(rawMsg, key) + case "to": + err = unpopulateTimeRFC3339(val, &r.To) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// Resource - The Resource model definition. +type Resource struct { + // READ-ONLY; ETag of the resource. + ETag *string `json:"eTag,omitempty" azure:"ro"` + + // READ-ONLY; Resource Id. + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; Location of the resource. + Location *string `json:"location,omitempty" azure:"ro"` + + // READ-ONLY; Resource name. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; SKU of the resource. + SKU *string `json:"sku,omitempty" azure:"ro"` + + // READ-ONLY; Resource tags. + Tags map[string]*string `json:"tags,omitempty" azure:"ro"` + + // READ-ONLY; Resource type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Resource. +func (r Resource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + r.marshalInternal(objectMap) + return json.Marshal(objectMap) +} + +func (r Resource) marshalInternal(objectMap map[string]interface{}) { + populate(objectMap, "eTag", r.ETag) + populate(objectMap, "id", r.ID) + populate(objectMap, "location", r.Location) + populate(objectMap, "name", r.Name) + populate(objectMap, "sku", r.SKU) + populate(objectMap, "tags", r.Tags) + populate(objectMap, "type", r.Type) +} + +// ResourceAutoGenerated - The Resource model definition. +type ResourceAutoGenerated struct { + // READ-ONLY; Resource Id. + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; Resource name. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; Resource tags. + Tags map[string]*string `json:"tags,omitempty" azure:"ro"` + + // READ-ONLY; Resource type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ResourceAutoGenerated. +func (r ResourceAutoGenerated) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "id", r.ID) + populate(objectMap, "name", r.Name) + populate(objectMap, "tags", r.Tags) + populate(objectMap, "type", r.Type) + return json.Marshal(objectMap) +} + +// Status - The status of the long running operation. +type Status struct { + // The status of the long running operation. + Status *OperationStatusType `json:"status,omitempty"` +} + +// View - States and configurations of Cost Analysis. +type View struct { + ProxyResource + // The properties of the view. + Properties *ViewProperties `json:"properties,omitempty"` +} + +// ViewListResult - Result of listing views. It contains a list of available views. +type ViewListResult struct { + // READ-ONLY; The link (url) to the next page of results. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; The list of views. + Value []*View `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ViewListResult. +func (v ViewListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", v.NextLink) + populate(objectMap, "value", v.Value) + return json.Marshal(objectMap) +} + +// ViewProperties - The properties of the view. +type ViewProperties struct { + // Show costs accumulated over time. + Accumulated *AccumulatedType `json:"accumulated,omitempty"` + + // Chart type of the main view in Cost Analysis. Required. + Chart *ChartType `json:"chart,omitempty"` + + // User input name of the view. Required. + DisplayName *string `json:"displayName,omitempty"` + + // List of KPIs to show in Cost Analysis UI. + Kpis []*KpiProperties `json:"kpis,omitempty"` + + // Metric to use when displaying costs. + Metric *MetricType `json:"metric,omitempty"` + + // Configuration of 3 sub-views in the Cost Analysis UI. + Pivots []*PivotProperties `json:"pivots,omitempty"` + + // Query body configuration. Required. + Query *ReportConfigDefinition `json:"query,omitempty"` + + // Cost Management scope to save the view on. This includes 'subscriptions/{subscriptionId}' for subscription scope, 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' + // for resourceGroup + // scope, 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope, 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' + // for + // Department scope, 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for EnrollmentAccount scope, + // 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for BillingProfile scope, + // 'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for InvoiceSection scope, 'providers/Microsoft.Management/managementGroups/{managementGroupId}' + // for + // Management Group scope, '/providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for ExternalBillingAccount scope, + // and + // '/providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for ExternalSubscription scope. + Scope *string `json:"scope,omitempty"` + + // READ-ONLY; Date the user created this view. + CreatedOn *time.Time `json:"createdOn,omitempty" azure:"ro"` + + // READ-ONLY; Currency of the current view. + Currency *string `json:"currency,omitempty" azure:"ro"` + + // READ-ONLY; Date range of the current view. + DateRange *string `json:"dateRange,omitempty" azure:"ro"` + + // READ-ONLY; Date when the user last modified this view. + ModifiedOn *time.Time `json:"modifiedOn,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ViewProperties. +func (v ViewProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "accumulated", v.Accumulated) + populate(objectMap, "chart", v.Chart) + populateTimeRFC3339(objectMap, "createdOn", v.CreatedOn) + populate(objectMap, "currency", v.Currency) + populate(objectMap, "dateRange", v.DateRange) + populate(objectMap, "displayName", v.DisplayName) + populate(objectMap, "kpis", v.Kpis) + populate(objectMap, "metric", v.Metric) + populateTimeRFC3339(objectMap, "modifiedOn", v.ModifiedOn) + populate(objectMap, "pivots", v.Pivots) + populate(objectMap, "query", v.Query) + populate(objectMap, "scope", v.Scope) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ViewProperties. +func (v *ViewProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "accumulated": + err = unpopulate(val, &v.Accumulated) + delete(rawMsg, key) + case "chart": + err = unpopulate(val, &v.Chart) + delete(rawMsg, key) + case "createdOn": + err = unpopulateTimeRFC3339(val, &v.CreatedOn) + delete(rawMsg, key) + case "currency": + err = unpopulate(val, &v.Currency) + delete(rawMsg, key) + case "dateRange": + err = unpopulate(val, &v.DateRange) + delete(rawMsg, key) + case "displayName": + err = unpopulate(val, &v.DisplayName) + delete(rawMsg, key) + case "kpis": + err = unpopulate(val, &v.Kpis) + delete(rawMsg, key) + case "metric": + err = unpopulate(val, &v.Metric) + delete(rawMsg, key) + case "modifiedOn": + err = unpopulateTimeRFC3339(val, &v.ModifiedOn) + delete(rawMsg, key) + case "pivots": + err = unpopulate(val, &v.Pivots) + delete(rawMsg, key) + case "query": + err = unpopulate(val, &v.Query) + delete(rawMsg, key) + case "scope": + err = unpopulate(val, &v.Scope) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ViewsCreateOrUpdateByScopeOptions contains the optional parameters for the Views.CreateOrUpdateByScope method. +type ViewsCreateOrUpdateByScopeOptions struct { + // placeholder for future optional parameters +} + +// ViewsCreateOrUpdateOptions contains the optional parameters for the Views.CreateOrUpdate method. +type ViewsCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// ViewsDeleteByScopeOptions contains the optional parameters for the Views.DeleteByScope method. +type ViewsDeleteByScopeOptions struct { + // placeholder for future optional parameters +} + +// ViewsDeleteOptions contains the optional parameters for the Views.Delete method. +type ViewsDeleteOptions struct { + // placeholder for future optional parameters +} + +// ViewsGetByScopeOptions contains the optional parameters for the Views.GetByScope method. +type ViewsGetByScopeOptions struct { + // placeholder for future optional parameters +} + +// ViewsGetOptions contains the optional parameters for the Views.Get method. +type ViewsGetOptions struct { + // placeholder for future optional parameters +} + +// ViewsListByScopeOptions contains the optional parameters for the Views.ListByScope method. +type ViewsListByScopeOptions struct { + // placeholder for future optional parameters +} + +// ViewsListOptions contains the optional parameters for the Views.List method. +type ViewsListOptions struct { + // placeholder for future optional parameters +} + +func populate(m map[string]interface{}, k string, v interface{}) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, v interface{}) error { + if data == nil { + return nil + } + return json.Unmarshal(data, v) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_operations_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_operations_client.go new file mode 100644 index 000000000000..fac9f79cd8f3 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_operations_client.go @@ -0,0 +1,89 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" +) + +// OperationsClient contains the methods for the Operations group. +// Don't use this type directly, use NewOperationsClient() instead. +type OperationsClient struct { + ep string + pl runtime.Pipeline +} + +// NewOperationsClient creates a new instance of OperationsClient with the specified values. +func NewOperationsClient(credential azcore.TokenCredential, options *arm.ClientOptions) *OperationsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &OperationsClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// List - Lists all of the available cost management REST API operations. +// If the operation fails it returns the *ErrorResponse error type. +func (client *OperationsClient) List(options *OperationsListOptions) *OperationsListPager { + return &OperationsListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp OperationsListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.OperationListResult.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/operations" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsListResponse, error) { + result := OperationsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.OperationListResult); err != nil { + return OperationsListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *OperationsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_pagers.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_pagers.go new file mode 100644 index 000000000000..67718cd2b084 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_pagers.go @@ -0,0 +1,179 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "reflect" +) + +// OperationsListPager provides operations for iterating over paged responses. +type OperationsListPager struct { + client *OperationsClient + current OperationsListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, OperationsListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *OperationsListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *OperationsListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.OperationListResult.NextLink == nil || len(*p.current.OperationListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current OperationsListResponse page. +func (p *OperationsListPager) PageResponse() OperationsListResponse { + return p.current +} + +// ViewsListByScopePager provides operations for iterating over paged responses. +type ViewsListByScopePager struct { + client *ViewsClient + current ViewsListByScopeResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ViewsListByScopeResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ViewsListByScopePager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ViewsListByScopePager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ViewListResult.NextLink == nil || len(*p.current.ViewListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByScopeHandleError(resp) + return false + } + result, err := p.client.listByScopeHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ViewsListByScopeResponse page. +func (p *ViewsListByScopePager) PageResponse() ViewsListByScopeResponse { + return p.current +} + +// ViewsListPager provides operations for iterating over paged responses. +type ViewsListPager struct { + client *ViewsClient + current ViewsListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ViewsListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ViewsListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ViewsListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ViewListResult.NextLink == nil || len(*p.current.ViewListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ViewsListResponse page. +func (p *ViewsListPager) PageResponse() ViewsListResponse { + return p.current +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_pollers.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_pollers.go new file mode 100644 index 000000000000..957781bf2e3c --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_pollers.go @@ -0,0 +1,58 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "net/http" +) + +// GenerateDetailedCostReportCreateOperationPoller provides polling facilities until the operation reaches a terminal state. +type GenerateDetailedCostReportCreateOperationPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *GenerateDetailedCostReportCreateOperationPoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *GenerateDetailedCostReportCreateOperationPoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final GenerateDetailedCostReportCreateOperationResponse will be returned. +func (p *GenerateDetailedCostReportCreateOperationPoller) FinalResponse(ctx context.Context) (GenerateDetailedCostReportCreateOperationResponse, error) { + respType := GenerateDetailedCostReportCreateOperationResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.GenerateDetailedCostReportOperationResult) + if err != nil { + return GenerateDetailedCostReportCreateOperationResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *GenerateDetailedCostReportCreateOperationPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_query_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_query_client.go new file mode 100644 index 000000000000..2cdcc17b8936 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_query_client.go @@ -0,0 +1,157 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// QueryClient contains the methods for the Query group. +// Don't use this type directly, use NewQueryClient() instead. +type QueryClient struct { + ep string + pl runtime.Pipeline +} + +// NewQueryClient creates a new instance of QueryClient with the specified values. +func NewQueryClient(credential azcore.TokenCredential, options *arm.ClientOptions) *QueryClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &QueryClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// Usage - Query the usage data for scope defined. +// If the operation fails it returns the *ErrorResponse error type. +func (client *QueryClient) Usage(ctx context.Context, scope string, parameters QueryDefinition, options *QueryUsageOptions) (QueryUsageResponse, error) { + req, err := client.usageCreateRequest(ctx, scope, parameters, options) + if err != nil { + return QueryUsageResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return QueryUsageResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return QueryUsageResponse{}, client.usageHandleError(resp) + } + return client.usageHandleResponse(resp) +} + +// usageCreateRequest creates the Usage request. +func (client *QueryClient) usageCreateRequest(ctx context.Context, scope string, parameters QueryDefinition, options *QueryUsageOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/query" + urlPath = strings.ReplaceAll(urlPath, "{scope}", scope) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// usageHandleResponse handles the Usage response. +func (client *QueryClient) usageHandleResponse(resp *http.Response) (QueryUsageResponse, error) { + result := QueryUsageResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.QueryResult); err != nil { + return QueryUsageResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// usageHandleError handles the Usage error response. +func (client *QueryClient) usageHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// UsageByExternalCloudProviderType - Query the usage data for external cloud provider type defined. +// If the operation fails it returns the *ErrorResponse error type. +func (client *QueryClient) UsageByExternalCloudProviderType(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string, parameters QueryDefinition, options *QueryUsageByExternalCloudProviderTypeOptions) (QueryUsageByExternalCloudProviderTypeResponse, error) { + req, err := client.usageByExternalCloudProviderTypeCreateRequest(ctx, externalCloudProviderType, externalCloudProviderID, parameters, options) + if err != nil { + return QueryUsageByExternalCloudProviderTypeResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return QueryUsageByExternalCloudProviderTypeResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return QueryUsageByExternalCloudProviderTypeResponse{}, client.usageByExternalCloudProviderTypeHandleError(resp) + } + return client.usageByExternalCloudProviderTypeHandleResponse(resp) +} + +// usageByExternalCloudProviderTypeCreateRequest creates the UsageByExternalCloudProviderType request. +func (client *QueryClient) usageByExternalCloudProviderTypeCreateRequest(ctx context.Context, externalCloudProviderType ExternalCloudProviderType, externalCloudProviderID string, parameters QueryDefinition, options *QueryUsageByExternalCloudProviderTypeOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/{externalCloudProviderType}/{externalCloudProviderId}/query" + if externalCloudProviderType == "" { + return nil, errors.New("parameter externalCloudProviderType cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{externalCloudProviderType}", url.PathEscape(string(externalCloudProviderType))) + if externalCloudProviderID == "" { + return nil, errors.New("parameter externalCloudProviderID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{externalCloudProviderId}", url.PathEscape(externalCloudProviderID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// usageByExternalCloudProviderTypeHandleResponse handles the UsageByExternalCloudProviderType response. +func (client *QueryClient) usageByExternalCloudProviderTypeHandleResponse(resp *http.Response) (QueryUsageByExternalCloudProviderTypeResponse, error) { + result := QueryUsageByExternalCloudProviderTypeResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.QueryResult); err != nil { + return QueryUsageByExternalCloudProviderTypeResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// usageByExternalCloudProviderTypeHandleError handles the UsageByExternalCloudProviderType error response. +func (client *QueryClient) usageByExternalCloudProviderTypeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_response_types.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_response_types.go new file mode 100644 index 000000000000..8ea087cc1d06 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_response_types.go @@ -0,0 +1,368 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "net/http" + "time" +) + +// AlertsDismissResponse contains the response from method Alerts.Dismiss. +type AlertsDismissResponse struct { + AlertsDismissResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsDismissResult contains the result from method Alerts.Dismiss. +type AlertsDismissResult struct { + Alert +} + +// AlertsGetResponse contains the response from method Alerts.Get. +type AlertsGetResponse struct { + AlertsGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsGetResult contains the result from method Alerts.Get. +type AlertsGetResult struct { + Alert +} + +// AlertsListExternalResponse contains the response from method Alerts.ListExternal. +type AlertsListExternalResponse struct { + AlertsListExternalResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsListExternalResult contains the result from method Alerts.ListExternal. +type AlertsListExternalResult struct { + AlertsResult +} + +// AlertsListResponse contains the response from method Alerts.List. +type AlertsListResponse struct { + AlertsListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AlertsListResult contains the result from method Alerts.List. +type AlertsListResult struct { + AlertsResult +} + +// DimensionsByExternalCloudProviderTypeResponse contains the response from method Dimensions.ByExternalCloudProviderType. +type DimensionsByExternalCloudProviderTypeResponse struct { + DimensionsByExternalCloudProviderTypeResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// DimensionsByExternalCloudProviderTypeResult contains the result from method Dimensions.ByExternalCloudProviderType. +type DimensionsByExternalCloudProviderTypeResult struct { + DimensionsListResult +} + +// DimensionsListResponse contains the response from method Dimensions.List. +type DimensionsListResponse struct { + DimensionsListResultEnvelope + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// DimensionsListResultEnvelope contains the result from method Dimensions.List. +type DimensionsListResultEnvelope struct { + DimensionsListResult +} + +// ExportsCreateOrUpdateResponse contains the response from method Exports.CreateOrUpdate. +type ExportsCreateOrUpdateResponse struct { + ExportsCreateOrUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ExportsCreateOrUpdateResult contains the result from method Exports.CreateOrUpdate. +type ExportsCreateOrUpdateResult struct { + Export +} + +// ExportsDeleteResponse contains the response from method Exports.Delete. +type ExportsDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ExportsExecuteResponse contains the response from method Exports.Execute. +type ExportsExecuteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ExportsGetExecutionHistoryResponse contains the response from method Exports.GetExecutionHistory. +type ExportsGetExecutionHistoryResponse struct { + ExportsGetExecutionHistoryResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ExportsGetExecutionHistoryResult contains the result from method Exports.GetExecutionHistory. +type ExportsGetExecutionHistoryResult struct { + ExportExecutionListResult +} + +// ExportsGetResponse contains the response from method Exports.Get. +type ExportsGetResponse struct { + ExportsGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ExportsGetResult contains the result from method Exports.Get. +type ExportsGetResult struct { + Export +} + +// ExportsListResponse contains the response from method Exports.List. +type ExportsListResponse struct { + ExportsListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ExportsListResult contains the result from method Exports.List. +type ExportsListResult struct { + ExportListResult +} + +// ForecastExternalCloudProviderUsageResponse contains the response from method Forecast.ExternalCloudProviderUsage. +type ForecastExternalCloudProviderUsageResponse struct { + ForecastExternalCloudProviderUsageResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ForecastExternalCloudProviderUsageResult contains the result from method Forecast.ExternalCloudProviderUsage. +type ForecastExternalCloudProviderUsageResult struct { + QueryResult +} + +// ForecastUsageResponse contains the response from method Forecast.Usage. +type ForecastUsageResponse struct { + ForecastUsageResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ForecastUsageResult contains the result from method Forecast.Usage. +type ForecastUsageResult struct { + QueryResult +} + +// GenerateDetailedCostReportCreateOperationPollerResponse contains the response from method GenerateDetailedCostReport.CreateOperation. +type GenerateDetailedCostReportCreateOperationPollerResponse struct { + // Poller contains an initialized poller. + Poller *GenerateDetailedCostReportCreateOperationPoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +// freq: the time to wait between intervals in absence of a Retry-After header. Allowed minimum is one second. +// A good starting value is 30 seconds. Note that some resources might benefit from a different value. +func (l GenerateDetailedCostReportCreateOperationPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (GenerateDetailedCostReportCreateOperationResponse, error) { + respType := GenerateDetailedCostReportCreateOperationResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.GenerateDetailedCostReportOperationResult) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a GenerateDetailedCostReportCreateOperationPollerResponse from the provided client and resume token. +func (l *GenerateDetailedCostReportCreateOperationPollerResponse) Resume(ctx context.Context, client *GenerateDetailedCostReportClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("GenerateDetailedCostReportClient.CreateOperation", token, client.pl, client.createOperationHandleError) + if err != nil { + return err + } + poller := &GenerateDetailedCostReportCreateOperationPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// GenerateDetailedCostReportCreateOperationResponse contains the response from method GenerateDetailedCostReport.CreateOperation. +type GenerateDetailedCostReportCreateOperationResponse struct { + GenerateDetailedCostReportCreateOperationResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// GenerateDetailedCostReportCreateOperationResult contains the result from method GenerateDetailedCostReport.CreateOperation. +type GenerateDetailedCostReportCreateOperationResult struct { + GenerateDetailedCostReportOperationResult +} + +// GenerateDetailedCostReportOperationResultsGetResponse contains the response from method GenerateDetailedCostReportOperationResults.Get. +type GenerateDetailedCostReportOperationResultsGetResponse struct { + GenerateDetailedCostReportOperationResultsGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// GenerateDetailedCostReportOperationResultsGetResult contains the result from method GenerateDetailedCostReportOperationResults.Get. +type GenerateDetailedCostReportOperationResultsGetResult struct { + GenerateDetailedCostReportOperationResult +} + +// GenerateDetailedCostReportOperationStatusGetResponse contains the response from method GenerateDetailedCostReportOperationStatus.Get. +type GenerateDetailedCostReportOperationStatusGetResponse struct { + GenerateDetailedCostReportOperationStatusGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// GenerateDetailedCostReportOperationStatusGetResult contains the result from method GenerateDetailedCostReportOperationStatus.Get. +type GenerateDetailedCostReportOperationStatusGetResult struct { + GenerateDetailedCostReportOperationStatuses +} + +// OperationsListResponse contains the response from method Operations.List. +type OperationsListResponse struct { + OperationsListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// OperationsListResult contains the result from method Operations.List. +type OperationsListResult struct { + OperationListResult +} + +// QueryUsageByExternalCloudProviderTypeResponse contains the response from method Query.UsageByExternalCloudProviderType. +type QueryUsageByExternalCloudProviderTypeResponse struct { + QueryUsageByExternalCloudProviderTypeResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// QueryUsageByExternalCloudProviderTypeResult contains the result from method Query.UsageByExternalCloudProviderType. +type QueryUsageByExternalCloudProviderTypeResult struct { + QueryResult +} + +// QueryUsageResponse contains the response from method Query.Usage. +type QueryUsageResponse struct { + QueryUsageResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// QueryUsageResult contains the result from method Query.Usage. +type QueryUsageResult struct { + QueryResult +} + +// ViewsCreateOrUpdateByScopeResponse contains the response from method Views.CreateOrUpdateByScope. +type ViewsCreateOrUpdateByScopeResponse struct { + ViewsCreateOrUpdateByScopeResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ViewsCreateOrUpdateByScopeResult contains the result from method Views.CreateOrUpdateByScope. +type ViewsCreateOrUpdateByScopeResult struct { + View +} + +// ViewsCreateOrUpdateResponse contains the response from method Views.CreateOrUpdate. +type ViewsCreateOrUpdateResponse struct { + ViewsCreateOrUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ViewsCreateOrUpdateResult contains the result from method Views.CreateOrUpdate. +type ViewsCreateOrUpdateResult struct { + View +} + +// ViewsDeleteByScopeResponse contains the response from method Views.DeleteByScope. +type ViewsDeleteByScopeResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ViewsDeleteResponse contains the response from method Views.Delete. +type ViewsDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ViewsGetByScopeResponse contains the response from method Views.GetByScope. +type ViewsGetByScopeResponse struct { + ViewsGetByScopeResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ViewsGetByScopeResult contains the result from method Views.GetByScope. +type ViewsGetByScopeResult struct { + View +} + +// ViewsGetResponse contains the response from method Views.Get. +type ViewsGetResponse struct { + ViewsGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ViewsGetResult contains the result from method Views.Get. +type ViewsGetResult struct { + View +} + +// ViewsListByScopeResponse contains the response from method Views.ListByScope. +type ViewsListByScopeResponse struct { + ViewsListByScopeResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ViewsListByScopeResult contains the result from method Views.ListByScope. +type ViewsListByScopeResult struct { + ViewListResult +} + +// ViewsListResponse contains the response from method Views.List. +type ViewsListResponse struct { + ViewsListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ViewsListResult contains the result from method Views.List. +type ViewsListResult struct { + ViewListResult +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_time_rfc3339.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_time_rfc3339.go new file mode 100644 index 000000000000..f6c9c39c1f87 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_time_rfc3339.go @@ -0,0 +1,85 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "encoding/json" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "regexp" + "strings" + "time" +) + +const ( + utcLayoutJSON = `"2006-01-02T15:04:05.999999999"` + utcLayout = "2006-01-02T15:04:05.999999999" + rfc3339JSON = `"` + time.RFC3339Nano + `"` +) + +// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases. +var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`) + +type timeRFC3339 time.Time + +func (t timeRFC3339) MarshalJSON() (json []byte, err error) { + tt := time.Time(t) + return tt.MarshalJSON() +} + +func (t timeRFC3339) MarshalText() (text []byte, err error) { + tt := time.Time(t) + return tt.MarshalText() +} + +func (t *timeRFC3339) UnmarshalJSON(data []byte) error { + layout := utcLayoutJSON + if tzOffsetRegex.Match(data) { + layout = rfc3339JSON + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) UnmarshalText(data []byte) (err error) { + layout := utcLayout + if tzOffsetRegex.Match(data) { + layout = time.RFC3339Nano + } + return t.Parse(layout, string(data)) +} + +func (t *timeRFC3339) Parse(layout, value string) error { + p, err := time.Parse(layout, strings.ToUpper(value)) + *t = timeRFC3339(p) + return err +} + +func populateTimeRFC3339(m map[string]interface{}, k string, t *time.Time) { + if t == nil { + return + } else if azcore.IsNullValue(t) { + m[k] = nil + return + } else if reflect.ValueOf(t).IsNil() { + return + } + m[k] = (*timeRFC3339)(t) +} + +func unpopulateTimeRFC3339(data json.RawMessage, t **time.Time) error { + if data == nil || strings.EqualFold(string(data), "null") { + return nil + } + var aux timeRFC3339 + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + *t = (*time.Time)(&aux) + return nil +} diff --git a/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_views_client.go b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_views_client.go new file mode 100644 index 000000000000..55ee0da0c305 --- /dev/null +++ b/sdk/resourcemanager/costmanagement/armcostmanagement/zz_generated_views_client.go @@ -0,0 +1,486 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armcostmanagement + +import ( + "context" + "errors" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" + "net/http" + "net/url" + "strings" +) + +// ViewsClient contains the methods for the Views group. +// Don't use this type directly, use NewViewsClient() instead. +type ViewsClient struct { + ep string + pl runtime.Pipeline +} + +// NewViewsClient creates a new instance of ViewsClient with the specified values. +func NewViewsClient(credential azcore.TokenCredential, options *arm.ClientOptions) *ViewsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &ViewsClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// CreateOrUpdate - The operation to create or update a view. Update operation requires latest eTag to be set in the request. You may obtain the latest +// eTag by performing a get operation. Create operation does not +// require eTag. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ViewsClient) CreateOrUpdate(ctx context.Context, viewName string, parameters View, options *ViewsCreateOrUpdateOptions) (ViewsCreateOrUpdateResponse, error) { + req, err := client.createOrUpdateCreateRequest(ctx, viewName, parameters, options) + if err != nil { + return ViewsCreateOrUpdateResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ViewsCreateOrUpdateResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return ViewsCreateOrUpdateResponse{}, client.createOrUpdateHandleError(resp) + } + return client.createOrUpdateHandleResponse(resp) +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *ViewsClient) createOrUpdateCreateRequest(ctx context.Context, viewName string, parameters View, options *ViewsCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/views/{viewName}" + if viewName == "" { + return nil, errors.New("parameter viewName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{viewName}", url.PathEscape(viewName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleResponse handles the CreateOrUpdate response. +func (client *ViewsClient) createOrUpdateHandleResponse(resp *http.Response) (ViewsCreateOrUpdateResponse, error) { + result := ViewsCreateOrUpdateResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.View); err != nil { + return ViewsCreateOrUpdateResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// createOrUpdateHandleError handles the CreateOrUpdate error response. +func (client *ViewsClient) createOrUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// CreateOrUpdateByScope - The operation to create or update a view. Update operation requires latest eTag to be set in the request. You may obtain the +// latest eTag by performing a get operation. Create operation does not +// require eTag. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ViewsClient) CreateOrUpdateByScope(ctx context.Context, scope string, viewName string, parameters View, options *ViewsCreateOrUpdateByScopeOptions) (ViewsCreateOrUpdateByScopeResponse, error) { + req, err := client.createOrUpdateByScopeCreateRequest(ctx, scope, viewName, parameters, options) + if err != nil { + return ViewsCreateOrUpdateByScopeResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ViewsCreateOrUpdateByScopeResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return ViewsCreateOrUpdateByScopeResponse{}, client.createOrUpdateByScopeHandleError(resp) + } + return client.createOrUpdateByScopeHandleResponse(resp) +} + +// createOrUpdateByScopeCreateRequest creates the CreateOrUpdateByScope request. +func (client *ViewsClient) createOrUpdateByScopeCreateRequest(ctx context.Context, scope string, viewName string, parameters View, options *ViewsCreateOrUpdateByScopeOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/views/{viewName}" + if scope == "" { + return nil, errors.New("parameter scope cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{scope}", url.PathEscape(scope)) + if viewName == "" { + return nil, errors.New("parameter viewName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{viewName}", url.PathEscape(viewName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateByScopeHandleResponse handles the CreateOrUpdateByScope response. +func (client *ViewsClient) createOrUpdateByScopeHandleResponse(resp *http.Response) (ViewsCreateOrUpdateByScopeResponse, error) { + result := ViewsCreateOrUpdateByScopeResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.View); err != nil { + return ViewsCreateOrUpdateByScopeResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// createOrUpdateByScopeHandleError handles the CreateOrUpdateByScope error response. +func (client *ViewsClient) createOrUpdateByScopeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Delete - The operation to delete a view. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ViewsClient) Delete(ctx context.Context, viewName string, options *ViewsDeleteOptions) (ViewsDeleteResponse, error) { + req, err := client.deleteCreateRequest(ctx, viewName, options) + if err != nil { + return ViewsDeleteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ViewsDeleteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return ViewsDeleteResponse{}, client.deleteHandleError(resp) + } + return ViewsDeleteResponse{RawResponse: resp}, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *ViewsClient) deleteCreateRequest(ctx context.Context, viewName string, options *ViewsDeleteOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/views/{viewName}" + if viewName == "" { + return nil, errors.New("parameter viewName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{viewName}", url.PathEscape(viewName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *ViewsClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// DeleteByScope - The operation to delete a view. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ViewsClient) DeleteByScope(ctx context.Context, scope string, viewName string, options *ViewsDeleteByScopeOptions) (ViewsDeleteByScopeResponse, error) { + req, err := client.deleteByScopeCreateRequest(ctx, scope, viewName, options) + if err != nil { + return ViewsDeleteByScopeResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ViewsDeleteByScopeResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return ViewsDeleteByScopeResponse{}, client.deleteByScopeHandleError(resp) + } + return ViewsDeleteByScopeResponse{RawResponse: resp}, nil +} + +// deleteByScopeCreateRequest creates the DeleteByScope request. +func (client *ViewsClient) deleteByScopeCreateRequest(ctx context.Context, scope string, viewName string, options *ViewsDeleteByScopeOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/views/{viewName}" + if scope == "" { + return nil, errors.New("parameter scope cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{scope}", url.PathEscape(scope)) + if viewName == "" { + return nil, errors.New("parameter viewName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{viewName}", url.PathEscape(viewName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteByScopeHandleError handles the DeleteByScope error response. +func (client *ViewsClient) deleteByScopeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Gets the view by view name. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ViewsClient) Get(ctx context.Context, viewName string, options *ViewsGetOptions) (ViewsGetResponse, error) { + req, err := client.getCreateRequest(ctx, viewName, options) + if err != nil { + return ViewsGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ViewsGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ViewsGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ViewsClient) getCreateRequest(ctx context.Context, viewName string, options *ViewsGetOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/views/{viewName}" + if viewName == "" { + return nil, errors.New("parameter viewName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{viewName}", url.PathEscape(viewName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ViewsClient) getHandleResponse(resp *http.Response) (ViewsGetResponse, error) { + result := ViewsGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.View); err != nil { + return ViewsGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *ViewsClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// GetByScope - Gets the view for the defined scope by view name. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ViewsClient) GetByScope(ctx context.Context, scope string, viewName string, options *ViewsGetByScopeOptions) (ViewsGetByScopeResponse, error) { + req, err := client.getByScopeCreateRequest(ctx, scope, viewName, options) + if err != nil { + return ViewsGetByScopeResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ViewsGetByScopeResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ViewsGetByScopeResponse{}, client.getByScopeHandleError(resp) + } + return client.getByScopeHandleResponse(resp) +} + +// getByScopeCreateRequest creates the GetByScope request. +func (client *ViewsClient) getByScopeCreateRequest(ctx context.Context, scope string, viewName string, options *ViewsGetByScopeOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/views/{viewName}" + if scope == "" { + return nil, errors.New("parameter scope cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{scope}", url.PathEscape(scope)) + if viewName == "" { + return nil, errors.New("parameter viewName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{viewName}", url.PathEscape(viewName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getByScopeHandleResponse handles the GetByScope response. +func (client *ViewsClient) getByScopeHandleResponse(resp *http.Response) (ViewsGetByScopeResponse, error) { + result := ViewsGetByScopeResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.View); err != nil { + return ViewsGetByScopeResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getByScopeHandleError handles the GetByScope error response. +func (client *ViewsClient) getByScopeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// List - Lists all views by tenant and object. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ViewsClient) List(options *ViewsListOptions) *ViewsListPager { + return &ViewsListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp ViewsListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ViewListResult.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *ViewsClient) listCreateRequest(ctx context.Context, options *ViewsListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.CostManagement/views" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *ViewsClient) listHandleResponse(resp *http.Response) (ViewsListResponse, error) { + result := ViewsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ViewListResult); err != nil { + return ViewsListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *ViewsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListByScope - Lists all views at the given scope. +// If the operation fails it returns the *ErrorResponse error type. +func (client *ViewsClient) ListByScope(scope string, options *ViewsListByScopeOptions) *ViewsListByScopePager { + return &ViewsListByScopePager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByScopeCreateRequest(ctx, scope, options) + }, + advancer: func(ctx context.Context, resp ViewsListByScopeResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ViewListResult.NextLink) + }, + } +} + +// listByScopeCreateRequest creates the ListByScope request. +func (client *ViewsClient) listByScopeCreateRequest(ctx context.Context, scope string, options *ViewsListByScopeOptions) (*policy.Request, error) { + urlPath := "/{scope}/providers/Microsoft.CostManagement/views" + if scope == "" { + return nil, errors.New("parameter scope cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{scope}", url.PathEscape(scope)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-10-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByScopeHandleResponse handles the ListByScope response. +func (client *ViewsClient) listByScopeHandleResponse(resp *http.Response) (ViewsListByScopeResponse, error) { + result := ViewsListByScopeResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ViewListResult); err != nil { + return ViewsListByScopeResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listByScopeHandleError handles the ListByScope error response. +func (client *ViewsClient) listByScopeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponse{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +}