From 9e0fc8ec6a334c95e5d2258ab65b23ae73cd097d Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Fri, 10 Dec 2021 02:57:45 +0000 Subject: [PATCH] CodeGen from PR 17000 in Azure/azure-rest-api-specs [Go] Track2 modify readme.go.md 9 (#17000) * [Go] Track2 modify readme.go.md 9 * fix --- .../subscription/armsubscription/CHANGELOG.md | 5 + .../subscription/armsubscription/LICENSE.txt | 21 + .../subscription/armsubscription/README.md | 75 +++ .../subscription/armsubscription/autorest.md | 13 + .../subscription/armsubscription/build.go | 7 + .../subscription/armsubscription/ci.yml | 27 + .../subscription/armsubscription/go.mod | 8 + .../subscription/armsubscription/go.sum | 37 ++ .../armsubscription/go_mod_tidy_hack.go | 13 + .../zz_generated_alias_client.go | 268 ++++++++ .../zz_generated_billingaccount_client.go | 99 +++ .../armsubscription/zz_generated_constants.go | 106 ++++ .../armsubscription/zz_generated_models.go | 597 ++++++++++++++++++ .../zz_generated_operations_client.go | 89 +++ .../armsubscription/zz_generated_pagers.go | 125 ++++ .../armsubscription/zz_generated_pollers.go | 101 +++ .../zz_generated_response_types.go | 252 ++++++++ .../zz_generated_subscription_client.go | 338 ++++++++++ .../zz_generated_subscriptionpolicy_client.go | 195 ++++++ .../zz_generated_time_rfc3339.go | 85 +++ 20 files changed, 2461 insertions(+) create mode 100644 sdk/resourcemanager/subscription/armsubscription/CHANGELOG.md create mode 100644 sdk/resourcemanager/subscription/armsubscription/LICENSE.txt create mode 100644 sdk/resourcemanager/subscription/armsubscription/README.md create mode 100644 sdk/resourcemanager/subscription/armsubscription/autorest.md create mode 100644 sdk/resourcemanager/subscription/armsubscription/build.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/ci.yml create mode 100644 sdk/resourcemanager/subscription/armsubscription/go.mod create mode 100644 sdk/resourcemanager/subscription/armsubscription/go.sum create mode 100644 sdk/resourcemanager/subscription/armsubscription/go_mod_tidy_hack.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_alias_client.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_billingaccount_client.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_constants.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_models.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_operations_client.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_pagers.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_pollers.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_response_types.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_subscription_client.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_subscriptionpolicy_client.go create mode 100644 sdk/resourcemanager/subscription/armsubscription/zz_generated_time_rfc3339.go diff --git a/sdk/resourcemanager/subscription/armsubscription/CHANGELOG.md b/sdk/resourcemanager/subscription/armsubscription/CHANGELOG.md new file mode 100644 index 000000000000..17b9dceace74 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/CHANGELOG.md @@ -0,0 +1,5 @@ +# Release History + +## 0.1.0 (2021-12-10) + +- Init release. \ No newline at end of file diff --git a/sdk/resourcemanager/subscription/armsubscription/LICENSE.txt b/sdk/resourcemanager/subscription/armsubscription/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/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/subscription/armsubscription/README.md b/sdk/resourcemanager/subscription/armsubscription/README.md new file mode 100644 index 000000000000..c79f010e8f44 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/README.md @@ -0,0 +1,75 @@ +# Azure Subscription Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription) + +The `armsubscription` module provides operations for working with Azure Subscription. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/subscription/armsubscription) + +# 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 Subscription module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Subscription. 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 Subscription 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 := armsubscription.(, 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 := armsubscription.(, 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 `Subscription` 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/subscription/armsubscription/autorest.md b/sdk/resourcemanager/subscription/armsubscription/autorest.md new file mode 100644 index 000000000000..b63a263fd1b4 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/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/subscription/resource-manager/readme.md +- /home/vsts/work/1/s/azure-rest-api-specs/specification/subscription/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/subscription/armsubscription/build.go b/sdk/resourcemanager/subscription/armsubscription/build.go new file mode 100644 index 000000000000..7c2c218bda5c --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/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/subscription/armsubscription + +package armsubscription diff --git a/sdk/resourcemanager/subscription/armsubscription/ci.yml b/sdk/resourcemanager/subscription/armsubscription/ci.yml new file mode 100644 index 000000000000..e9f76b4a6d84 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/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/subscription/armsubscription/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/subscription/armsubscription/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'resourcemanager/subscription/armsubscription' diff --git a/sdk/resourcemanager/subscription/armsubscription/go.mod b/sdk/resourcemanager/subscription/armsubscription/go.mod new file mode 100644 index 000000000000..98c6ff3de50b --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/go.mod @@ -0,0 +1,8 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription + +go 1.16 + +require ( + github.com/Azure/azure-sdk-for-go v60.1.0+incompatible + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 +) diff --git a/sdk/resourcemanager/subscription/armsubscription/go.sum b/sdk/resourcemanager/subscription/armsubscription/go.sum new file mode 100644 index 000000000000..960c6c966a3f --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/go.sum @@ -0,0 +1,37 @@ +github.com/Azure/azure-sdk-for-go v60.1.0+incompatible h1:j6y8ddurcaiyLfwBwPmJFaunp6BDzyQTuAgMrm1r++o= +github.com/Azure/azure-sdk-for-go v60.1.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/subscription/armsubscription/go_mod_tidy_hack.go b/sdk/resourcemanager/subscription/armsubscription/go_mod_tidy_hack.go new file mode 100644 index 000000000000..993f94e24ed8 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/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 armsubscription + +// 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/subscription/armsubscription/zz_generated_alias_client.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_alias_client.go new file mode 100644 index 000000000000..6762297c4004 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_alias_client.go @@ -0,0 +1,268 @@ +//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 armsubscription + +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" +) + +// AliasClient contains the methods for the Alias group. +// Don't use this type directly, use NewAliasClient() instead. +type AliasClient struct { + ep string + pl runtime.Pipeline +} + +// NewAliasClient creates a new instance of AliasClient with the specified values. +func NewAliasClient(credential azcore.TokenCredential, options *arm.ClientOptions) *AliasClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &AliasClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// BeginCreate - Create Alias Subscription. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *AliasClient) BeginCreate(ctx context.Context, aliasName string, body PutAliasRequest, options *AliasBeginCreateOptions) (AliasCreatePollerResponse, error) { + resp, err := client.create(ctx, aliasName, body, options) + if err != nil { + return AliasCreatePollerResponse{}, err + } + result := AliasCreatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("AliasClient.Create", "", resp, client.pl, client.createHandleError) + if err != nil { + return AliasCreatePollerResponse{}, err + } + result.Poller = &AliasCreatePoller{ + pt: pt, + } + return result, nil +} + +// Create - Create Alias Subscription. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *AliasClient) create(ctx context.Context, aliasName string, body PutAliasRequest, options *AliasBeginCreateOptions) (*http.Response, error) { + req, err := client.createCreateRequest(ctx, aliasName, body, 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.StatusCreated) { + return nil, client.createHandleError(resp) + } + return resp, nil +} + +// createCreateRequest creates the Create request. +func (client *AliasClient) createCreateRequest(ctx context.Context, aliasName string, body PutAliasRequest, options *AliasBeginCreateOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/aliases/{aliasName}" + if aliasName == "" { + return nil, errors.New("parameter aliasName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{aliasName}", url.PathEscape(aliasName)) + 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, body) +} + +// createHandleError handles the Create error response. +func (client *AliasClient) createHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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 - Delete Alias. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *AliasClient) Delete(ctx context.Context, aliasName string, options *AliasDeleteOptions) (AliasDeleteResponse, error) { + req, err := client.deleteCreateRequest(ctx, aliasName, options) + if err != nil { + return AliasDeleteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AliasDeleteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusNoContent) { + return AliasDeleteResponse{}, client.deleteHandleError(resp) + } + return AliasDeleteResponse{RawResponse: resp}, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *AliasClient) deleteCreateRequest(ctx context.Context, aliasName string, options *AliasDeleteOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/aliases/{aliasName}" + if aliasName == "" { + return nil, errors.New("parameter aliasName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{aliasName}", url.PathEscape(aliasName)) + 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 *AliasClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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 - Get Alias Subscription. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *AliasClient) Get(ctx context.Context, aliasName string, options *AliasGetOptions) (AliasGetResponse, error) { + req, err := client.getCreateRequest(ctx, aliasName, options) + if err != nil { + return AliasGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AliasGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AliasGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *AliasClient) getCreateRequest(ctx context.Context, aliasName string, options *AliasGetOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/aliases/{aliasName}" + if aliasName == "" { + return nil, errors.New("parameter aliasName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{aliasName}", url.PathEscape(aliasName)) + 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 *AliasClient) getHandleResponse(resp *http.Response) (AliasGetResponse, error) { + result := AliasGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.SubscriptionAliasResponse); err != nil { + return AliasGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *AliasClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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 - List Alias Subscription. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *AliasClient) List(ctx context.Context, options *AliasListOptions) (AliasListResponse, error) { + req, err := client.listCreateRequest(ctx, options) + if err != nil { + return AliasListResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return AliasListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return AliasListResponse{}, client.listHandleError(resp) + } + return client.listHandleResponse(resp) +} + +// listCreateRequest creates the List request. +func (client *AliasClient) listCreateRequest(ctx context.Context, options *AliasListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/aliases" + 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 *AliasClient) listHandleResponse(resp *http.Response) (AliasListResponse, error) { + result := AliasListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.SubscriptionAliasListResult); err != nil { + return AliasListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *AliasClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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/subscription/armsubscription/zz_generated_billingaccount_client.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_billingaccount_client.go new file mode 100644 index 000000000000..4be3b7eb3f9a --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_billingaccount_client.go @@ -0,0 +1,99 @@ +//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 armsubscription + +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" +) + +// BillingAccountClient contains the methods for the BillingAccount group. +// Don't use this type directly, use NewBillingAccountClient() instead. +type BillingAccountClient struct { + ep string + pl runtime.Pipeline +} + +// NewBillingAccountClient creates a new instance of BillingAccountClient with the specified values. +func NewBillingAccountClient(credential azcore.TokenCredential, options *arm.ClientOptions) *BillingAccountClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &BillingAccountClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// GetPolicy - Get Billing Account Policy. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *BillingAccountClient) GetPolicy(ctx context.Context, billingAccountID string, options *BillingAccountGetPolicyOptions) (BillingAccountGetPolicyResponse, error) { + req, err := client.getPolicyCreateRequest(ctx, billingAccountID, options) + if err != nil { + return BillingAccountGetPolicyResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return BillingAccountGetPolicyResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return BillingAccountGetPolicyResponse{}, client.getPolicyHandleError(resp) + } + return client.getPolicyHandleResponse(resp) +} + +// getPolicyCreateRequest creates the GetPolicy request. +func (client *BillingAccountClient) getPolicyCreateRequest(ctx context.Context, billingAccountID string, options *BillingAccountGetPolicyOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Subscription/policies/default" + if billingAccountID == "" { + return nil, errors.New("parameter billingAccountID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{billingAccountId}", url.PathEscape(billingAccountID)) + 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 +} + +// getPolicyHandleResponse handles the GetPolicy response. +func (client *BillingAccountClient) getPolicyHandleResponse(resp *http.Response) (BillingAccountGetPolicyResponse, error) { + result := BillingAccountGetPolicyResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.BillingAccountPoliciesResponse); err != nil { + return BillingAccountGetPolicyResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getPolicyHandleError handles the GetPolicy error response. +func (client *BillingAccountClient) getPolicyHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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/subscription/armsubscription/zz_generated_constants.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_constants.go new file mode 100644 index 000000000000..bd1af8f51bc9 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_constants.go @@ -0,0 +1,106 @@ +//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 armsubscription + +const ( + module = "armsubscription" + version = "v0.1.0" +) + +// AcceptOwnership - The accept ownership state of the resource. +type AcceptOwnership string + +const ( + AcceptOwnershipCompleted AcceptOwnership = "Completed" + AcceptOwnershipExpired AcceptOwnership = "Expired" + AcceptOwnershipPending AcceptOwnership = "Pending" +) + +// PossibleAcceptOwnershipValues returns the possible values for the AcceptOwnership const type. +func PossibleAcceptOwnershipValues() []AcceptOwnership { + return []AcceptOwnership{ + AcceptOwnershipCompleted, + AcceptOwnershipExpired, + AcceptOwnershipPending, + } +} + +// ToPtr returns a *AcceptOwnership pointing to the current value. +func (c AcceptOwnership) ToPtr() *AcceptOwnership { + return &c +} + +// CreatedByType - The type of identity that created the resource. +type CreatedByType string + +const ( + CreatedByTypeApplication CreatedByType = "Application" + CreatedByTypeKey CreatedByType = "Key" + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + CreatedByTypeUser CreatedByType = "User" +) + +// PossibleCreatedByTypeValues returns the possible values for the CreatedByType const type. +func PossibleCreatedByTypeValues() []CreatedByType { + return []CreatedByType{ + CreatedByTypeApplication, + CreatedByTypeKey, + CreatedByTypeManagedIdentity, + CreatedByTypeUser, + } +} + +// ToPtr returns a *CreatedByType pointing to the current value. +func (c CreatedByType) ToPtr() *CreatedByType { + return &c +} + +// ProvisioningState - The provisioning state of the resource. +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +// PossibleProvisioningStateValues returns the possible values for the ProvisioningState const type. +func PossibleProvisioningStateValues() []ProvisioningState { + return []ProvisioningState{ + ProvisioningStateAccepted, + ProvisioningStateFailed, + ProvisioningStateSucceeded, + } +} + +// ToPtr returns a *ProvisioningState pointing to the current value. +func (c ProvisioningState) ToPtr() *ProvisioningState { + return &c +} + +// Workload - The workload type of the subscription. It can be either Production or DevTest. +type Workload string + +const ( + WorkloadDevTest Workload = "DevTest" + WorkloadProduction Workload = "Production" +) + +// PossibleWorkloadValues returns the possible values for the Workload const type. +func PossibleWorkloadValues() []Workload { + return []Workload{ + WorkloadDevTest, + WorkloadProduction, + } +} + +// ToPtr returns a *Workload pointing to the current value. +func (c Workload) ToPtr() *Workload { + return &c +} diff --git a/sdk/resourcemanager/subscription/armsubscription/zz_generated_models.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_models.go new file mode 100644 index 000000000000..97a2ab1a4e84 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_models.go @@ -0,0 +1,597 @@ +//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 armsubscription + +import ( + "encoding/json" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "time" +) + +// AcceptOwnershipRequest - The parameters required to accept subscription ownership. +type AcceptOwnershipRequest struct { + // Accept subscription ownership request properties. + Properties *AcceptOwnershipRequestProperties `json:"properties,omitempty"` +} + +// AcceptOwnershipRequestProperties - Accept subscription ownership request properties. +type AcceptOwnershipRequestProperties struct { + // REQUIRED; The friendly name of the subscription. + DisplayName *string `json:"displayName,omitempty"` + + // Management group Id for the subscription. + ManagementGroupID *string `json:"managementGroupId,omitempty"` + + // Tags for the subscription + Tags map[string]*string `json:"tags,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type AcceptOwnershipRequestProperties. +func (a AcceptOwnershipRequestProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "displayName", a.DisplayName) + populate(objectMap, "managementGroupId", a.ManagementGroupID) + populate(objectMap, "tags", a.Tags) + return json.Marshal(objectMap) +} + +// AcceptOwnershipStatusResponse - Subscription Accept Ownership Response +type AcceptOwnershipStatusResponse struct { + // The display name of the subscription. + DisplayName *string `json:"displayName,omitempty"` + + // Tenant Id of the subscription + SubscriptionTenantID *string `json:"subscriptionTenantId,omitempty"` + + // Tags for the subscription + Tags map[string]*string `json:"tags,omitempty"` + + // READ-ONLY; The accept ownership state of the resource. + AcceptOwnershipState *AcceptOwnership `json:"acceptOwnershipState,omitempty" azure:"ro"` + + // READ-ONLY; UPN of the billing owner + BillingOwner *string `json:"billingOwner,omitempty" azure:"ro"` + + // READ-ONLY; Newly created subscription Id. + SubscriptionID *string `json:"subscriptionId,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type AcceptOwnershipStatusResponse. +func (a AcceptOwnershipStatusResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "acceptOwnershipState", a.AcceptOwnershipState) + populate(objectMap, "billingOwner", a.BillingOwner) + populate(objectMap, "displayName", a.DisplayName) + populate(objectMap, "subscriptionId", a.SubscriptionID) + populate(objectMap, "subscriptionTenantId", a.SubscriptionTenantID) + populate(objectMap, "tags", a.Tags) + return json.Marshal(objectMap) +} + +// AliasBeginCreateOptions contains the optional parameters for the Alias.BeginCreate method. +type AliasBeginCreateOptions struct { + // placeholder for future optional parameters +} + +// AliasDeleteOptions contains the optional parameters for the Alias.Delete method. +type AliasDeleteOptions struct { + // placeholder for future optional parameters +} + +// AliasGetOptions contains the optional parameters for the Alias.Get method. +type AliasGetOptions struct { + // placeholder for future optional parameters +} + +// AliasListOptions contains the optional parameters for the Alias.List method. +type AliasListOptions struct { + // placeholder for future optional parameters +} + +// BillingAccountGetPolicyOptions contains the optional parameters for the BillingAccount.GetPolicy method. +type BillingAccountGetPolicyOptions struct { + // placeholder for future optional parameters +} + +// BillingAccountPoliciesResponse - Billing account policies information. +type BillingAccountPoliciesResponse struct { + // Billing account policies response properties. + Properties *BillingAccountPoliciesResponseProperties `json:"properties,omitempty"` + + // READ-ONLY; Fully qualified ID for the policy. + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; Policy name. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; Metadata pertaining to creation and last modification of the resource. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` + + // READ-ONLY; Resource type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// BillingAccountPoliciesResponseProperties - Put billing account policies response properties. +type BillingAccountPoliciesResponseProperties struct { + // Determine if the transfers are allowed for the billing account + AllowTransfers *bool `json:"allowTransfers,omitempty"` + + // Service tenant for the billing account. + ServiceTenants []*ServiceTenantResponse `json:"serviceTenants,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type BillingAccountPoliciesResponseProperties. +func (b BillingAccountPoliciesResponseProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "allowTransfers", b.AllowTransfers) + populate(objectMap, "serviceTenants", b.ServiceTenants) + return json.Marshal(objectMap) +} + +// CanceledSubscriptionID - The ID of the canceled subscription +type CanceledSubscriptionID struct { + // READ-ONLY; The ID of the canceled subscription + Value *string `json:"value,omitempty" azure:"ro"` +} + +// EnabledSubscriptionID - The ID of the subscriptions that is being enabled +type EnabledSubscriptionID struct { + // READ-ONLY; The ID of the subscriptions that is being enabled + Value *string `json:"value,omitempty" azure:"ro"` +} + +// ErrorResponse - Describes the format of Error response. +type ErrorResponse struct { + // Error code + Code *string `json:"code,omitempty"` + + // Error message indicating why the operation failed. + Message *string `json:"message,omitempty"` +} + +// ErrorResponseBody - Error response indicates that the service is not able to process the incoming request. The reason is provided in the error message. +// Implements the error and azcore.HTTPResponse interfaces. +type ErrorResponseBody struct { + raw string + // Error code + Code *string `json:"code,omitempty"` + + // The details of the error. + InnerError *ErrorResponse `json:"error,omitempty"` + + // Error message indicating why the operation failed. + Message *string `json:"message,omitempty"` +} + +// Error implements the error interface for type ErrorResponseBody. +// The contents of the error text are not contractual and subject to change. +func (e ErrorResponseBody) Error() string { + return e.raw +} + +// GetTenantPolicyListResponse - Tenant policy information list. +type GetTenantPolicyListResponse struct { + // READ-ONLY; The link (url) to the next page of results. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; The list of tenant policies. + Value []*GetTenantPolicyResponse `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type GetTenantPolicyListResponse. +func (g GetTenantPolicyListResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", g.NextLink) + populate(objectMap, "value", g.Value) + return json.Marshal(objectMap) +} + +// GetTenantPolicyResponse - Tenant policy Information. +type GetTenantPolicyResponse struct { + // Tenant policy properties. + Properties *TenantPolicy `json:"properties,omitempty"` + + // READ-ONLY; Policy Id. + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; Policy name. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; Metadata pertaining to creation and last modification of the resource. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` + + // READ-ONLY; Resource type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// Operation - REST API operation +type Operation struct { + // The object that represents the operation. + Display *OperationDisplay `json:"display,omitempty"` + + // Indicates whether the operation is a data action + IsDataAction *bool `json:"isDataAction,omitempty"` + + // Operation name: {provider}/{resource}/{operation} + Name *string `json:"name,omitempty"` +} + +// OperationDisplay - The object that represents the operation. +type OperationDisplay struct { + // Localized friendly description for the operation + Description *string `json:"description,omitempty"` + + // Operation type: Read, write, delete, etc. + Operation *string `json:"operation,omitempty"` + + // Service provider: Microsoft.Subscription + Provider *string `json:"provider,omitempty"` + + // Resource on which the operation is performed: Profile, endpoint, etc. + Resource *string `json:"resource,omitempty"` +} + +// OperationListResult - Result of the request to list operations. It contains a list of operations and a URL link to get the next set of results. +type OperationListResult struct { + // URL to get the next set of operation list results if there are any. + NextLink *string `json:"nextLink,omitempty"` + + // List of operations. + Value []*Operation `json:"value,omitempty"` +} + +// 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 +} + +// PutAliasRequest - The parameters required to create a new subscription. +type PutAliasRequest struct { + // Put alias request properties. + Properties *PutAliasRequestProperties `json:"properties,omitempty"` +} + +// PutAliasRequestAdditionalProperties - Put subscription additional properties. +type PutAliasRequestAdditionalProperties struct { + // Management group Id for the subscription. + ManagementGroupID *string `json:"managementGroupId,omitempty"` + + // Owner Id of the subscription + SubscriptionOwnerID *string `json:"subscriptionOwnerId,omitempty"` + + // Tenant Id of the subscription + SubscriptionTenantID *string `json:"subscriptionTenantId,omitempty"` + + // Tags for the subscription + Tags map[string]*string `json:"tags,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type PutAliasRequestAdditionalProperties. +func (p PutAliasRequestAdditionalProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "managementGroupId", p.ManagementGroupID) + populate(objectMap, "subscriptionOwnerId", p.SubscriptionOwnerID) + populate(objectMap, "subscriptionTenantId", p.SubscriptionTenantID) + populate(objectMap, "tags", p.Tags) + return json.Marshal(objectMap) +} + +// PutAliasRequestProperties - Put subscription properties. +type PutAliasRequestProperties struct { + // Put alias request additional properties. + AdditionalProperties *PutAliasRequestAdditionalProperties `json:"additionalProperties,omitempty"` + + // Billing scope of the subscription. For CustomerLed and FieldLed - /billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName} + // For PartnerLed - + // /billingAccounts/{billingAccountName}/customers/{customerName} For Legacy EA - /billingAccounts/{billingAccountName}/enrollmentAccounts/{enrollmentAccountName} + BillingScope *string `json:"billingScope,omitempty"` + + // The friendly name of the subscription. + DisplayName *string `json:"displayName,omitempty"` + + // Reseller Id + ResellerID *string `json:"resellerId,omitempty"` + + // This parameter can be used to create alias for existing subscription Id + SubscriptionID *string `json:"subscriptionId,omitempty"` + + // The workload type of the subscription. It can be either Production or DevTest. + Workload *Workload `json:"workload,omitempty"` +} + +// PutTenantPolicyRequestProperties - Put tenant policy request properties. +type PutTenantPolicyRequestProperties struct { + // Blocks the entering of subscriptions into user's tenant. + BlockSubscriptionsIntoTenant *bool `json:"blockSubscriptionsIntoTenant,omitempty"` + + // Blocks the leaving of subscriptions from user's tenant. + BlockSubscriptionsLeavingTenant *bool `json:"blockSubscriptionsLeavingTenant,omitempty"` + + // List of user objectIds that are exempted from the set subscription tenant policies for the user's tenant. + ExemptedPrincipals []*string `json:"exemptedPrincipals,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type PutTenantPolicyRequestProperties. +func (p PutTenantPolicyRequestProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "blockSubscriptionsIntoTenant", p.BlockSubscriptionsIntoTenant) + populate(objectMap, "blockSubscriptionsLeavingTenant", p.BlockSubscriptionsLeavingTenant) + populate(objectMap, "exemptedPrincipals", p.ExemptedPrincipals) + return json.Marshal(objectMap) +} + +// RenamedSubscriptionID - The ID of the subscriptions that is being renamed +type RenamedSubscriptionID struct { + // READ-ONLY; The ID of the subscriptions that is being renamed + Value *string `json:"value,omitempty" azure:"ro"` +} + +// ServiceTenantResponse - Billing account service tenant. +type ServiceTenantResponse struct { + // Service tenant id. + TenantID *string `json:"tenantId,omitempty"` + + // Service tenant name. + TenantName *string `json:"tenantName,omitempty"` +} + +// SubscriptionAcceptOwnershipStatusOptions contains the optional parameters for the Subscription.AcceptOwnershipStatus method. +type SubscriptionAcceptOwnershipStatusOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionAliasListResult - The list of aliases. +type SubscriptionAliasListResult struct { + // READ-ONLY; The link (url) to the next page of results. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; The list of alias. + Value []*SubscriptionAliasResponse `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type SubscriptionAliasListResult. +func (s SubscriptionAliasListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// SubscriptionAliasResponse - Subscription Information with the alias. +type SubscriptionAliasResponse struct { + // Subscription Alias response properties. + Properties *SubscriptionAliasResponseProperties `json:"properties,omitempty"` + + // READ-ONLY; Fully qualified ID for the alias resource. + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; Alias ID. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; Metadata pertaining to creation and last modification of the resource. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` + + // READ-ONLY; Resource type, Microsoft.Subscription/aliases. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// SubscriptionAliasResponseProperties - Put subscription creation result properties. +type SubscriptionAliasResponseProperties struct { + // Billing scope of the subscription. For CustomerLed and FieldLed - /billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName} + // For PartnerLed - + // /billingAccounts/{billingAccountName}/customers/{customerName} For Legacy EA - /billingAccounts/{billingAccountName}/enrollmentAccounts/{enrollmentAccountName} + BillingScope *string `json:"billingScope,omitempty"` + + // The display name of the subscription. + DisplayName *string `json:"displayName,omitempty"` + + // The Management Group Id. + ManagementGroupID *string `json:"managementGroupId,omitempty"` + + // The provisioning state of the resource. + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + + // Reseller Id + ResellerID *string `json:"resellerId,omitempty"` + + // Owner Id of the subscription + SubscriptionOwnerID *string `json:"subscriptionOwnerId,omitempty"` + + // Tags for the subscription + Tags map[string]*string `json:"tags,omitempty"` + + // The workload type of the subscription. It can be either Production or DevTest. + Workload *Workload `json:"workload,omitempty"` + + // READ-ONLY; The accept ownership state of the resource. + AcceptOwnershipState *AcceptOwnership `json:"acceptOwnershipState,omitempty" azure:"ro"` + + // READ-ONLY; Url to accept ownership of the subscription. + AcceptOwnershipURL *string `json:"acceptOwnershipUrl,omitempty" azure:"ro"` + + // READ-ONLY; Newly created subscription Id. + SubscriptionID *string `json:"subscriptionId,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type SubscriptionAliasResponseProperties. +func (s SubscriptionAliasResponseProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "acceptOwnershipState", s.AcceptOwnershipState) + populate(objectMap, "acceptOwnershipUrl", s.AcceptOwnershipURL) + populate(objectMap, "billingScope", s.BillingScope) + populate(objectMap, "displayName", s.DisplayName) + populate(objectMap, "managementGroupId", s.ManagementGroupID) + populate(objectMap, "provisioningState", s.ProvisioningState) + populate(objectMap, "resellerId", s.ResellerID) + populate(objectMap, "subscriptionId", s.SubscriptionID) + populate(objectMap, "subscriptionOwnerId", s.SubscriptionOwnerID) + populate(objectMap, "tags", s.Tags) + populate(objectMap, "workload", s.Workload) + return json.Marshal(objectMap) +} + +// SubscriptionBeginAcceptOwnershipOptions contains the optional parameters for the Subscription.BeginAcceptOwnership method. +type SubscriptionBeginAcceptOwnershipOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionCancelOptions contains the optional parameters for the Subscription.Cancel method. +type SubscriptionCancelOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionEnableOptions contains the optional parameters for the Subscription.Enable method. +type SubscriptionEnableOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionName - The new name of the subscription. +type SubscriptionName struct { + // New subscription name + SubscriptionName *string `json:"subscriptionName,omitempty"` +} + +// SubscriptionPolicyAddUpdatePolicyForTenantOptions contains the optional parameters for the SubscriptionPolicy.AddUpdatePolicyForTenant method. +type SubscriptionPolicyAddUpdatePolicyForTenantOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionPolicyGetPolicyForTenantOptions contains the optional parameters for the SubscriptionPolicy.GetPolicyForTenant method. +type SubscriptionPolicyGetPolicyForTenantOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionPolicyListPolicyForTenantOptions contains the optional parameters for the SubscriptionPolicy.ListPolicyForTenant method. +type SubscriptionPolicyListPolicyForTenantOptions struct { + // placeholder for future optional parameters +} + +// SubscriptionRenameOptions contains the optional parameters for the Subscription.Rename method. +type SubscriptionRenameOptions struct { + // placeholder for future optional parameters +} + +// SystemData - Metadata pertaining to creation and last modification of the resource. +type SystemData struct { + // The timestamp of resource creation (UTC). + CreatedAt *time.Time `json:"createdAt,omitempty"` + + // The identity that created the resource. + CreatedBy *string `json:"createdBy,omitempty"` + + // The type of identity that created the resource. + CreatedByType *CreatedByType `json:"createdByType,omitempty"` + + // The timestamp of resource last modification (UTC) + LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty"` + + // The identity that last modified the resource. + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + + // The type of identity that last modified the resource. + LastModifiedByType *CreatedByType `json:"lastModifiedByType,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type SystemData. +func (s SystemData) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populateTimeRFC3339(objectMap, "createdAt", s.CreatedAt) + populate(objectMap, "createdBy", s.CreatedBy) + populate(objectMap, "createdByType", s.CreatedByType) + populateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt) + populate(objectMap, "lastModifiedBy", s.LastModifiedBy) + populate(objectMap, "lastModifiedByType", s.LastModifiedByType) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SystemData. +func (s *SystemData) 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 "createdAt": + err = unpopulateTimeRFC3339(val, &s.CreatedAt) + delete(rawMsg, key) + case "createdBy": + err = unpopulate(val, &s.CreatedBy) + delete(rawMsg, key) + case "createdByType": + err = unpopulate(val, &s.CreatedByType) + delete(rawMsg, key) + case "lastModifiedAt": + err = unpopulateTimeRFC3339(val, &s.LastModifiedAt) + delete(rawMsg, key) + case "lastModifiedBy": + err = unpopulate(val, &s.LastModifiedBy) + delete(rawMsg, key) + case "lastModifiedByType": + err = unpopulate(val, &s.LastModifiedByType) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// TenantPolicy - Tenant policy. +type TenantPolicy struct { + // Blocks the entering of subscriptions into user's tenant. + BlockSubscriptionsIntoTenant *bool `json:"blockSubscriptionsIntoTenant,omitempty"` + + // Blocks the leaving of subscriptions from user's tenant. + BlockSubscriptionsLeavingTenant *bool `json:"blockSubscriptionsLeavingTenant,omitempty"` + + // List of user objectIds that are exempted from the set subscription tenant policies for the user's tenant. + ExemptedPrincipals []*string `json:"exemptedPrincipals,omitempty"` + + // READ-ONLY; Policy Id. + PolicyID *string `json:"policyId,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type TenantPolicy. +func (t TenantPolicy) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "blockSubscriptionsIntoTenant", t.BlockSubscriptionsIntoTenant) + populate(objectMap, "blockSubscriptionsLeavingTenant", t.BlockSubscriptionsLeavingTenant) + populate(objectMap, "exemptedPrincipals", t.ExemptedPrincipals) + populate(objectMap, "policyId", t.PolicyID) + return json.Marshal(objectMap) +} + +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/subscription/armsubscription/zz_generated_operations_client.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_operations_client.go new file mode 100644 index 000000000000..a7383af309d8 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/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 armsubscription + +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 Microsoft.Subscription API operations. +// If the operation fails it returns the *ErrorResponseBody 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.Subscription/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 := ErrorResponseBody{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/subscription/armsubscription/zz_generated_pagers.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_pagers.go new file mode 100644 index 000000000000..a4fa5dad0501 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_pagers.go @@ -0,0 +1,125 @@ +//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 armsubscription + +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 +} + +// SubscriptionPolicyListPolicyForTenantPager provides operations for iterating over paged responses. +type SubscriptionPolicyListPolicyForTenantPager struct { + client *SubscriptionPolicyClient + current SubscriptionPolicyListPolicyForTenantResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, SubscriptionPolicyListPolicyForTenantResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *SubscriptionPolicyListPolicyForTenantPager) 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 *SubscriptionPolicyListPolicyForTenantPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.GetTenantPolicyListResponse.NextLink == nil || len(*p.current.GetTenantPolicyListResponse.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.listPolicyForTenantHandleError(resp) + return false + } + result, err := p.client.listPolicyForTenantHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current SubscriptionPolicyListPolicyForTenantResponse page. +func (p *SubscriptionPolicyListPolicyForTenantPager) PageResponse() SubscriptionPolicyListPolicyForTenantResponse { + return p.current +} diff --git a/sdk/resourcemanager/subscription/armsubscription/zz_generated_pollers.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_pollers.go new file mode 100644 index 000000000000..0917d33cde92 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_pollers.go @@ -0,0 +1,101 @@ +//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 armsubscription + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "net/http" +) + +// AliasCreatePoller provides polling facilities until the operation reaches a terminal state. +type AliasCreatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *AliasCreatePoller) 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 *AliasCreatePoller) 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 AliasCreateResponse will be returned. +func (p *AliasCreatePoller) FinalResponse(ctx context.Context) (AliasCreateResponse, error) { + respType := AliasCreateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.SubscriptionAliasResponse) + if err != nil { + return AliasCreateResponse{}, 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 *AliasCreatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// SubscriptionAcceptOwnershipPoller provides polling facilities until the operation reaches a terminal state. +type SubscriptionAcceptOwnershipPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *SubscriptionAcceptOwnershipPoller) 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 *SubscriptionAcceptOwnershipPoller) 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 SubscriptionAcceptOwnershipResponse will be returned. +func (p *SubscriptionAcceptOwnershipPoller) FinalResponse(ctx context.Context) (SubscriptionAcceptOwnershipResponse, error) { + respType := SubscriptionAcceptOwnershipResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return SubscriptionAcceptOwnershipResponse{}, 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 *SubscriptionAcceptOwnershipPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} diff --git a/sdk/resourcemanager/subscription/armsubscription/zz_generated_response_types.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_response_types.go new file mode 100644 index 000000000000..ac2a7b4b07b4 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_response_types.go @@ -0,0 +1,252 @@ +//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 armsubscription + +import ( + "context" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "net/http" + "time" +) + +// AliasCreatePollerResponse contains the response from method Alias.Create. +type AliasCreatePollerResponse struct { + // Poller contains an initialized poller. + Poller *AliasCreatePoller + + // 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 AliasCreatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (AliasCreateResponse, error) { + respType := AliasCreateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.SubscriptionAliasResponse) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a AliasCreatePollerResponse from the provided client and resume token. +func (l *AliasCreatePollerResponse) Resume(ctx context.Context, client *AliasClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("AliasClient.Create", token, client.pl, client.createHandleError) + if err != nil { + return err + } + poller := &AliasCreatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// AliasCreateResponse contains the response from method Alias.Create. +type AliasCreateResponse struct { + AliasCreateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AliasCreateResult contains the result from method Alias.Create. +type AliasCreateResult struct { + SubscriptionAliasResponse +} + +// AliasDeleteResponse contains the response from method Alias.Delete. +type AliasDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AliasGetResponse contains the response from method Alias.Get. +type AliasGetResponse struct { + AliasGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AliasGetResult contains the result from method Alias.Get. +type AliasGetResult struct { + SubscriptionAliasResponse +} + +// AliasListResponse contains the response from method Alias.List. +type AliasListResponse struct { + AliasListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// AliasListResult contains the result from method Alias.List. +type AliasListResult struct { + SubscriptionAliasListResult +} + +// BillingAccountGetPolicyResponse contains the response from method BillingAccount.GetPolicy. +type BillingAccountGetPolicyResponse struct { + BillingAccountGetPolicyResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// BillingAccountGetPolicyResult contains the result from method BillingAccount.GetPolicy. +type BillingAccountGetPolicyResult struct { + BillingAccountPoliciesResponse +} + +// 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 +} + +// SubscriptionAcceptOwnershipPollerResponse contains the response from method Subscription.AcceptOwnership. +type SubscriptionAcceptOwnershipPollerResponse struct { + // Poller contains an initialized poller. + Poller *SubscriptionAcceptOwnershipPoller + + // 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 SubscriptionAcceptOwnershipPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (SubscriptionAcceptOwnershipResponse, error) { + respType := SubscriptionAcceptOwnershipResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a SubscriptionAcceptOwnershipPollerResponse from the provided client and resume token. +func (l *SubscriptionAcceptOwnershipPollerResponse) Resume(ctx context.Context, client *SubscriptionClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("SubscriptionClient.AcceptOwnership", token, client.pl, client.acceptOwnershipHandleError) + if err != nil { + return err + } + poller := &SubscriptionAcceptOwnershipPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// SubscriptionAcceptOwnershipResponse contains the response from method Subscription.AcceptOwnership. +type SubscriptionAcceptOwnershipResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SubscriptionAcceptOwnershipStatusResponse contains the response from method Subscription.AcceptOwnershipStatus. +type SubscriptionAcceptOwnershipStatusResponse struct { + SubscriptionAcceptOwnershipStatusResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SubscriptionAcceptOwnershipStatusResult contains the result from method Subscription.AcceptOwnershipStatus. +type SubscriptionAcceptOwnershipStatusResult struct { + AcceptOwnershipStatusResponse +} + +// SubscriptionCancelResponse contains the response from method Subscription.Cancel. +type SubscriptionCancelResponse struct { + SubscriptionCancelResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SubscriptionCancelResult contains the result from method Subscription.Cancel. +type SubscriptionCancelResult struct { + CanceledSubscriptionID +} + +// SubscriptionEnableResponse contains the response from method Subscription.Enable. +type SubscriptionEnableResponse struct { + SubscriptionEnableResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SubscriptionEnableResult contains the result from method Subscription.Enable. +type SubscriptionEnableResult struct { + EnabledSubscriptionID +} + +// SubscriptionPolicyAddUpdatePolicyForTenantResponse contains the response from method SubscriptionPolicy.AddUpdatePolicyForTenant. +type SubscriptionPolicyAddUpdatePolicyForTenantResponse struct { + SubscriptionPolicyAddUpdatePolicyForTenantResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SubscriptionPolicyAddUpdatePolicyForTenantResult contains the result from method SubscriptionPolicy.AddUpdatePolicyForTenant. +type SubscriptionPolicyAddUpdatePolicyForTenantResult struct { + GetTenantPolicyResponse +} + +// SubscriptionPolicyGetPolicyForTenantResponse contains the response from method SubscriptionPolicy.GetPolicyForTenant. +type SubscriptionPolicyGetPolicyForTenantResponse struct { + SubscriptionPolicyGetPolicyForTenantResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SubscriptionPolicyGetPolicyForTenantResult contains the result from method SubscriptionPolicy.GetPolicyForTenant. +type SubscriptionPolicyGetPolicyForTenantResult struct { + GetTenantPolicyResponse +} + +// SubscriptionPolicyListPolicyForTenantResponse contains the response from method SubscriptionPolicy.ListPolicyForTenant. +type SubscriptionPolicyListPolicyForTenantResponse struct { + SubscriptionPolicyListPolicyForTenantResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SubscriptionPolicyListPolicyForTenantResult contains the result from method SubscriptionPolicy.ListPolicyForTenant. +type SubscriptionPolicyListPolicyForTenantResult struct { + GetTenantPolicyListResponse +} + +// SubscriptionRenameResponse contains the response from method Subscription.Rename. +type SubscriptionRenameResponse struct { + SubscriptionRenameResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// SubscriptionRenameResult contains the result from method Subscription.Rename. +type SubscriptionRenameResult struct { + RenamedSubscriptionID +} diff --git a/sdk/resourcemanager/subscription/armsubscription/zz_generated_subscription_client.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_subscription_client.go new file mode 100644 index 000000000000..455fb47d712c --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_subscription_client.go @@ -0,0 +1,338 @@ +//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 armsubscription + +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" +) + +// SubscriptionClient contains the methods for the Subscription group. +// Don't use this type directly, use NewSubscriptionClient() instead. +type SubscriptionClient struct { + ep string + pl runtime.Pipeline +} + +// NewSubscriptionClient creates a new instance of SubscriptionClient with the specified values. +func NewSubscriptionClient(credential azcore.TokenCredential, options *arm.ClientOptions) *SubscriptionClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &SubscriptionClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// BeginAcceptOwnership - Accept subscription ownership. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionClient) BeginAcceptOwnership(ctx context.Context, subscriptionID string, body AcceptOwnershipRequest, options *SubscriptionBeginAcceptOwnershipOptions) (SubscriptionAcceptOwnershipPollerResponse, error) { + resp, err := client.acceptOwnership(ctx, subscriptionID, body, options) + if err != nil { + return SubscriptionAcceptOwnershipPollerResponse{}, err + } + result := SubscriptionAcceptOwnershipPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("SubscriptionClient.AcceptOwnership", "", resp, client.pl, client.acceptOwnershipHandleError) + if err != nil { + return SubscriptionAcceptOwnershipPollerResponse{}, err + } + result.Poller = &SubscriptionAcceptOwnershipPoller{ + pt: pt, + } + return result, nil +} + +// AcceptOwnership - Accept subscription ownership. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionClient) acceptOwnership(ctx context.Context, subscriptionID string, body AcceptOwnershipRequest, options *SubscriptionBeginAcceptOwnershipOptions) (*http.Response, error) { + req, err := client.acceptOwnershipCreateRequest(ctx, subscriptionID, body, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusAccepted) { + return nil, client.acceptOwnershipHandleError(resp) + } + return resp, nil +} + +// acceptOwnershipCreateRequest creates the AcceptOwnership request. +func (client *SubscriptionClient) acceptOwnershipCreateRequest(ctx context.Context, subscriptionID string, body AcceptOwnershipRequest, options *SubscriptionBeginAcceptOwnershipOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/{subscriptionId}/acceptOwnership" + if subscriptionID == "" { + return nil, errors.New("parameter subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(subscriptionID)) + 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, body) +} + +// acceptOwnershipHandleError handles the AcceptOwnership error response. +func (client *SubscriptionClient) acceptOwnershipHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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) +} + +// AcceptOwnershipStatus - Accept subscription ownership status. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionClient) AcceptOwnershipStatus(ctx context.Context, subscriptionID string, options *SubscriptionAcceptOwnershipStatusOptions) (SubscriptionAcceptOwnershipStatusResponse, error) { + req, err := client.acceptOwnershipStatusCreateRequest(ctx, subscriptionID, options) + if err != nil { + return SubscriptionAcceptOwnershipStatusResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SubscriptionAcceptOwnershipStatusResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SubscriptionAcceptOwnershipStatusResponse{}, client.acceptOwnershipStatusHandleError(resp) + } + return client.acceptOwnershipStatusHandleResponse(resp) +} + +// acceptOwnershipStatusCreateRequest creates the AcceptOwnershipStatus request. +func (client *SubscriptionClient) acceptOwnershipStatusCreateRequest(ctx context.Context, subscriptionID string, options *SubscriptionAcceptOwnershipStatusOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/{subscriptionId}/acceptOwnershipStatus" + if subscriptionID == "" { + return nil, errors.New("parameter subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(subscriptionID)) + 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 +} + +// acceptOwnershipStatusHandleResponse handles the AcceptOwnershipStatus response. +func (client *SubscriptionClient) acceptOwnershipStatusHandleResponse(resp *http.Response) (SubscriptionAcceptOwnershipStatusResponse, error) { + result := SubscriptionAcceptOwnershipStatusResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.AcceptOwnershipStatusResponse); err != nil { + return SubscriptionAcceptOwnershipStatusResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// acceptOwnershipStatusHandleError handles the AcceptOwnershipStatus error response. +func (client *SubscriptionClient) acceptOwnershipStatusHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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) +} + +// Cancel - The operation to cancel a subscription +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionClient) Cancel(ctx context.Context, subscriptionID string, options *SubscriptionCancelOptions) (SubscriptionCancelResponse, error) { + req, err := client.cancelCreateRequest(ctx, subscriptionID, options) + if err != nil { + return SubscriptionCancelResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SubscriptionCancelResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SubscriptionCancelResponse{}, client.cancelHandleError(resp) + } + return client.cancelHandleResponse(resp) +} + +// cancelCreateRequest creates the Cancel request. +func (client *SubscriptionClient) cancelCreateRequest(ctx context.Context, subscriptionID string, options *SubscriptionCancelOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Subscription/cancel" + if subscriptionID == "" { + return nil, errors.New("parameter subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(subscriptionID)) + 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 +} + +// cancelHandleResponse handles the Cancel response. +func (client *SubscriptionClient) cancelHandleResponse(resp *http.Response) (SubscriptionCancelResponse, error) { + result := SubscriptionCancelResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.CanceledSubscriptionID); err != nil { + return SubscriptionCancelResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// cancelHandleError handles the Cancel error response. +func (client *SubscriptionClient) cancelHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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) +} + +// Enable - The operation to enable a subscription +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionClient) Enable(ctx context.Context, subscriptionID string, options *SubscriptionEnableOptions) (SubscriptionEnableResponse, error) { + req, err := client.enableCreateRequest(ctx, subscriptionID, options) + if err != nil { + return SubscriptionEnableResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SubscriptionEnableResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SubscriptionEnableResponse{}, client.enableHandleError(resp) + } + return client.enableHandleResponse(resp) +} + +// enableCreateRequest creates the Enable request. +func (client *SubscriptionClient) enableCreateRequest(ctx context.Context, subscriptionID string, options *SubscriptionEnableOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Subscription/enable" + if subscriptionID == "" { + return nil, errors.New("parameter subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(subscriptionID)) + 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 +} + +// enableHandleResponse handles the Enable response. +func (client *SubscriptionClient) enableHandleResponse(resp *http.Response) (SubscriptionEnableResponse, error) { + result := SubscriptionEnableResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.EnabledSubscriptionID); err != nil { + return SubscriptionEnableResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// enableHandleError handles the Enable error response. +func (client *SubscriptionClient) enableHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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) +} + +// Rename - The operation to rename a subscription +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionClient) Rename(ctx context.Context, subscriptionID string, body SubscriptionName, options *SubscriptionRenameOptions) (SubscriptionRenameResponse, error) { + req, err := client.renameCreateRequest(ctx, subscriptionID, body, options) + if err != nil { + return SubscriptionRenameResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SubscriptionRenameResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SubscriptionRenameResponse{}, client.renameHandleError(resp) + } + return client.renameHandleResponse(resp) +} + +// renameCreateRequest creates the Rename request. +func (client *SubscriptionClient) renameCreateRequest(ctx context.Context, subscriptionID string, body SubscriptionName, options *SubscriptionRenameOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Subscription/rename" + if subscriptionID == "" { + return nil, errors.New("parameter subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(subscriptionID)) + 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, body) +} + +// renameHandleResponse handles the Rename response. +func (client *SubscriptionClient) renameHandleResponse(resp *http.Response) (SubscriptionRenameResponse, error) { + result := SubscriptionRenameResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.RenamedSubscriptionID); err != nil { + return SubscriptionRenameResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// renameHandleError handles the Rename error response. +func (client *SubscriptionClient) renameHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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/subscription/armsubscription/zz_generated_subscriptionpolicy_client.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_subscriptionpolicy_client.go new file mode 100644 index 000000000000..6ffd870739c0 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/zz_generated_subscriptionpolicy_client.go @@ -0,0 +1,195 @@ +//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 armsubscription + +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" +) + +// SubscriptionPolicyClient contains the methods for the SubscriptionPolicy group. +// Don't use this type directly, use NewSubscriptionPolicyClient() instead. +type SubscriptionPolicyClient struct { + ep string + pl runtime.Pipeline +} + +// NewSubscriptionPolicyClient creates a new instance of SubscriptionPolicyClient with the specified values. +func NewSubscriptionPolicyClient(credential azcore.TokenCredential, options *arm.ClientOptions) *SubscriptionPolicyClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &SubscriptionPolicyClient{ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// AddUpdatePolicyForTenant - Create or Update Subscription tenant policy for user's tenant. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionPolicyClient) AddUpdatePolicyForTenant(ctx context.Context, body PutTenantPolicyRequestProperties, options *SubscriptionPolicyAddUpdatePolicyForTenantOptions) (SubscriptionPolicyAddUpdatePolicyForTenantResponse, error) { + req, err := client.addUpdatePolicyForTenantCreateRequest(ctx, body, options) + if err != nil { + return SubscriptionPolicyAddUpdatePolicyForTenantResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SubscriptionPolicyAddUpdatePolicyForTenantResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusCreated) { + return SubscriptionPolicyAddUpdatePolicyForTenantResponse{}, client.addUpdatePolicyForTenantHandleError(resp) + } + return client.addUpdatePolicyForTenantHandleResponse(resp) +} + +// addUpdatePolicyForTenantCreateRequest creates the AddUpdatePolicyForTenant request. +func (client *SubscriptionPolicyClient) addUpdatePolicyForTenantCreateRequest(ctx context.Context, body PutTenantPolicyRequestProperties, options *SubscriptionPolicyAddUpdatePolicyForTenantOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/policies/default" + 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, body) +} + +// addUpdatePolicyForTenantHandleResponse handles the AddUpdatePolicyForTenant response. +func (client *SubscriptionPolicyClient) addUpdatePolicyForTenantHandleResponse(resp *http.Response) (SubscriptionPolicyAddUpdatePolicyForTenantResponse, error) { + result := SubscriptionPolicyAddUpdatePolicyForTenantResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.GetTenantPolicyResponse); err != nil { + return SubscriptionPolicyAddUpdatePolicyForTenantResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// addUpdatePolicyForTenantHandleError handles the AddUpdatePolicyForTenant error response. +func (client *SubscriptionPolicyClient) addUpdatePolicyForTenantHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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) +} + +// GetPolicyForTenant - Get the subscription tenant policy for the user's tenant. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionPolicyClient) GetPolicyForTenant(ctx context.Context, options *SubscriptionPolicyGetPolicyForTenantOptions) (SubscriptionPolicyGetPolicyForTenantResponse, error) { + req, err := client.getPolicyForTenantCreateRequest(ctx, options) + if err != nil { + return SubscriptionPolicyGetPolicyForTenantResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return SubscriptionPolicyGetPolicyForTenantResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return SubscriptionPolicyGetPolicyForTenantResponse{}, client.getPolicyForTenantHandleError(resp) + } + return client.getPolicyForTenantHandleResponse(resp) +} + +// getPolicyForTenantCreateRequest creates the GetPolicyForTenant request. +func (client *SubscriptionPolicyClient) getPolicyForTenantCreateRequest(ctx context.Context, options *SubscriptionPolicyGetPolicyForTenantOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/policies/default" + 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 +} + +// getPolicyForTenantHandleResponse handles the GetPolicyForTenant response. +func (client *SubscriptionPolicyClient) getPolicyForTenantHandleResponse(resp *http.Response) (SubscriptionPolicyGetPolicyForTenantResponse, error) { + result := SubscriptionPolicyGetPolicyForTenantResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.GetTenantPolicyResponse); err != nil { + return SubscriptionPolicyGetPolicyForTenantResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getPolicyForTenantHandleError handles the GetPolicyForTenant error response. +func (client *SubscriptionPolicyClient) getPolicyForTenantHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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) +} + +// ListPolicyForTenant - Get the subscription tenant policy for the user's tenant. +// If the operation fails it returns the *ErrorResponseBody error type. +func (client *SubscriptionPolicyClient) ListPolicyForTenant(options *SubscriptionPolicyListPolicyForTenantOptions) *SubscriptionPolicyListPolicyForTenantPager { + return &SubscriptionPolicyListPolicyForTenantPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listPolicyForTenantCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp SubscriptionPolicyListPolicyForTenantResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.GetTenantPolicyListResponse.NextLink) + }, + } +} + +// listPolicyForTenantCreateRequest creates the ListPolicyForTenant request. +func (client *SubscriptionPolicyClient) listPolicyForTenantCreateRequest(ctx context.Context, options *SubscriptionPolicyListPolicyForTenantOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.Subscription/policies" + 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 +} + +// listPolicyForTenantHandleResponse handles the ListPolicyForTenant response. +func (client *SubscriptionPolicyClient) listPolicyForTenantHandleResponse(resp *http.Response) (SubscriptionPolicyListPolicyForTenantResponse, error) { + result := SubscriptionPolicyListPolicyForTenantResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.GetTenantPolicyListResponse); err != nil { + return SubscriptionPolicyListPolicyForTenantResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listPolicyForTenantHandleError handles the ListPolicyForTenant error response. +func (client *SubscriptionPolicyClient) listPolicyForTenantHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := ErrorResponseBody{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/subscription/armsubscription/zz_generated_time_rfc3339.go b/sdk/resourcemanager/subscription/armsubscription/zz_generated_time_rfc3339.go new file mode 100644 index 000000000000..b55e151d5987 --- /dev/null +++ b/sdk/resourcemanager/subscription/armsubscription/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 armsubscription + +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 +}