diff --git a/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/CHANGELOG.md b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/CHANGELOG.md new file mode 100644 index 000000000000..17b9dceace74 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/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/postgresqlhsc/armpostgresqlhsc/LICENSE.txt b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/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/postgresqlhsc/armpostgresqlhsc/README.md b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/README.md new file mode 100644 index 000000000000..81fe76092bfc --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/README.md @@ -0,0 +1,75 @@ +# Azure Postgresqlhsc Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc) + +The `armpostgresqlhsc` module provides operations for working with Azure Postgresqlhsc. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc) + +# 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 Postgresqlhsc module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Postgresqlhsc. 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 Postgresqlhsc 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 := armpostgresqlhsc.NewServersClient(, 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 := armpostgresqlhsc.NewServersClient(, 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 `Postgresqlhsc` 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/postgresqlhsc/armpostgresqlhsc/autorest.md b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/autorest.md new file mode 100644 index 000000000000..4026a2f280d8 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/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/postgresqlhsc/resource-manager/readme.md +- /home/vsts/work/1/s/azure-rest-api-specs/specification/postgresqlhsc/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/postgresqlhsc/armpostgresqlhsc/build.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/build.go new file mode 100644 index 000000000000..2bd24640a6ac --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/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/postgresqlhsc/armpostgresqlhsc + +package armpostgresqlhsc diff --git a/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/ci.yml b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/ci.yml new file mode 100644 index 000000000000..068486d9b364 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/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/postgresqlhsc/armpostgresqlhsc/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'resourcemanager/postgresqlhsc/armpostgresqlhsc' diff --git a/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/go.mod b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/go.mod new file mode 100644 index 000000000000..6c528e5794f4 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/go.mod @@ -0,0 +1,8 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc + +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/postgresqlhsc/armpostgresqlhsc/go.sum b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/go.sum new file mode 100644 index 000000000000..960c6c966a3f --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/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/postgresqlhsc/armpostgresqlhsc/go_mod_tidy_hack.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/go_mod_tidy_hack.go new file mode 100644 index 000000000000..83427a8d5b63 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/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 armpostgresqlhsc + +// 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/postgresqlhsc/armpostgresqlhsc/zz_generated_configurations_client.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_configurations_client.go new file mode 100644 index 000000000000..cdc3dfefaeb9 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_configurations_client.go @@ -0,0 +1,320 @@ +//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 armpostgresqlhsc + +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" +) + +// ConfigurationsClient contains the methods for the Configurations group. +// Don't use this type directly, use NewConfigurationsClient() instead. +type ConfigurationsClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewConfigurationsClient creates a new instance of ConfigurationsClient with the specified values. +func NewConfigurationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) *ConfigurationsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &ConfigurationsClient{subscriptionID: subscriptionID, ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// Get - Gets information about single server group configuration. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) Get(ctx context.Context, resourceGroupName string, serverGroupName string, configurationName string, options *ConfigurationsGetOptions) (ConfigurationsGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverGroupName, configurationName, options) + if err != nil { + return ConfigurationsGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ConfigurationsGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ConfigurationsGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ConfigurationsClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, configurationName string, options *ConfigurationsGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/configurations/{configurationName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if configurationName == "" { + return nil, errors.New("parameter configurationName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ConfigurationsClient) getHandleResponse(resp *http.Response) (ConfigurationsGetResponse, error) { + result := ConfigurationsGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerGroupConfiguration); err != nil { + return ConfigurationsGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *ConfigurationsClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// ListByServer - List all the configurations of a server in server group. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) ListByServer(resourceGroupName string, serverGroupName string, serverName string, options *ConfigurationsListByServerOptions) *ConfigurationsListByServerPager { + return &ConfigurationsListByServerPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByServerCreateRequest(ctx, resourceGroupName, serverGroupName, serverName, options) + }, + advancer: func(ctx context.Context, resp ConfigurationsListByServerResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ServerConfigurationListResult.NextLink) + }, + } +} + +// listByServerCreateRequest creates the ListByServer request. +func (client *ConfigurationsClient) listByServerCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, serverName string, options *ConfigurationsListByServerOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/servers/{serverName}/configurations" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerHandleResponse handles the ListByServer response. +func (client *ConfigurationsClient) listByServerHandleResponse(resp *http.Response) (ConfigurationsListByServerResponse, error) { + result := ConfigurationsListByServerResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerConfigurationListResult); err != nil { + return ConfigurationsListByServerResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listByServerHandleError handles the ListByServer error response. +func (client *ConfigurationsClient) listByServerHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// ListByServerGroup - List all the configurations of a server group. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) ListByServerGroup(resourceGroupName string, serverGroupName string, options *ConfigurationsListByServerGroupOptions) *ConfigurationsListByServerGroupPager { + return &ConfigurationsListByServerGroupPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByServerGroupCreateRequest(ctx, resourceGroupName, serverGroupName, options) + }, + advancer: func(ctx context.Context, resp ConfigurationsListByServerGroupResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ServerGroupConfigurationListResult.NextLink) + }, + } +} + +// listByServerGroupCreateRequest creates the ListByServerGroup request. +func (client *ConfigurationsClient) listByServerGroupCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *ConfigurationsListByServerGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/configurations" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerGroupHandleResponse handles the ListByServerGroup response. +func (client *ConfigurationsClient) listByServerGroupHandleResponse(resp *http.Response) (ConfigurationsListByServerGroupResponse, error) { + result := ConfigurationsListByServerGroupResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerGroupConfigurationListResult); err != nil { + return ConfigurationsListByServerGroupResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listByServerGroupHandleError handles the ListByServerGroup error response. +func (client *ConfigurationsClient) listByServerGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginUpdate - Updates configuration of server role groups in a server group +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) BeginUpdate(ctx context.Context, resourceGroupName string, serverGroupName string, configurationName string, parameters ServerGroupConfiguration, options *ConfigurationsBeginUpdateOptions) (ConfigurationsUpdatePollerResponse, error) { + resp, err := client.update(ctx, resourceGroupName, serverGroupName, configurationName, parameters, options) + if err != nil { + return ConfigurationsUpdatePollerResponse{}, err + } + result := ConfigurationsUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ConfigurationsClient.Update", "", resp, client.pl, client.updateHandleError) + if err != nil { + return ConfigurationsUpdatePollerResponse{}, err + } + result.Poller = &ConfigurationsUpdatePoller{ + pt: pt, + } + return result, nil +} + +// Update - Updates configuration of server role groups in a server group +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) update(ctx context.Context, resourceGroupName string, serverGroupName string, configurationName string, parameters ServerGroupConfiguration, options *ConfigurationsBeginUpdateOptions) (*http.Response, error) { + req, err := client.updateCreateRequest(ctx, resourceGroupName, serverGroupName, configurationName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.updateHandleError(resp) + } + return resp, nil +} + +// updateCreateRequest creates the Update request. +func (client *ConfigurationsClient) updateCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, configurationName string, parameters ServerGroupConfiguration, options *ConfigurationsBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/configurations/{configurationName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if configurationName == "" { + return nil, errors.New("parameter configurationName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// updateHandleError handles the Update error response. +func (client *ConfigurationsClient) updateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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/postgresqlhsc/armpostgresqlhsc/zz_generated_constants.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_constants.go new file mode 100644 index 000000000000..768a4a3177a0 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_constants.go @@ -0,0 +1,289 @@ +//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 armpostgresqlhsc + +const ( + module = "armpostgresqlhsc" + version = "v0.1.0" +) + +// CitusVersion - The Citus version. +type CitusVersion string + +const ( + CitusVersionEight3 CitusVersion = "8.3" + CitusVersionNine0 CitusVersion = "9.0" + CitusVersionNine1 CitusVersion = "9.1" + CitusVersionNine2 CitusVersion = "9.2" + CitusVersionNine3 CitusVersion = "9.3" + CitusVersionNine4 CitusVersion = "9.4" + CitusVersionNine5 CitusVersion = "9.5" +) + +// PossibleCitusVersionValues returns the possible values for the CitusVersion const type. +func PossibleCitusVersionValues() []CitusVersion { + return []CitusVersion{ + CitusVersionEight3, + CitusVersionNine0, + CitusVersionNine1, + CitusVersionNine2, + CitusVersionNine3, + CitusVersionNine4, + CitusVersionNine5, + } +} + +// ToPtr returns a *CitusVersion pointing to the current value. +func (c CitusVersion) ToPtr() *CitusVersion { + return &c +} + +// ConfigurationDataType - Data type of the configuration. +type ConfigurationDataType string + +const ( + ConfigurationDataTypeBoolean ConfigurationDataType = "Boolean" + ConfigurationDataTypeEnumeration ConfigurationDataType = "Enumeration" + ConfigurationDataTypeInteger ConfigurationDataType = "Integer" + ConfigurationDataTypeNumeric ConfigurationDataType = "Numeric" +) + +// PossibleConfigurationDataTypeValues returns the possible values for the ConfigurationDataType const type. +func PossibleConfigurationDataTypeValues() []ConfigurationDataType { + return []ConfigurationDataType{ + ConfigurationDataTypeBoolean, + ConfigurationDataTypeEnumeration, + ConfigurationDataTypeInteger, + ConfigurationDataTypeNumeric, + } +} + +// ToPtr returns a *ConfigurationDataType pointing to the current value. +func (c ConfigurationDataType) ToPtr() *ConfigurationDataType { + return &c +} + +// CreateMode - The mode to create a new server group. +type CreateMode string + +const ( + CreateModeDefault CreateMode = "Default" + CreateModePointInTimeRestore CreateMode = "PointInTimeRestore" + CreateModeReadReplica CreateMode = "ReadReplica" +) + +// PossibleCreateModeValues returns the possible values for the CreateMode const type. +func PossibleCreateModeValues() []CreateMode { + return []CreateMode{ + CreateModeDefault, + CreateModePointInTimeRestore, + CreateModeReadReplica, + } +} + +// ToPtr returns a *CreateMode pointing to the current value. +func (c CreateMode) ToPtr() *CreateMode { + 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 +} + +// OperationOrigin - The intended executor of the operation. +type OperationOrigin string + +const ( + OperationOriginNotSpecified OperationOrigin = "NotSpecified" + OperationOriginSystem OperationOrigin = "system" + OperationOriginUser OperationOrigin = "user" +) + +// PossibleOperationOriginValues returns the possible values for the OperationOrigin const type. +func PossibleOperationOriginValues() []OperationOrigin { + return []OperationOrigin{ + OperationOriginNotSpecified, + OperationOriginSystem, + OperationOriginUser, + } +} + +// ToPtr returns a *OperationOrigin pointing to the current value. +func (c OperationOrigin) ToPtr() *OperationOrigin { + return &c +} + +// PostgreSQLVersion - The PostgreSQL version. +type PostgreSQLVersion string + +const ( + PostgreSQLVersionEleven PostgreSQLVersion = "11" + PostgreSQLVersionTwelve PostgreSQLVersion = "12" +) + +// PossiblePostgreSQLVersionValues returns the possible values for the PostgreSQLVersion const type. +func PossiblePostgreSQLVersionValues() []PostgreSQLVersion { + return []PostgreSQLVersion{ + PostgreSQLVersionEleven, + PostgreSQLVersionTwelve, + } +} + +// ToPtr returns a *PostgreSQLVersion pointing to the current value. +func (c PostgreSQLVersion) ToPtr() *PostgreSQLVersion { + return &c +} + +// ResourceProviderType - The resource provider type of server group. +type ResourceProviderType string + +const ( + ResourceProviderTypeMarlin ResourceProviderType = "Marlin" + ResourceProviderTypeMeru ResourceProviderType = "Meru" +) + +// PossibleResourceProviderTypeValues returns the possible values for the ResourceProviderType const type. +func PossibleResourceProviderTypeValues() []ResourceProviderType { + return []ResourceProviderType{ + ResourceProviderTypeMarlin, + ResourceProviderTypeMeru, + } +} + +// ToPtr returns a *ResourceProviderType pointing to the current value. +func (c ResourceProviderType) ToPtr() *ResourceProviderType { + return &c +} + +// ServerEdition - The edition of a server (default: GeneralPurpose). +type ServerEdition string + +const ( + ServerEditionGeneralPurpose ServerEdition = "GeneralPurpose" + ServerEditionMemoryOptimized ServerEdition = "MemoryOptimized" +) + +// PossibleServerEditionValues returns the possible values for the ServerEdition const type. +func PossibleServerEditionValues() []ServerEdition { + return []ServerEdition{ + ServerEditionGeneralPurpose, + ServerEditionMemoryOptimized, + } +} + +// ToPtr returns a *ServerEdition pointing to the current value. +func (c ServerEdition) ToPtr() *ServerEdition { + return &c +} + +// ServerHaState - A state of a server role group/server that is visible to user for HA feature. +type ServerHaState string + +const ( + ServerHaStateCreatingStandby ServerHaState = "CreatingStandby" + ServerHaStateFailingOver ServerHaState = "FailingOver" + ServerHaStateHealthy ServerHaState = "Healthy" + ServerHaStateNotEnabled ServerHaState = "NotEnabled" + ServerHaStateNotSync ServerHaState = "NotSync" + ServerHaStateRemovingStandby ServerHaState = "RemovingStandby" + ServerHaStateReplicatingData ServerHaState = "ReplicatingData" +) + +// PossibleServerHaStateValues returns the possible values for the ServerHaState const type. +func PossibleServerHaStateValues() []ServerHaState { + return []ServerHaState{ + ServerHaStateCreatingStandby, + ServerHaStateFailingOver, + ServerHaStateHealthy, + ServerHaStateNotEnabled, + ServerHaStateNotSync, + ServerHaStateRemovingStandby, + ServerHaStateReplicatingData, + } +} + +// ToPtr returns a *ServerHaState pointing to the current value. +func (c ServerHaState) ToPtr() *ServerHaState { + return &c +} + +// ServerRole - The role of a server. +type ServerRole string + +const ( + ServerRoleCoordinator ServerRole = "Coordinator" + ServerRoleWorker ServerRole = "Worker" +) + +// PossibleServerRoleValues returns the possible values for the ServerRole const type. +func PossibleServerRoleValues() []ServerRole { + return []ServerRole{ + ServerRoleCoordinator, + ServerRoleWorker, + } +} + +// ToPtr returns a *ServerRole pointing to the current value. +func (c ServerRole) ToPtr() *ServerRole { + return &c +} + +// ServerState - A state of a server group/server that is visible to user. +type ServerState string + +const ( + ServerStateDisabled ServerState = "Disabled" + ServerStateDropping ServerState = "Dropping" + ServerStateProvisioning ServerState = "Provisioning" + ServerStateReady ServerState = "Ready" + ServerStateStarting ServerState = "Starting" + ServerStateStopped ServerState = "Stopped" + ServerStateStopping ServerState = "Stopping" + ServerStateUpdating ServerState = "Updating" +) + +// PossibleServerStateValues returns the possible values for the ServerState const type. +func PossibleServerStateValues() []ServerState { + return []ServerState{ + ServerStateDisabled, + ServerStateDropping, + ServerStateProvisioning, + ServerStateReady, + ServerStateStarting, + ServerStateStopped, + ServerStateStopping, + ServerStateUpdating, + } +} + +// ToPtr returns a *ServerState pointing to the current value. +func (c ServerState) ToPtr() *ServerState { + return &c +} diff --git a/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_firewallrules_client.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_firewallrules_client.go new file mode 100644 index 000000000000..989859dcdec8 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_firewallrules_client.go @@ -0,0 +1,337 @@ +//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 armpostgresqlhsc + +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" +) + +// FirewallRulesClient contains the methods for the FirewallRules group. +// Don't use this type directly, use NewFirewallRulesClient() instead. +type FirewallRulesClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewFirewallRulesClient creates a new instance of FirewallRulesClient with the specified values. +func NewFirewallRulesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) *FirewallRulesClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &FirewallRulesClient{subscriptionID: subscriptionID, ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// BeginCreateOrUpdate - Creates a new firewall rule or updates an existing firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, serverGroupName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesBeginCreateOrUpdateOptions) (FirewallRulesCreateOrUpdatePollerResponse, error) { + resp, err := client.createOrUpdate(ctx, resourceGroupName, serverGroupName, firewallRuleName, parameters, options) + if err != nil { + return FirewallRulesCreateOrUpdatePollerResponse{}, err + } + result := FirewallRulesCreateOrUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("FirewallRulesClient.CreateOrUpdate", "", resp, client.pl, client.createOrUpdateHandleError) + if err != nil { + return FirewallRulesCreateOrUpdatePollerResponse{}, err + } + result.Poller = &FirewallRulesCreateOrUpdatePoller{ + pt: pt, + } + return result, nil +} + +// CreateOrUpdate - Creates a new firewall rule or updates an existing firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) createOrUpdate(ctx context.Context, resourceGroupName string, serverGroupName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesBeginCreateOrUpdateOptions) (*http.Response, error) { + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, serverGroupName, firewallRuleName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + return nil, client.createOrUpdateHandleError(resp) + } + return resp, nil +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *FirewallRulesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/firewallRules/{firewallRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if firewallRuleName == "" { + return nil, errors.New("parameter firewallRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{firewallRuleName}", url.PathEscape(firewallRuleName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleError handles the CreateOrUpdate error response. +func (client *FirewallRulesClient) createOrUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginDelete - Deletes a server group firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) BeginDelete(ctx context.Context, resourceGroupName string, serverGroupName string, firewallRuleName string, options *FirewallRulesBeginDeleteOptions) (FirewallRulesDeletePollerResponse, error) { + resp, err := client.deleteOperation(ctx, resourceGroupName, serverGroupName, firewallRuleName, options) + if err != nil { + return FirewallRulesDeletePollerResponse{}, err + } + result := FirewallRulesDeletePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("FirewallRulesClient.Delete", "", resp, client.pl, client.deleteHandleError) + if err != nil { + return FirewallRulesDeletePollerResponse{}, err + } + result.Poller = &FirewallRulesDeletePoller{ + pt: pt, + } + return result, nil +} + +// Delete - Deletes a server group firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, serverGroupName string, firewallRuleName string, options *FirewallRulesBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, serverGroupName, firewallRuleName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + return nil, client.deleteHandleError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *FirewallRulesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, firewallRuleName string, options *FirewallRulesBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/firewallRules/{firewallRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if firewallRuleName == "" { + return nil, errors.New("parameter firewallRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{firewallRuleName}", url.PathEscape(firewallRuleName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *FirewallRulesClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Gets information about a server group firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) Get(ctx context.Context, resourceGroupName string, serverGroupName string, firewallRuleName string, options *FirewallRulesGetOptions) (FirewallRulesGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverGroupName, firewallRuleName, options) + if err != nil { + return FirewallRulesGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return FirewallRulesGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return FirewallRulesGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *FirewallRulesClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, firewallRuleName string, options *FirewallRulesGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/firewallRules/{firewallRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if firewallRuleName == "" { + return nil, errors.New("parameter firewallRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{firewallRuleName}", url.PathEscape(firewallRuleName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *FirewallRulesClient) getHandleResponse(resp *http.Response) (FirewallRulesGetResponse, error) { + result := FirewallRulesGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.FirewallRule); err != nil { + return FirewallRulesGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *FirewallRulesClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// ListByServerGroup - List all the firewall rules in a given server group. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) ListByServerGroup(ctx context.Context, resourceGroupName string, serverGroupName string, options *FirewallRulesListByServerGroupOptions) (FirewallRulesListByServerGroupResponse, error) { + req, err := client.listByServerGroupCreateRequest(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return FirewallRulesListByServerGroupResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return FirewallRulesListByServerGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return FirewallRulesListByServerGroupResponse{}, client.listByServerGroupHandleError(resp) + } + return client.listByServerGroupHandleResponse(resp) +} + +// listByServerGroupCreateRequest creates the ListByServerGroup request. +func (client *FirewallRulesClient) listByServerGroupCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *FirewallRulesListByServerGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/firewallRules" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerGroupHandleResponse handles the ListByServerGroup response. +func (client *FirewallRulesClient) listByServerGroupHandleResponse(resp *http.Response) (FirewallRulesListByServerGroupResponse, error) { + result := FirewallRulesListByServerGroupResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.FirewallRuleListResult); err != nil { + return FirewallRulesListByServerGroupResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listByServerGroupHandleError handles the ListByServerGroup error response. +func (client *FirewallRulesClient) listByServerGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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/postgresqlhsc/armpostgresqlhsc/zz_generated_models.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_models.go new file mode 100644 index 000000000000..a8c6cfb35f60 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_models.go @@ -0,0 +1,1092 @@ +//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 armpostgresqlhsc + +import ( + "encoding/json" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" + "time" +) + +// CloudError - An error response from the Batch service. +// Implements the error and azcore.HTTPResponse interfaces. +type CloudError struct { + raw string + // The error. + InnerError *CloudErrorBody `json:"error,omitempty"` +} + +// Error implements the error interface for type CloudError. +// The contents of the error text are not contractual and subject to change. +func (e CloudError) Error() string { + return e.raw +} + +// CloudErrorBody - An error response from the Batch service. +type CloudErrorBody struct { + // An identifier for the error. Codes are invariant and are intended to be consumed programmatically. + Code *string `json:"code,omitempty"` + + // A list of additional details about the error. + Details []*CloudErrorBody `json:"details,omitempty"` + + // A message describing the error, intended to be suitable for display in a user interface. + Message *string `json:"message,omitempty"` + + // The target of the particular error. For example, the name of the property in error. + Target *string `json:"target,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type CloudErrorBody. +func (c CloudErrorBody) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "code", c.Code) + populate(objectMap, "details", c.Details) + populate(objectMap, "message", c.Message) + populate(objectMap, "target", c.Target) + return json.Marshal(objectMap) +} + +// ConfigurationsBeginUpdateOptions contains the optional parameters for the Configurations.BeginUpdate method. +type ConfigurationsBeginUpdateOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsGetOptions contains the optional parameters for the Configurations.Get method. +type ConfigurationsGetOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsListByServerGroupOptions contains the optional parameters for the Configurations.ListByServerGroup method. +type ConfigurationsListByServerGroupOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsListByServerOptions contains the optional parameters for the Configurations.ListByServer method. +type ConfigurationsListByServerOptions struct { + // placeholder for future optional parameters +} + +// FirewallRule - Represents a server group firewall rule. +type FirewallRule struct { + ProxyResource + // REQUIRED; The properties of a firewall rule. + Properties *FirewallRuleProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type FirewallRule. +func (f FirewallRule) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + f.ProxyResource.marshalInternal(objectMap) + populate(objectMap, "properties", f.Properties) + populate(objectMap, "systemData", f.SystemData) + return json.Marshal(objectMap) +} + +// FirewallRuleListResult - A list of firewall rules. +type FirewallRuleListResult struct { + // The list of firewall rules in a server group. + Value []*FirewallRule `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type FirewallRuleListResult. +func (f FirewallRuleListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "value", f.Value) + return json.Marshal(objectMap) +} + +// FirewallRuleProperties - The properties of a server group firewall rule. +type FirewallRuleProperties struct { + // REQUIRED; The end IP address of the server group firewall rule. Must be IPv4 format. + EndIPAddress *string `json:"endIpAddress,omitempty"` + + // REQUIRED; The start IP address of the server group firewall rule. Must be IPv4 format. + StartIPAddress *string `json:"startIpAddress,omitempty"` +} + +// FirewallRulesBeginCreateOrUpdateOptions contains the optional parameters for the FirewallRules.BeginCreateOrUpdate method. +type FirewallRulesBeginCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// FirewallRulesBeginDeleteOptions contains the optional parameters for the FirewallRules.BeginDelete method. +type FirewallRulesBeginDeleteOptions struct { + // placeholder for future optional parameters +} + +// FirewallRulesGetOptions contains the optional parameters for the FirewallRules.Get method. +type FirewallRulesGetOptions struct { + // placeholder for future optional parameters +} + +// FirewallRulesListByServerGroupOptions contains the optional parameters for the FirewallRules.ListByServerGroup method. +type FirewallRulesListByServerGroupOptions struct { + // placeholder for future optional parameters +} + +// MaintenanceWindow - Maintenance window of a server group. +type MaintenanceWindow struct { + // indicates whether custom window is enabled or disabled + CustomWindow *string `json:"customWindow,omitempty"` + + // day of week for maintenance window + DayOfWeek *int32 `json:"dayOfWeek,omitempty"` + + // start hour for maintenance window + StartHour *int32 `json:"startHour,omitempty"` + + // start minute for maintenance window + StartMinute *int32 `json:"startMinute,omitempty"` +} + +// NameAvailability - Represents a resource name availability. +type NameAvailability struct { + // Error Message. + Message *string `json:"message,omitempty"` + + // name of the PostgreSQL server. + Name *string `json:"name,omitempty"` + + // Indicates whether the resource name is available. + NameAvailable *bool `json:"nameAvailable,omitempty"` + + // type of the server + Type *string `json:"type,omitempty"` +} + +// NameAvailabilityRequest - Request from client to check resource name availability. +type NameAvailabilityRequest struct { + // REQUIRED; Resource name to verify. + Name *string `json:"name,omitempty"` + + // REQUIRED; Resource type used for verification. + Type *string `json:"type,omitempty"` +} + +// Operation - REST API operation definition. +type Operation struct { + // Indicates whether the operation is a data action + IsDataAction *bool `json:"isDataAction,omitempty"` + + // READ-ONLY; The localized display information for this particular operation or action. + Display *OperationDisplay `json:"display,omitempty" azure:"ro"` + + // READ-ONLY; The name of the operation being performed on this particular object. + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; The intended executor of the operation. + Origin *OperationOrigin `json:"origin,omitempty" azure:"ro"` + + // READ-ONLY; Additional descriptions for the operation. + Properties map[string]map[string]interface{} `json:"properties,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Operation. +func (o Operation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "display", o.Display) + populate(objectMap, "isDataAction", o.IsDataAction) + populate(objectMap, "name", o.Name) + populate(objectMap, "origin", o.Origin) + populate(objectMap, "properties", o.Properties) + return json.Marshal(objectMap) +} + +// OperationDisplay - Display metadata associated with the operation. +type OperationDisplay struct { + // READ-ONLY; Operation description. + Description *string `json:"description,omitempty" azure:"ro"` + + // READ-ONLY; Localized friendly name for the operation. + Operation *string `json:"operation,omitempty" azure:"ro"` + + // READ-ONLY; Operation resource provider name. + Provider *string `json:"provider,omitempty" azure:"ro"` + + // READ-ONLY; Resource on which the operation is performed. + Resource *string `json:"resource,omitempty" azure:"ro"` +} + +// OperationListResult - A list of resource provider operations. +type OperationListResult struct { + // Collection of available operation details + Value []*Operation `json:"value,omitempty"` + + // READ-ONLY; URL client should use to fetch the next page (per server side paging). It's null for now, added for future use. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// OperationsListOptions contains the optional parameters for the Operations.List method. +type OperationsListOptions struct { + // placeholder for future optional parameters +} + +// ProxyResource - The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location +type ProxyResource struct { + Resource +} + +func (p ProxyResource) marshalInternal(objectMap map[string]interface{}) { + p.Resource.marshalInternal(objectMap) +} + +// Resource - Common fields that are returned in the response for all Azure Resource Manager resources +type Resource struct { + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; The name of the resource + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Resource. +func (r Resource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + r.marshalInternal(objectMap) + return json.Marshal(objectMap) +} + +func (r Resource) marshalInternal(objectMap map[string]interface{}) { + populate(objectMap, "id", r.ID) + populate(objectMap, "name", r.Name) + populate(objectMap, "type", r.Type) +} + +// Role - Represents a server group role. +type Role struct { + ProxyResource + // The properties of a role. + Properties *RoleProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Role. +func (r Role) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + r.ProxyResource.marshalInternal(objectMap) + populate(objectMap, "properties", r.Properties) + populate(objectMap, "systemData", r.SystemData) + return json.Marshal(objectMap) +} + +// RoleListResult - A list of roles. +type RoleListResult struct { + // The list of roles in a server group. + Value []*Role `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type RoleListResult. +func (r RoleListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "value", r.Value) + return json.Marshal(objectMap) +} + +// RoleProperties - The properties of a server group role. +type RoleProperties struct { + // REQUIRED; The password of the server group role. + Password *string `json:"password,omitempty"` +} + +// RolesBeginCreateOptions contains the optional parameters for the Roles.BeginCreate method. +type RolesBeginCreateOptions struct { + // placeholder for future optional parameters +} + +// RolesBeginDeleteOptions contains the optional parameters for the Roles.BeginDelete method. +type RolesBeginDeleteOptions struct { + // placeholder for future optional parameters +} + +// RolesListByServerGroupOptions contains the optional parameters for the Roles.ListByServerGroup method. +type RolesListByServerGroupOptions struct { + // placeholder for future optional parameters +} + +// ServerConfiguration - Represents a configuration. +type ServerConfiguration struct { + ProxyResource + // The properties of a configuration. + Properties *ServerConfigurationProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerConfiguration. +func (s ServerConfiguration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.ProxyResource.marshalInternal(objectMap) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + return json.Marshal(objectMap) +} + +// ServerConfigurationListResult - A list of server configurations. +type ServerConfigurationListResult struct { + // The list of server configurations. + Value []*ServerConfiguration `json:"value,omitempty"` + + // READ-ONLY; Link to retrieve next page of results. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerConfigurationListResult. +func (s ServerConfigurationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// ServerConfigurationProperties - The properties of a configuration. +type ServerConfigurationProperties struct { + // REQUIRED; Value of the configuration. + Value *string `json:"value,omitempty"` + + // READ-ONLY; Allowed values of the configuration. + AllowedValues *string `json:"allowedValues,omitempty" azure:"ro"` + + // READ-ONLY; Data type of the configuration. + DataType *ConfigurationDataType `json:"dataType,omitempty" azure:"ro"` + + // READ-ONLY; Default value of the configuration. + DefaultValue *string `json:"defaultValue,omitempty" azure:"ro"` + + // READ-ONLY; Description of the configuration. + Description *string `json:"description,omitempty" azure:"ro"` + + // READ-ONLY; Source of the configuration. + Source *string `json:"source,omitempty" azure:"ro"` +} + +// ServerGroup - Represents a server group for create. +type ServerGroup struct { + TrackedResource + // Properties of the server group create. + Properties *ServerGroupProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroup. +func (s ServerGroup) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.TrackedResource.marshalInternal(objectMap) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + return json.Marshal(objectMap) +} + +// ServerGroupConfiguration - Represents the configuration list of server role groups in a server group. +type ServerGroupConfiguration struct { + ProxyResource + // The properties of server group configuration. + Properties *ServerGroupConfigurationProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupConfiguration. +func (s ServerGroupConfiguration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.ProxyResource.marshalInternal(objectMap) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + return json.Marshal(objectMap) +} + +// ServerGroupConfigurationListResult - A list of server group configurations. +type ServerGroupConfigurationListResult struct { + // The list of server group configurations. + Value []*ServerGroupConfiguration `json:"value,omitempty"` + + // READ-ONLY; Link to retrieve next page of results. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupConfigurationListResult. +func (s ServerGroupConfigurationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// ServerGroupConfigurationProperties - The properties of server group configuration. +type ServerGroupConfigurationProperties struct { + // REQUIRED; The list of server role group configuration values. + ServerRoleGroupConfigurations []*ServerRoleGroupConfiguration `json:"serverRoleGroupConfigurations,omitempty"` + + // READ-ONLY; Allowed values of the configuration. + AllowedValues *string `json:"allowedValues,omitempty" azure:"ro"` + + // READ-ONLY; Data type of the configuration. + DataType *ConfigurationDataType `json:"dataType,omitempty" azure:"ro"` + + // READ-ONLY; Description of the configuration. + Description *string `json:"description,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupConfigurationProperties. +func (s ServerGroupConfigurationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "allowedValues", s.AllowedValues) + populate(objectMap, "dataType", s.DataType) + populate(objectMap, "description", s.Description) + populate(objectMap, "serverRoleGroupConfigurations", s.ServerRoleGroupConfigurations) + return json.Marshal(objectMap) +} + +// ServerGroupForUpdate - Represents a server group for update. +type ServerGroupForUpdate struct { + // The location the resource resides in. + Location *string `json:"location,omitempty"` + + // Properties of the server group. + Properties *ServerGroupPropertiesForUpdate `json:"properties,omitempty"` + + // Application-specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupForUpdate. +func (s ServerGroupForUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "location", s.Location) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "tags", s.Tags) + return json.Marshal(objectMap) +} + +// ServerGroupListResult - A list of server groups. +type ServerGroupListResult struct { + // The list of server groups + Value []*ServerGroup `json:"value,omitempty"` + + // READ-ONLY; The link used to get the next page of operations. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupListResult. +func (s ServerGroupListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// ServerGroupProperties - The properties used to create a new server group. +type ServerGroupProperties struct { + // The administrator's login name of servers in server group. Can only be specified when the server is being created (and is required for creation). + AdministratorLogin *string `json:"administratorLogin,omitempty"` + + // The password of the administrator login. + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + + // Availability Zone information of the server group. + AvailabilityZone *string `json:"availabilityZone,omitempty"` + + // The backup retention days for server group. + BackupRetentionDays *int32 `json:"backupRetentionDays,omitempty"` + + // The Citus version of server group. + CitusVersion *CitusVersion `json:"citusVersion,omitempty"` + + // The mode to create a new server group. + CreateMode *CreateMode `json:"createMode,omitempty"` + + // The delegated subnet arguments for a server group. + DelegatedSubnetArguments *ServerGroupPropertiesDelegatedSubnetArguments `json:"delegatedSubnetArguments,omitempty"` + + // If Citus MX is enabled or not for the server group. + EnableMx *bool `json:"enableMx,omitempty"` + + // If shards on coordinator is enabled or not for the server group. + EnableShardsOnCoordinator *bool `json:"enableShardsOnCoordinator,omitempty"` + + // If ZFS compression is enabled or not for the server group. + EnableZfs *bool `json:"enableZfs,omitempty"` + + // Maintenance window of a server group. + MaintenanceWindow *MaintenanceWindow `json:"maintenanceWindow,omitempty"` + + // Restore point creation time (ISO8601 format), specifying the time to restore from. It's required when 'createMode' is 'PointInTimeRestore' + PointInTimeUTC *time.Time `json:"pointInTimeUTC,omitempty"` + + // The PostgreSQL version of server group. + PostgresqlVersion *PostgreSQLVersion `json:"postgresqlVersion,omitempty"` + + // The private dns zone arguments for a server group. + PrivateDNSZoneArguments *ServerGroupPropertiesPrivateDNSZoneArguments `json:"privateDnsZoneArguments,omitempty"` + + // The list of server role groups. + ServerRoleGroups []*ServerRoleGroup `json:"serverRoleGroups,omitempty"` + + // The source server group location to restore from. It's required when 'createMode' is 'PointInTimeRestore' or 'ReadReplica' + SourceLocation *string `json:"sourceLocation,omitempty"` + + // The source resource group name to restore from. It's required when 'createMode' is 'PointInTimeRestore' or 'ReadReplica' + SourceResourceGroupName *string `json:"sourceResourceGroupName,omitempty"` + + // The source server group name to restore from. It's required when 'createMode' is 'PointInTimeRestore' or 'ReadReplica' + SourceServerGroupName *string `json:"sourceServerGroupName,omitempty"` + + // The source subscription id to restore from. It's required when 'createMode' is 'PointInTimeRestore' or 'ReadReplica' + SourceSubscriptionID *string `json:"sourceSubscriptionId,omitempty"` + + // Standby Availability Zone information of the server group. + StandbyAvailabilityZone *string `json:"standbyAvailabilityZone,omitempty"` + + // READ-ONLY; The earliest restore point time (ISO8601 format) for server group. + EarliestRestoreTime *time.Time `json:"earliestRestoreTime,omitempty" azure:"ro"` + + // READ-ONLY; The array of read replica server groups. + ReadReplicas []*string `json:"readReplicas,omitempty" azure:"ro"` + + // READ-ONLY; The resource provider type of server group. + ResourceProviderType *ResourceProviderType `json:"resourceProviderType,omitempty" azure:"ro"` + + // READ-ONLY; The source server group id for read replica server groups. + SourceServerGroup *string `json:"sourceServerGroup,omitempty" azure:"ro"` + + // READ-ONLY; A state of a server group that is visible to user. + State *ServerState `json:"state,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupProperties. +func (s ServerGroupProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "administratorLogin", s.AdministratorLogin) + populate(objectMap, "administratorLoginPassword", s.AdministratorLoginPassword) + populate(objectMap, "availabilityZone", s.AvailabilityZone) + populate(objectMap, "backupRetentionDays", s.BackupRetentionDays) + populate(objectMap, "citusVersion", s.CitusVersion) + populate(objectMap, "createMode", s.CreateMode) + populate(objectMap, "delegatedSubnetArguments", s.DelegatedSubnetArguments) + populateTimeRFC3339(objectMap, "earliestRestoreTime", s.EarliestRestoreTime) + populate(objectMap, "enableMx", s.EnableMx) + populate(objectMap, "enableShardsOnCoordinator", s.EnableShardsOnCoordinator) + populate(objectMap, "enableZfs", s.EnableZfs) + populate(objectMap, "maintenanceWindow", s.MaintenanceWindow) + populateTimeRFC3339(objectMap, "pointInTimeUTC", s.PointInTimeUTC) + populate(objectMap, "postgresqlVersion", s.PostgresqlVersion) + populate(objectMap, "privateDnsZoneArguments", s.PrivateDNSZoneArguments) + populate(objectMap, "readReplicas", s.ReadReplicas) + populate(objectMap, "resourceProviderType", s.ResourceProviderType) + populate(objectMap, "serverRoleGroups", s.ServerRoleGroups) + populate(objectMap, "sourceLocation", s.SourceLocation) + populate(objectMap, "sourceResourceGroupName", s.SourceResourceGroupName) + populate(objectMap, "sourceServerGroup", s.SourceServerGroup) + populate(objectMap, "sourceServerGroupName", s.SourceServerGroupName) + populate(objectMap, "sourceSubscriptionId", s.SourceSubscriptionID) + populate(objectMap, "standbyAvailabilityZone", s.StandbyAvailabilityZone) + populate(objectMap, "state", s.State) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ServerGroupProperties. +func (s *ServerGroupProperties) 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 "administratorLogin": + err = unpopulate(val, &s.AdministratorLogin) + delete(rawMsg, key) + case "administratorLoginPassword": + err = unpopulate(val, &s.AdministratorLoginPassword) + delete(rawMsg, key) + case "availabilityZone": + err = unpopulate(val, &s.AvailabilityZone) + delete(rawMsg, key) + case "backupRetentionDays": + err = unpopulate(val, &s.BackupRetentionDays) + delete(rawMsg, key) + case "citusVersion": + err = unpopulate(val, &s.CitusVersion) + delete(rawMsg, key) + case "createMode": + err = unpopulate(val, &s.CreateMode) + delete(rawMsg, key) + case "delegatedSubnetArguments": + err = unpopulate(val, &s.DelegatedSubnetArguments) + delete(rawMsg, key) + case "earliestRestoreTime": + err = unpopulateTimeRFC3339(val, &s.EarliestRestoreTime) + delete(rawMsg, key) + case "enableMx": + err = unpopulate(val, &s.EnableMx) + delete(rawMsg, key) + case "enableShardsOnCoordinator": + err = unpopulate(val, &s.EnableShardsOnCoordinator) + delete(rawMsg, key) + case "enableZfs": + err = unpopulate(val, &s.EnableZfs) + delete(rawMsg, key) + case "maintenanceWindow": + err = unpopulate(val, &s.MaintenanceWindow) + delete(rawMsg, key) + case "pointInTimeUTC": + err = unpopulateTimeRFC3339(val, &s.PointInTimeUTC) + delete(rawMsg, key) + case "postgresqlVersion": + err = unpopulate(val, &s.PostgresqlVersion) + delete(rawMsg, key) + case "privateDnsZoneArguments": + err = unpopulate(val, &s.PrivateDNSZoneArguments) + delete(rawMsg, key) + case "readReplicas": + err = unpopulate(val, &s.ReadReplicas) + delete(rawMsg, key) + case "resourceProviderType": + err = unpopulate(val, &s.ResourceProviderType) + delete(rawMsg, key) + case "serverRoleGroups": + err = unpopulate(val, &s.ServerRoleGroups) + delete(rawMsg, key) + case "sourceLocation": + err = unpopulate(val, &s.SourceLocation) + delete(rawMsg, key) + case "sourceResourceGroupName": + err = unpopulate(val, &s.SourceResourceGroupName) + delete(rawMsg, key) + case "sourceServerGroup": + err = unpopulate(val, &s.SourceServerGroup) + delete(rawMsg, key) + case "sourceServerGroupName": + err = unpopulate(val, &s.SourceServerGroupName) + delete(rawMsg, key) + case "sourceSubscriptionId": + err = unpopulate(val, &s.SourceSubscriptionID) + delete(rawMsg, key) + case "standbyAvailabilityZone": + err = unpopulate(val, &s.StandbyAvailabilityZone) + delete(rawMsg, key) + case "state": + err = unpopulate(val, &s.State) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ServerGroupPropertiesDelegatedSubnetArguments - The delegated subnet arguments for a server group. +type ServerGroupPropertiesDelegatedSubnetArguments struct { + // delegated subnet arm resource id. + SubnetArmResourceID *string `json:"subnetArmResourceId,omitempty"` +} + +// ServerGroupPropertiesForUpdate - The properties used to update a server group. +type ServerGroupPropertiesForUpdate struct { + // The password of the administrator login. + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + + // Availability Zone information of the server group. + AvailabilityZone *string `json:"availabilityZone,omitempty"` + + // The backup retention days for server group. + BackupRetentionDays *int32 `json:"backupRetentionDays,omitempty"` + + // The Citus version of server group. + CitusVersion *CitusVersion `json:"citusVersion,omitempty"` + + // If shards on coordinator is enabled or not for the server group. + EnableShardsOnCoordinator *bool `json:"enableShardsOnCoordinator,omitempty"` + + // Maintenance window of a server group. + MaintenanceWindow *MaintenanceWindow `json:"maintenanceWindow,omitempty"` + + // The PostgreSQL version of server group. + PostgresqlVersion *PostgreSQLVersion `json:"postgresqlVersion,omitempty"` + + // The list of server role groups. + ServerRoleGroups []*ServerRoleGroup `json:"serverRoleGroups,omitempty"` + + // Standby Availability Zone information of the server group. + StandbyAvailabilityZone *string `json:"standbyAvailabilityZone,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupPropertiesForUpdate. +func (s ServerGroupPropertiesForUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "administratorLoginPassword", s.AdministratorLoginPassword) + populate(objectMap, "availabilityZone", s.AvailabilityZone) + populate(objectMap, "backupRetentionDays", s.BackupRetentionDays) + populate(objectMap, "citusVersion", s.CitusVersion) + populate(objectMap, "enableShardsOnCoordinator", s.EnableShardsOnCoordinator) + populate(objectMap, "maintenanceWindow", s.MaintenanceWindow) + populate(objectMap, "postgresqlVersion", s.PostgresqlVersion) + populate(objectMap, "serverRoleGroups", s.ServerRoleGroups) + populate(objectMap, "standbyAvailabilityZone", s.StandbyAvailabilityZone) + return json.Marshal(objectMap) +} + +// ServerGroupPropertiesPrivateDNSZoneArguments - The private dns zone arguments for a server group. +type ServerGroupPropertiesPrivateDNSZoneArguments struct { + // private dns zone arm resource id. + PrivateDNSZoneArmResourceID *string `json:"privateDnsZoneArmResourceId,omitempty"` +} + +// ServerGroupServer - Represents a server in a server group. +type ServerGroupServer struct { + ProxyResource + // The properties of a server in a server group. + Properties *ServerGroupServerProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupServer. +func (s ServerGroupServer) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.ProxyResource.marshalInternal(objectMap) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + return json.Marshal(objectMap) +} + +// ServerGroupServerListResult - A list of servers in a server group. +type ServerGroupServerListResult struct { + // The list of servers in a server group. + Value []*ServerGroupServer `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupServerListResult. +func (s ServerGroupServerListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// ServerGroupServerProperties - The properties of a server in server group. +type ServerGroupServerProperties struct { + ServerProperties + // The administrator's login name of a servers in server group. + AdministratorLogin *string `json:"administratorLogin,omitempty"` + + // Availability Zone information of the server group. + AvailabilityZone *string `json:"availabilityZone,omitempty"` + + // The Citus version of server. + CitusVersion *CitusVersion `json:"citusVersion,omitempty"` + + // The PostgreSQL version of server. + PostgresqlVersion *PostgreSQLVersion `json:"postgresqlVersion,omitempty"` + + // The role of server in the server group. + Role *ServerRole `json:"role,omitempty"` + + // Standby Availability Zone information of the server group. + StandbyAvailabilityZone *string `json:"standbyAvailabilityZone,omitempty"` + + // READ-ONLY; The fully qualified domain name of a server. + FullyQualifiedDomainName *string `json:"fullyQualifiedDomainName,omitempty" azure:"ro"` + + // READ-ONLY; A state of a server group that is visible to user for HA feature. + HaState *ServerHaState `json:"haState,omitempty" azure:"ro"` + + // READ-ONLY; A state of a server that is visible to user. + State *ServerState `json:"state,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerGroupServerProperties. +func (s ServerGroupServerProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.ServerProperties.marshalInternal(objectMap) + populate(objectMap, "administratorLogin", s.AdministratorLogin) + populate(objectMap, "availabilityZone", s.AvailabilityZone) + populate(objectMap, "citusVersion", s.CitusVersion) + populate(objectMap, "fullyQualifiedDomainName", s.FullyQualifiedDomainName) + populate(objectMap, "haState", s.HaState) + populate(objectMap, "postgresqlVersion", s.PostgresqlVersion) + populate(objectMap, "role", s.Role) + populate(objectMap, "standbyAvailabilityZone", s.StandbyAvailabilityZone) + populate(objectMap, "state", s.State) + return json.Marshal(objectMap) +} + +// ServerGroupsBeginCreateOrUpdateOptions contains the optional parameters for the ServerGroups.BeginCreateOrUpdate method. +type ServerGroupsBeginCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsBeginDeleteOptions contains the optional parameters for the ServerGroups.BeginDelete method. +type ServerGroupsBeginDeleteOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsBeginRestartOptions contains the optional parameters for the ServerGroups.BeginRestart method. +type ServerGroupsBeginRestartOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsBeginStartOptions contains the optional parameters for the ServerGroups.BeginStart method. +type ServerGroupsBeginStartOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsBeginStopOptions contains the optional parameters for the ServerGroups.BeginStop method. +type ServerGroupsBeginStopOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsBeginUpdateOptions contains the optional parameters for the ServerGroups.BeginUpdate method. +type ServerGroupsBeginUpdateOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsCheckNameAvailabilityOptions contains the optional parameters for the ServerGroups.CheckNameAvailability method. +type ServerGroupsCheckNameAvailabilityOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsGetOptions contains the optional parameters for the ServerGroups.Get method. +type ServerGroupsGetOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsListByResourceGroupOptions contains the optional parameters for the ServerGroups.ListByResourceGroup method. +type ServerGroupsListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// ServerGroupsListOptions contains the optional parameters for the ServerGroups.List method. +type ServerGroupsListOptions struct { + // placeholder for future optional parameters +} + +// ServerNameItem - The name object for a server. +type ServerNameItem struct { + // The name of a server. + Name *string `json:"name,omitempty"` + + // READ-ONLY; The fully qualified domain name of a server. + FullyQualifiedDomainName *string `json:"fullyQualifiedDomainName,omitempty" azure:"ro"` +} + +// ServerProperties - The properties of a server. +type ServerProperties struct { + // If high availability is enabled or not for the server. + EnableHa *bool `json:"enableHa,omitempty"` + + // The edition of a server (default: GeneralPurpose). + ServerEdition *ServerEdition `json:"serverEdition,omitempty"` + + // The storage of a server in MB (max: 2097152 = 2TiB). + StorageQuotaInMb *int64 `json:"storageQuotaInMb,omitempty"` + + // The vCores count of a server (max: 64). + VCores *int64 `json:"vCores,omitempty"` + + // READ-ONLY; If public IP is requested or not for a server. + EnablePublicIP *bool `json:"enablePublicIp,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerProperties. +func (s ServerProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.marshalInternal(objectMap) + return json.Marshal(objectMap) +} + +func (s ServerProperties) marshalInternal(objectMap map[string]interface{}) { + populate(objectMap, "enableHa", s.EnableHa) + populate(objectMap, "enablePublicIp", s.EnablePublicIP) + populate(objectMap, "serverEdition", s.ServerEdition) + populate(objectMap, "storageQuotaInMb", s.StorageQuotaInMb) + populate(objectMap, "vCores", s.VCores) +} + +// ServerRoleGroup - Represents a server role group. +type ServerRoleGroup struct { + ServerProperties + // The name of the server role group. + Name *string `json:"name,omitempty"` + + // The role of servers in the server role group. + Role *ServerRole `json:"role,omitempty"` + + // The number of servers in the server role group. + ServerCount *int32 `json:"serverCount,omitempty"` + + // READ-ONLY; The list of server names in the server role group. + ServerNames []*ServerNameItem `json:"serverNames,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerRoleGroup. +func (s ServerRoleGroup) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + s.ServerProperties.marshalInternal(objectMap) + populate(objectMap, "name", s.Name) + populate(objectMap, "role", s.Role) + populate(objectMap, "serverCount", s.ServerCount) + populate(objectMap, "serverNames", s.ServerNames) + return json.Marshal(objectMap) +} + +// ServerRoleGroupConfiguration - Represents server role group configuration value. +type ServerRoleGroupConfiguration struct { + // REQUIRED; The role of servers in the server role group. + Role *ServerRole `json:"role,omitempty"` + + // REQUIRED; Value of the configuration. + Value *string `json:"value,omitempty"` + + // READ-ONLY; Default value of the configuration. + DefaultValue *string `json:"defaultValue,omitempty" azure:"ro"` + + // READ-ONLY; Source of the configuration. + Source *string `json:"source,omitempty" azure:"ro"` +} + +// ServersGetOptions contains the optional parameters for the Servers.Get method. +type ServersGetOptions struct { + // placeholder for future optional parameters +} + +// ServersListByServerGroupOptions contains the optional parameters for the Servers.ListByServerGroup method. +type ServersListByServerGroupOptions 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 +} + +// TrackedResource - The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location' +type TrackedResource struct { + Resource + // REQUIRED; The geo-location where the resource lives + Location *string `json:"location,omitempty"` + + // Resource tags. + Tags map[string]*string `json:"tags,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type TrackedResource. +func (t TrackedResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + t.marshalInternal(objectMap) + return json.Marshal(objectMap) +} + +func (t TrackedResource) marshalInternal(objectMap map[string]interface{}) { + t.Resource.marshalInternal(objectMap) + populate(objectMap, "location", t.Location) + populate(objectMap, "tags", t.Tags) +} + +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/postgresqlhsc/armpostgresqlhsc/zz_generated_operations_client.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_operations_client.go new file mode 100644 index 000000000000..4648ecfc6324 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_operations_client.go @@ -0,0 +1,92 @@ +//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 armpostgresqlhsc + +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 REST API operations. +// If the operation fails it returns the *CloudError error type. +func (client *OperationsClient) List(ctx context.Context, options *OperationsListOptions) (OperationsListResponse, error) { + req, err := client.listCreateRequest(ctx, options) + if err != nil { + return OperationsListResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return OperationsListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return OperationsListResponse{}, client.listHandleError(resp) + } + return client.listHandleResponse(resp) +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.DBForPostgreSql/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", "2020-10-05-privatepreview") + 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 := CloudError{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/postgresqlhsc/armpostgresqlhsc/zz_generated_pagers.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_pagers.go new file mode 100644 index 000000000000..13edb844f093 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_pagers.go @@ -0,0 +1,233 @@ +//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 armpostgresqlhsc + +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" +) + +// ConfigurationsListByServerGroupPager provides operations for iterating over paged responses. +type ConfigurationsListByServerGroupPager struct { + client *ConfigurationsClient + current ConfigurationsListByServerGroupResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ConfigurationsListByServerGroupResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ConfigurationsListByServerGroupPager) 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 *ConfigurationsListByServerGroupPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ServerGroupConfigurationListResult.NextLink == nil || len(*p.current.ServerGroupConfigurationListResult.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.listByServerGroupHandleError(resp) + return false + } + result, err := p.client.listByServerGroupHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ConfigurationsListByServerGroupResponse page. +func (p *ConfigurationsListByServerGroupPager) PageResponse() ConfigurationsListByServerGroupResponse { + return p.current +} + +// ConfigurationsListByServerPager provides operations for iterating over paged responses. +type ConfigurationsListByServerPager struct { + client *ConfigurationsClient + current ConfigurationsListByServerResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ConfigurationsListByServerResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ConfigurationsListByServerPager) 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 *ConfigurationsListByServerPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ServerConfigurationListResult.NextLink == nil || len(*p.current.ServerConfigurationListResult.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.listByServerHandleError(resp) + return false + } + result, err := p.client.listByServerHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ConfigurationsListByServerResponse page. +func (p *ConfigurationsListByServerPager) PageResponse() ConfigurationsListByServerResponse { + return p.current +} + +// ServerGroupsListByResourceGroupPager provides operations for iterating over paged responses. +type ServerGroupsListByResourceGroupPager struct { + client *ServerGroupsClient + current ServerGroupsListByResourceGroupResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ServerGroupsListByResourceGroupResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ServerGroupsListByResourceGroupPager) 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 *ServerGroupsListByResourceGroupPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ServerGroupListResult.NextLink == nil || len(*p.current.ServerGroupListResult.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.listByResourceGroupHandleError(resp) + return false + } + result, err := p.client.listByResourceGroupHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ServerGroupsListByResourceGroupResponse page. +func (p *ServerGroupsListByResourceGroupPager) PageResponse() ServerGroupsListByResourceGroupResponse { + return p.current +} + +// ServerGroupsListPager provides operations for iterating over paged responses. +type ServerGroupsListPager struct { + client *ServerGroupsClient + current ServerGroupsListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ServerGroupsListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ServerGroupsListPager) 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 *ServerGroupsListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ServerGroupListResult.NextLink == nil || len(*p.current.ServerGroupListResult.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 ServerGroupsListResponse page. +func (p *ServerGroupsListPager) PageResponse() ServerGroupsListResponse { + return p.current +} diff --git a/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_pollers.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_pollers.go new file mode 100644 index 000000000000..8bd1c97ccde0 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_pollers.go @@ -0,0 +1,488 @@ +//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 armpostgresqlhsc + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "net/http" +) + +// ConfigurationsUpdatePoller provides polling facilities until the operation reaches a terminal state. +type ConfigurationsUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ConfigurationsUpdatePoller) 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 *ConfigurationsUpdatePoller) 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 ConfigurationsUpdateResponse will be returned. +func (p *ConfigurationsUpdatePoller) FinalResponse(ctx context.Context) (ConfigurationsUpdateResponse, error) { + respType := ConfigurationsUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.ServerGroupConfiguration) + if err != nil { + return ConfigurationsUpdateResponse{}, 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 *ConfigurationsUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// FirewallRulesCreateOrUpdatePoller provides polling facilities until the operation reaches a terminal state. +type FirewallRulesCreateOrUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *FirewallRulesCreateOrUpdatePoller) 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 *FirewallRulesCreateOrUpdatePoller) 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 FirewallRulesCreateOrUpdateResponse will be returned. +func (p *FirewallRulesCreateOrUpdatePoller) FinalResponse(ctx context.Context) (FirewallRulesCreateOrUpdateResponse, error) { + respType := FirewallRulesCreateOrUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.FirewallRule) + if err != nil { + return FirewallRulesCreateOrUpdateResponse{}, 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 *FirewallRulesCreateOrUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// FirewallRulesDeletePoller provides polling facilities until the operation reaches a terminal state. +type FirewallRulesDeletePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *FirewallRulesDeletePoller) 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 *FirewallRulesDeletePoller) 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 FirewallRulesDeleteResponse will be returned. +func (p *FirewallRulesDeletePoller) FinalResponse(ctx context.Context) (FirewallRulesDeleteResponse, error) { + respType := FirewallRulesDeleteResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return FirewallRulesDeleteResponse{}, 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 *FirewallRulesDeletePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// RolesCreatePoller provides polling facilities until the operation reaches a terminal state. +type RolesCreatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *RolesCreatePoller) 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 *RolesCreatePoller) 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 RolesCreateResponse will be returned. +func (p *RolesCreatePoller) FinalResponse(ctx context.Context) (RolesCreateResponse, error) { + respType := RolesCreateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.Role) + if err != nil { + return RolesCreateResponse{}, 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 *RolesCreatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// RolesDeletePoller provides polling facilities until the operation reaches a terminal state. +type RolesDeletePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *RolesDeletePoller) 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 *RolesDeletePoller) 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 RolesDeleteResponse will be returned. +func (p *RolesDeletePoller) FinalResponse(ctx context.Context) (RolesDeleteResponse, error) { + respType := RolesDeleteResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return RolesDeleteResponse{}, 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 *RolesDeletePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServerGroupsCreateOrUpdatePoller provides polling facilities until the operation reaches a terminal state. +type ServerGroupsCreateOrUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServerGroupsCreateOrUpdatePoller) 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 *ServerGroupsCreateOrUpdatePoller) 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 ServerGroupsCreateOrUpdateResponse will be returned. +func (p *ServerGroupsCreateOrUpdatePoller) FinalResponse(ctx context.Context) (ServerGroupsCreateOrUpdateResponse, error) { + respType := ServerGroupsCreateOrUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.ServerGroup) + if err != nil { + return ServerGroupsCreateOrUpdateResponse{}, 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 *ServerGroupsCreateOrUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServerGroupsDeletePoller provides polling facilities until the operation reaches a terminal state. +type ServerGroupsDeletePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServerGroupsDeletePoller) 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 *ServerGroupsDeletePoller) 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 ServerGroupsDeleteResponse will be returned. +func (p *ServerGroupsDeletePoller) FinalResponse(ctx context.Context) (ServerGroupsDeleteResponse, error) { + respType := ServerGroupsDeleteResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServerGroupsDeleteResponse{}, 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 *ServerGroupsDeletePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServerGroupsRestartPoller provides polling facilities until the operation reaches a terminal state. +type ServerGroupsRestartPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServerGroupsRestartPoller) 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 *ServerGroupsRestartPoller) 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 ServerGroupsRestartResponse will be returned. +func (p *ServerGroupsRestartPoller) FinalResponse(ctx context.Context) (ServerGroupsRestartResponse, error) { + respType := ServerGroupsRestartResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServerGroupsRestartResponse{}, 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 *ServerGroupsRestartPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServerGroupsStartPoller provides polling facilities until the operation reaches a terminal state. +type ServerGroupsStartPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServerGroupsStartPoller) 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 *ServerGroupsStartPoller) 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 ServerGroupsStartResponse will be returned. +func (p *ServerGroupsStartPoller) FinalResponse(ctx context.Context) (ServerGroupsStartResponse, error) { + respType := ServerGroupsStartResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServerGroupsStartResponse{}, 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 *ServerGroupsStartPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServerGroupsStopPoller provides polling facilities until the operation reaches a terminal state. +type ServerGroupsStopPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServerGroupsStopPoller) 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 *ServerGroupsStopPoller) 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 ServerGroupsStopResponse will be returned. +func (p *ServerGroupsStopPoller) FinalResponse(ctx context.Context) (ServerGroupsStopResponse, error) { + respType := ServerGroupsStopResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServerGroupsStopResponse{}, 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 *ServerGroupsStopPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServerGroupsUpdatePoller provides polling facilities until the operation reaches a terminal state. +type ServerGroupsUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServerGroupsUpdatePoller) 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 *ServerGroupsUpdatePoller) 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 ServerGroupsUpdateResponse will be returned. +func (p *ServerGroupsUpdatePoller) FinalResponse(ctx context.Context) (ServerGroupsUpdateResponse, error) { + respType := ServerGroupsUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.ServerGroup) + if err != nil { + return ServerGroupsUpdateResponse{}, 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 *ServerGroupsUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} diff --git a/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_response_types.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_response_types.go new file mode 100644 index 000000000000..824e5742de33 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_response_types.go @@ -0,0 +1,708 @@ +//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 armpostgresqlhsc + +import ( + "context" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "net/http" + "time" +) + +// ConfigurationsGetResponse contains the response from method Configurations.Get. +type ConfigurationsGetResponse struct { + ConfigurationsGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ConfigurationsGetResult contains the result from method Configurations.Get. +type ConfigurationsGetResult struct { + ServerGroupConfiguration +} + +// ConfigurationsListByServerGroupResponse contains the response from method Configurations.ListByServerGroup. +type ConfigurationsListByServerGroupResponse struct { + ConfigurationsListByServerGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ConfigurationsListByServerGroupResult contains the result from method Configurations.ListByServerGroup. +type ConfigurationsListByServerGroupResult struct { + ServerGroupConfigurationListResult +} + +// ConfigurationsListByServerResponse contains the response from method Configurations.ListByServer. +type ConfigurationsListByServerResponse struct { + ConfigurationsListByServerResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ConfigurationsListByServerResult contains the result from method Configurations.ListByServer. +type ConfigurationsListByServerResult struct { + ServerConfigurationListResult +} + +// ConfigurationsUpdatePollerResponse contains the response from method Configurations.Update. +type ConfigurationsUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *ConfigurationsUpdatePoller + + // 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 ConfigurationsUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ConfigurationsUpdateResponse, error) { + respType := ConfigurationsUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.ServerGroupConfiguration) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ConfigurationsUpdatePollerResponse from the provided client and resume token. +func (l *ConfigurationsUpdatePollerResponse) Resume(ctx context.Context, client *ConfigurationsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ConfigurationsClient.Update", token, client.pl, client.updateHandleError) + if err != nil { + return err + } + poller := &ConfigurationsUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ConfigurationsUpdateResponse contains the response from method Configurations.Update. +type ConfigurationsUpdateResponse struct { + ConfigurationsUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ConfigurationsUpdateResult contains the result from method Configurations.Update. +type ConfigurationsUpdateResult struct { + ServerGroupConfiguration +} + +// FirewallRulesCreateOrUpdatePollerResponse contains the response from method FirewallRules.CreateOrUpdate. +type FirewallRulesCreateOrUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *FirewallRulesCreateOrUpdatePoller + + // 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 FirewallRulesCreateOrUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (FirewallRulesCreateOrUpdateResponse, error) { + respType := FirewallRulesCreateOrUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.FirewallRule) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a FirewallRulesCreateOrUpdatePollerResponse from the provided client and resume token. +func (l *FirewallRulesCreateOrUpdatePollerResponse) Resume(ctx context.Context, client *FirewallRulesClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("FirewallRulesClient.CreateOrUpdate", token, client.pl, client.createOrUpdateHandleError) + if err != nil { + return err + } + poller := &FirewallRulesCreateOrUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// FirewallRulesCreateOrUpdateResponse contains the response from method FirewallRules.CreateOrUpdate. +type FirewallRulesCreateOrUpdateResponse struct { + FirewallRulesCreateOrUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// FirewallRulesCreateOrUpdateResult contains the result from method FirewallRules.CreateOrUpdate. +type FirewallRulesCreateOrUpdateResult struct { + FirewallRule +} + +// FirewallRulesDeletePollerResponse contains the response from method FirewallRules.Delete. +type FirewallRulesDeletePollerResponse struct { + // Poller contains an initialized poller. + Poller *FirewallRulesDeletePoller + + // 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 FirewallRulesDeletePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (FirewallRulesDeleteResponse, error) { + respType := FirewallRulesDeleteResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a FirewallRulesDeletePollerResponse from the provided client and resume token. +func (l *FirewallRulesDeletePollerResponse) Resume(ctx context.Context, client *FirewallRulesClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("FirewallRulesClient.Delete", token, client.pl, client.deleteHandleError) + if err != nil { + return err + } + poller := &FirewallRulesDeletePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// FirewallRulesDeleteResponse contains the response from method FirewallRules.Delete. +type FirewallRulesDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// FirewallRulesGetResponse contains the response from method FirewallRules.Get. +type FirewallRulesGetResponse struct { + FirewallRulesGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// FirewallRulesGetResult contains the result from method FirewallRules.Get. +type FirewallRulesGetResult struct { + FirewallRule +} + +// FirewallRulesListByServerGroupResponse contains the response from method FirewallRules.ListByServerGroup. +type FirewallRulesListByServerGroupResponse struct { + FirewallRulesListByServerGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// FirewallRulesListByServerGroupResult contains the result from method FirewallRules.ListByServerGroup. +type FirewallRulesListByServerGroupResult struct { + FirewallRuleListResult +} + +// 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 +} + +// RolesCreatePollerResponse contains the response from method Roles.Create. +type RolesCreatePollerResponse struct { + // Poller contains an initialized poller. + Poller *RolesCreatePoller + + // 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 RolesCreatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (RolesCreateResponse, error) { + respType := RolesCreateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.Role) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a RolesCreatePollerResponse from the provided client and resume token. +func (l *RolesCreatePollerResponse) Resume(ctx context.Context, client *RolesClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("RolesClient.Create", token, client.pl, client.createHandleError) + if err != nil { + return err + } + poller := &RolesCreatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// RolesCreateResponse contains the response from method Roles.Create. +type RolesCreateResponse struct { + RolesCreateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// RolesCreateResult contains the result from method Roles.Create. +type RolesCreateResult struct { + Role +} + +// RolesDeletePollerResponse contains the response from method Roles.Delete. +type RolesDeletePollerResponse struct { + // Poller contains an initialized poller. + Poller *RolesDeletePoller + + // 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 RolesDeletePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (RolesDeleteResponse, error) { + respType := RolesDeleteResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a RolesDeletePollerResponse from the provided client and resume token. +func (l *RolesDeletePollerResponse) Resume(ctx context.Context, client *RolesClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("RolesClient.Delete", token, client.pl, client.deleteHandleError) + if err != nil { + return err + } + poller := &RolesDeletePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// RolesDeleteResponse contains the response from method Roles.Delete. +type RolesDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// RolesListByServerGroupResponse contains the response from method Roles.ListByServerGroup. +type RolesListByServerGroupResponse struct { + RolesListByServerGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// RolesListByServerGroupResult contains the result from method Roles.ListByServerGroup. +type RolesListByServerGroupResult struct { + RoleListResult +} + +// ServerGroupsCheckNameAvailabilityResponse contains the response from method ServerGroups.CheckNameAvailability. +type ServerGroupsCheckNameAvailabilityResponse struct { + ServerGroupsCheckNameAvailabilityResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsCheckNameAvailabilityResult contains the result from method ServerGroups.CheckNameAvailability. +type ServerGroupsCheckNameAvailabilityResult struct { + NameAvailability +} + +// ServerGroupsCreateOrUpdatePollerResponse contains the response from method ServerGroups.CreateOrUpdate. +type ServerGroupsCreateOrUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *ServerGroupsCreateOrUpdatePoller + + // 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 ServerGroupsCreateOrUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServerGroupsCreateOrUpdateResponse, error) { + respType := ServerGroupsCreateOrUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.ServerGroup) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServerGroupsCreateOrUpdatePollerResponse from the provided client and resume token. +func (l *ServerGroupsCreateOrUpdatePollerResponse) Resume(ctx context.Context, client *ServerGroupsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServerGroupsClient.CreateOrUpdate", token, client.pl, client.createOrUpdateHandleError) + if err != nil { + return err + } + poller := &ServerGroupsCreateOrUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServerGroupsCreateOrUpdateResponse contains the response from method ServerGroups.CreateOrUpdate. +type ServerGroupsCreateOrUpdateResponse struct { + ServerGroupsCreateOrUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsCreateOrUpdateResult contains the result from method ServerGroups.CreateOrUpdate. +type ServerGroupsCreateOrUpdateResult struct { + ServerGroup +} + +// ServerGroupsDeletePollerResponse contains the response from method ServerGroups.Delete. +type ServerGroupsDeletePollerResponse struct { + // Poller contains an initialized poller. + Poller *ServerGroupsDeletePoller + + // 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 ServerGroupsDeletePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServerGroupsDeleteResponse, error) { + respType := ServerGroupsDeleteResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServerGroupsDeletePollerResponse from the provided client and resume token. +func (l *ServerGroupsDeletePollerResponse) Resume(ctx context.Context, client *ServerGroupsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServerGroupsClient.Delete", token, client.pl, client.deleteHandleError) + if err != nil { + return err + } + poller := &ServerGroupsDeletePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServerGroupsDeleteResponse contains the response from method ServerGroups.Delete. +type ServerGroupsDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsGetResponse contains the response from method ServerGroups.Get. +type ServerGroupsGetResponse struct { + ServerGroupsGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsGetResult contains the result from method ServerGroups.Get. +type ServerGroupsGetResult struct { + ServerGroup +} + +// ServerGroupsListByResourceGroupResponse contains the response from method ServerGroups.ListByResourceGroup. +type ServerGroupsListByResourceGroupResponse struct { + ServerGroupsListByResourceGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsListByResourceGroupResult contains the result from method ServerGroups.ListByResourceGroup. +type ServerGroupsListByResourceGroupResult struct { + ServerGroupListResult +} + +// ServerGroupsListResponse contains the response from method ServerGroups.List. +type ServerGroupsListResponse struct { + ServerGroupsListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsListResult contains the result from method ServerGroups.List. +type ServerGroupsListResult struct { + ServerGroupListResult +} + +// ServerGroupsRestartPollerResponse contains the response from method ServerGroups.Restart. +type ServerGroupsRestartPollerResponse struct { + // Poller contains an initialized poller. + Poller *ServerGroupsRestartPoller + + // 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 ServerGroupsRestartPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServerGroupsRestartResponse, error) { + respType := ServerGroupsRestartResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServerGroupsRestartPollerResponse from the provided client and resume token. +func (l *ServerGroupsRestartPollerResponse) Resume(ctx context.Context, client *ServerGroupsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServerGroupsClient.Restart", token, client.pl, client.restartHandleError) + if err != nil { + return err + } + poller := &ServerGroupsRestartPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServerGroupsRestartResponse contains the response from method ServerGroups.Restart. +type ServerGroupsRestartResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsStartPollerResponse contains the response from method ServerGroups.Start. +type ServerGroupsStartPollerResponse struct { + // Poller contains an initialized poller. + Poller *ServerGroupsStartPoller + + // 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 ServerGroupsStartPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServerGroupsStartResponse, error) { + respType := ServerGroupsStartResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServerGroupsStartPollerResponse from the provided client and resume token. +func (l *ServerGroupsStartPollerResponse) Resume(ctx context.Context, client *ServerGroupsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServerGroupsClient.Start", token, client.pl, client.startHandleError) + if err != nil { + return err + } + poller := &ServerGroupsStartPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServerGroupsStartResponse contains the response from method ServerGroups.Start. +type ServerGroupsStartResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsStopPollerResponse contains the response from method ServerGroups.Stop. +type ServerGroupsStopPollerResponse struct { + // Poller contains an initialized poller. + Poller *ServerGroupsStopPoller + + // 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 ServerGroupsStopPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServerGroupsStopResponse, error) { + respType := ServerGroupsStopResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServerGroupsStopPollerResponse from the provided client and resume token. +func (l *ServerGroupsStopPollerResponse) Resume(ctx context.Context, client *ServerGroupsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServerGroupsClient.Stop", token, client.pl, client.stopHandleError) + if err != nil { + return err + } + poller := &ServerGroupsStopPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServerGroupsStopResponse contains the response from method ServerGroups.Stop. +type ServerGroupsStopResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsUpdatePollerResponse contains the response from method ServerGroups.Update. +type ServerGroupsUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *ServerGroupsUpdatePoller + + // 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 ServerGroupsUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServerGroupsUpdateResponse, error) { + respType := ServerGroupsUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.ServerGroup) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServerGroupsUpdatePollerResponse from the provided client and resume token. +func (l *ServerGroupsUpdatePollerResponse) Resume(ctx context.Context, client *ServerGroupsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServerGroupsClient.Update", token, client.pl, client.updateHandleError) + if err != nil { + return err + } + poller := &ServerGroupsUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServerGroupsUpdateResponse contains the response from method ServerGroups.Update. +type ServerGroupsUpdateResponse struct { + ServerGroupsUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServerGroupsUpdateResult contains the result from method ServerGroups.Update. +type ServerGroupsUpdateResult struct { + ServerGroup +} + +// ServersGetResponse contains the response from method Servers.Get. +type ServersGetResponse struct { + ServersGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersGetResult contains the result from method Servers.Get. +type ServersGetResult struct { + ServerGroupServer +} + +// ServersListByServerGroupResponse contains the response from method Servers.ListByServerGroup. +type ServersListByServerGroupResponse struct { + ServersListByServerGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersListByServerGroupResult contains the result from method Servers.ListByServerGroup. +type ServersListByServerGroupResult struct { + ServerGroupServerListResult +} diff --git a/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_roles_client.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_roles_client.go new file mode 100644 index 000000000000..73df2b8456be --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_roles_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 armpostgresqlhsc + +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" +) + +// RolesClient contains the methods for the Roles group. +// Don't use this type directly, use NewRolesClient() instead. +type RolesClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewRolesClient creates a new instance of RolesClient with the specified values. +func NewRolesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) *RolesClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &RolesClient{subscriptionID: subscriptionID, ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// BeginCreate - Creates a new role or updates an existing role. +// If the operation fails it returns the *CloudError error type. +func (client *RolesClient) BeginCreate(ctx context.Context, resourceGroupName string, serverGroupName string, roleName string, parameters Role, options *RolesBeginCreateOptions) (RolesCreatePollerResponse, error) { + resp, err := client.create(ctx, resourceGroupName, serverGroupName, roleName, parameters, options) + if err != nil { + return RolesCreatePollerResponse{}, err + } + result := RolesCreatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("RolesClient.Create", "", resp, client.pl, client.createHandleError) + if err != nil { + return RolesCreatePollerResponse{}, err + } + result.Poller = &RolesCreatePoller{ + pt: pt, + } + return result, nil +} + +// Create - Creates a new role or updates an existing role. +// If the operation fails it returns the *CloudError error type. +func (client *RolesClient) create(ctx context.Context, resourceGroupName string, serverGroupName string, roleName string, parameters Role, options *RolesBeginCreateOptions) (*http.Response, error) { + req, err := client.createCreateRequest(ctx, resourceGroupName, serverGroupName, roleName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + return nil, client.createHandleError(resp) + } + return resp, nil +} + +// createCreateRequest creates the Create request. +func (client *RolesClient) createCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, roleName string, parameters Role, options *RolesBeginCreateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/roles/{roleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if roleName == "" { + return nil, errors.New("parameter roleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{roleName}", url.PathEscape(roleName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createHandleError handles the Create error response. +func (client *RolesClient) createHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginDelete - Deletes a server group role. +// If the operation fails it returns the *CloudError error type. +func (client *RolesClient) BeginDelete(ctx context.Context, resourceGroupName string, serverGroupName string, roleName string, options *RolesBeginDeleteOptions) (RolesDeletePollerResponse, error) { + resp, err := client.deleteOperation(ctx, resourceGroupName, serverGroupName, roleName, options) + if err != nil { + return RolesDeletePollerResponse{}, err + } + result := RolesDeletePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("RolesClient.Delete", "", resp, client.pl, client.deleteHandleError) + if err != nil { + return RolesDeletePollerResponse{}, err + } + result.Poller = &RolesDeletePoller{ + pt: pt, + } + return result, nil +} + +// Delete - Deletes a server group role. +// If the operation fails it returns the *CloudError error type. +func (client *RolesClient) deleteOperation(ctx context.Context, resourceGroupName string, serverGroupName string, roleName string, options *RolesBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, serverGroupName, roleName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + return nil, client.deleteHandleError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *RolesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, roleName string, options *RolesBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/roles/{roleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if roleName == "" { + return nil, errors.New("parameter roleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{roleName}", url.PathEscape(roleName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *RolesClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// ListByServerGroup - List all the roles in a given server group. +// If the operation fails it returns the *CloudError error type. +func (client *RolesClient) ListByServerGroup(ctx context.Context, resourceGroupName string, serverGroupName string, options *RolesListByServerGroupOptions) (RolesListByServerGroupResponse, error) { + req, err := client.listByServerGroupCreateRequest(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return RolesListByServerGroupResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return RolesListByServerGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return RolesListByServerGroupResponse{}, client.listByServerGroupHandleError(resp) + } + return client.listByServerGroupHandleResponse(resp) +} + +// listByServerGroupCreateRequest creates the ListByServerGroup request. +func (client *RolesClient) listByServerGroupCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *RolesListByServerGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/roles" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerGroupHandleResponse handles the ListByServerGroup response. +func (client *RolesClient) listByServerGroupHandleResponse(resp *http.Response) (RolesListByServerGroupResponse, error) { + result := RolesListByServerGroupResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.RoleListResult); err != nil { + return RolesListByServerGroupResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listByServerGroupHandleError handles the ListByServerGroup error response. +func (client *RolesClient) listByServerGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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/postgresqlhsc/armpostgresqlhsc/zz_generated_servergroups_client.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_servergroups_client.go new file mode 100644 index 000000000000..79d944429301 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_servergroups_client.go @@ -0,0 +1,733 @@ +//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 armpostgresqlhsc + +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" +) + +// ServerGroupsClient contains the methods for the ServerGroups group. +// Don't use this type directly, use NewServerGroupsClient() instead. +type ServerGroupsClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewServerGroupsClient creates a new instance of ServerGroupsClient with the specified values. +func NewServerGroupsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) *ServerGroupsClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &ServerGroupsClient{subscriptionID: subscriptionID, ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// CheckNameAvailability - Check the availability of name for resource +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) CheckNameAvailability(ctx context.Context, nameAvailabilityRequest NameAvailabilityRequest, options *ServerGroupsCheckNameAvailabilityOptions) (ServerGroupsCheckNameAvailabilityResponse, error) { + req, err := client.checkNameAvailabilityCreateRequest(ctx, nameAvailabilityRequest, options) + if err != nil { + return ServerGroupsCheckNameAvailabilityResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ServerGroupsCheckNameAvailabilityResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ServerGroupsCheckNameAvailabilityResponse{}, client.checkNameAvailabilityHandleError(resp) + } + return client.checkNameAvailabilityHandleResponse(resp) +} + +// checkNameAvailabilityCreateRequest creates the CheckNameAvailability request. +func (client *ServerGroupsClient) checkNameAvailabilityCreateRequest(ctx context.Context, nameAvailabilityRequest NameAvailabilityRequest, options *ServerGroupsCheckNameAvailabilityOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DBForPostgreSql/checkNameAvailability" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, nameAvailabilityRequest) +} + +// checkNameAvailabilityHandleResponse handles the CheckNameAvailability response. +func (client *ServerGroupsClient) checkNameAvailabilityHandleResponse(resp *http.Response) (ServerGroupsCheckNameAvailabilityResponse, error) { + result := ServerGroupsCheckNameAvailabilityResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.NameAvailability); err != nil { + return ServerGroupsCheckNameAvailabilityResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// checkNameAvailabilityHandleError handles the CheckNameAvailability error response. +func (client *ServerGroupsClient) checkNameAvailabilityHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginCreateOrUpdate - Creates a new server group with servers. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, serverGroupName string, parameters ServerGroup, options *ServerGroupsBeginCreateOrUpdateOptions) (ServerGroupsCreateOrUpdatePollerResponse, error) { + resp, err := client.createOrUpdate(ctx, resourceGroupName, serverGroupName, parameters, options) + if err != nil { + return ServerGroupsCreateOrUpdatePollerResponse{}, err + } + result := ServerGroupsCreateOrUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServerGroupsClient.CreateOrUpdate", "", resp, client.pl, client.createOrUpdateHandleError) + if err != nil { + return ServerGroupsCreateOrUpdatePollerResponse{}, err + } + result.Poller = &ServerGroupsCreateOrUpdatePoller{ + pt: pt, + } + return result, nil +} + +// CreateOrUpdate - Creates a new server group with servers. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) createOrUpdate(ctx context.Context, resourceGroupName string, serverGroupName string, parameters ServerGroup, options *ServerGroupsBeginCreateOrUpdateOptions) (*http.Response, error) { + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, serverGroupName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + return nil, client.createOrUpdateHandleError(resp) + } + return resp, nil +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *ServerGroupsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, parameters ServerGroup, options *ServerGroupsBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleError handles the CreateOrUpdate error response. +func (client *ServerGroupsClient) createOrUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginDelete - Deletes a server group together with servers in it. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) BeginDelete(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginDeleteOptions) (ServerGroupsDeletePollerResponse, error) { + resp, err := client.deleteOperation(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return ServerGroupsDeletePollerResponse{}, err + } + result := ServerGroupsDeletePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServerGroupsClient.Delete", "", resp, client.pl, client.deleteHandleError) + if err != nil { + return ServerGroupsDeletePollerResponse{}, err + } + result.Poller = &ServerGroupsDeletePoller{ + pt: pt, + } + return result, nil +} + +// Delete - Deletes a server group together with servers in it. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) deleteOperation(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + return nil, client.deleteHandleError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *ServerGroupsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *ServerGroupsClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Gets information about a server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) Get(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsGetOptions) (ServerGroupsGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return ServerGroupsGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ServerGroupsGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ServerGroupsGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ServerGroupsClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ServerGroupsClient) getHandleResponse(resp *http.Response) (ServerGroupsGetResponse, error) { + result := ServerGroupsGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerGroup); err != nil { + return ServerGroupsGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *ServerGroupsClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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 all the server groups in a given subscription. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) List(options *ServerGroupsListOptions) *ServerGroupsListPager { + return &ServerGroupsListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp ServerGroupsListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ServerGroupListResult.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *ServerGroupsClient) listCreateRequest(ctx context.Context, options *ServerGroupsListOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DBForPostgreSql/serverGroupsv2" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *ServerGroupsClient) listHandleResponse(resp *http.Response) (ServerGroupsListResponse, error) { + result := ServerGroupsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerGroupListResult); err != nil { + return ServerGroupsListResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *ServerGroupsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// ListByResourceGroup - List all the server groups in a given resource group. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) ListByResourceGroup(resourceGroupName string, options *ServerGroupsListByResourceGroupOptions) *ServerGroupsListByResourceGroupPager { + return &ServerGroupsListByResourceGroupPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, + advancer: func(ctx context.Context, resp ServerGroupsListByResourceGroupResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ServerGroupListResult.NextLink) + }, + } +} + +// listByResourceGroupCreateRequest creates the ListByResourceGroup request. +func (client *ServerGroupsClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *ServerGroupsListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByResourceGroupHandleResponse handles the ListByResourceGroup response. +func (client *ServerGroupsClient) listByResourceGroupHandleResponse(resp *http.Response) (ServerGroupsListByResourceGroupResponse, error) { + result := ServerGroupsListByResourceGroupResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerGroupListResult); err != nil { + return ServerGroupsListByResourceGroupResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listByResourceGroupHandleError handles the ListByResourceGroup error response. +func (client *ServerGroupsClient) listByResourceGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginRestart - Restarts the server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) BeginRestart(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginRestartOptions) (ServerGroupsRestartPollerResponse, error) { + resp, err := client.restart(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return ServerGroupsRestartPollerResponse{}, err + } + result := ServerGroupsRestartPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServerGroupsClient.Restart", "", resp, client.pl, client.restartHandleError) + if err != nil { + return ServerGroupsRestartPollerResponse{}, err + } + result.Poller = &ServerGroupsRestartPoller{ + pt: pt, + } + return result, nil +} + +// Restart - Restarts the server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) restart(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginRestartOptions) (*http.Response, error) { + req, err := client.restartCreateRequest(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.restartHandleError(resp) + } + return resp, nil +} + +// restartCreateRequest creates the Restart request. +func (client *ServerGroupsClient) restartCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginRestartOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/restart" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// restartHandleError handles the Restart error response. +func (client *ServerGroupsClient) restartHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginStart - Starts the server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) BeginStart(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginStartOptions) (ServerGroupsStartPollerResponse, error) { + resp, err := client.start(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return ServerGroupsStartPollerResponse{}, err + } + result := ServerGroupsStartPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServerGroupsClient.Start", "", resp, client.pl, client.startHandleError) + if err != nil { + return ServerGroupsStartPollerResponse{}, err + } + result.Poller = &ServerGroupsStartPoller{ + pt: pt, + } + return result, nil +} + +// Start - Starts the server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) start(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginStartOptions) (*http.Response, error) { + req, err := client.startCreateRequest(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.startHandleError(resp) + } + return resp, nil +} + +// startCreateRequest creates the Start request. +func (client *ServerGroupsClient) startCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginStartOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/start" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// startHandleError handles the Start error response. +func (client *ServerGroupsClient) startHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginStop - Stops the server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) BeginStop(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginStopOptions) (ServerGroupsStopPollerResponse, error) { + resp, err := client.stop(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return ServerGroupsStopPollerResponse{}, err + } + result := ServerGroupsStopPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServerGroupsClient.Stop", "", resp, client.pl, client.stopHandleError) + if err != nil { + return ServerGroupsStopPollerResponse{}, err + } + result.Poller = &ServerGroupsStopPoller{ + pt: pt, + } + return result, nil +} + +// Stop - Stops the server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) stop(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginStopOptions) (*http.Response, error) { + req, err := client.stopCreateRequest(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.stopHandleError(resp) + } + return resp, nil +} + +// stopCreateRequest creates the Stop request. +func (client *ServerGroupsClient) stopCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServerGroupsBeginStopOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/stop" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// stopHandleError handles the Stop error response. +func (client *ServerGroupsClient) stopHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// BeginUpdate - Updates an existing server group. The request body can contain one to many of the properties present in the normal server group definition. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) BeginUpdate(ctx context.Context, resourceGroupName string, serverGroupName string, parameters ServerGroupForUpdate, options *ServerGroupsBeginUpdateOptions) (ServerGroupsUpdatePollerResponse, error) { + resp, err := client.update(ctx, resourceGroupName, serverGroupName, parameters, options) + if err != nil { + return ServerGroupsUpdatePollerResponse{}, err + } + result := ServerGroupsUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServerGroupsClient.Update", "", resp, client.pl, client.updateHandleError) + if err != nil { + return ServerGroupsUpdatePollerResponse{}, err + } + result.Poller = &ServerGroupsUpdatePoller{ + pt: pt, + } + return result, nil +} + +// Update - Updates an existing server group. The request body can contain one to many of the properties present in the normal server group definition. +// If the operation fails it returns the *CloudError error type. +func (client *ServerGroupsClient) update(ctx context.Context, resourceGroupName string, serverGroupName string, parameters ServerGroupForUpdate, options *ServerGroupsBeginUpdateOptions) (*http.Response, error) { + req, err := client.updateCreateRequest(ctx, resourceGroupName, serverGroupName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.updateHandleError(resp) + } + return resp, nil +} + +// updateCreateRequest creates the Update request. +func (client *ServerGroupsClient) updateCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, parameters ServerGroupForUpdate, options *ServerGroupsBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// updateHandleError handles the Update error response. +func (client *ServerGroupsClient) updateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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/postgresqlhsc/armpostgresqlhsc/zz_generated_servers_client.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_servers_client.go new file mode 100644 index 000000000000..4e57c1c3cab9 --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_servers_client.go @@ -0,0 +1,177 @@ +//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 armpostgresqlhsc + +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" +) + +// ServersClient contains the methods for the Servers group. +// Don't use this type directly, use NewServersClient() instead. +type ServersClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewServersClient creates a new instance of ServersClient with the specified values. +func NewServersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) *ServersClient { + cp := arm.ClientOptions{} + if options != nil { + cp = *options + } + if len(cp.Host) == 0 { + cp.Host = arm.AzurePublicCloud + } + return &ServersClient{subscriptionID: subscriptionID, ep: string(cp.Host), pl: armruntime.NewPipeline(module, version, credential, &cp)} +} + +// Get - Gets information about a server in server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) Get(ctx context.Context, resourceGroupName string, serverGroupName string, serverName string, options *ServersGetOptions) (ServersGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverGroupName, serverName, options) + if err != nil { + return ServersGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ServersGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ServersGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ServersClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, serverName string, options *ServersGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/servers/{serverName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ServersClient) getHandleResponse(resp *http.Response) (ServersGetResponse, error) { + result := ServersGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerGroupServer); err != nil { + return ServersGetResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *ServersClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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) +} + +// ListByServerGroup - Lists servers of a server group. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) ListByServerGroup(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServersListByServerGroupOptions) (ServersListByServerGroupResponse, error) { + req, err := client.listByServerGroupCreateRequest(ctx, resourceGroupName, serverGroupName, options) + if err != nil { + return ServersListByServerGroupResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ServersListByServerGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ServersListByServerGroupResponse{}, client.listByServerGroupHandleError(resp) + } + return client.listByServerGroupHandleResponse(resp) +} + +// listByServerGroupCreateRequest creates the ListByServerGroup request. +func (client *ServersClient) listByServerGroupCreateRequest(ctx context.Context, resourceGroupName string, serverGroupName string, options *ServersListByServerGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/serverGroupsv2/{serverGroupName}/servers" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverGroupName == "" { + return nil, errors.New("parameter serverGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverGroupName}", url.PathEscape(serverGroupName)) + 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", "2020-10-05-privatepreview") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerGroupHandleResponse handles the ListByServerGroup response. +func (client *ServersClient) listByServerGroupHandleResponse(resp *http.Response) (ServersListByServerGroupResponse, error) { + result := ServersListByServerGroupResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerGroupServerListResult); err != nil { + return ServersListByServerGroupResponse{}, runtime.NewResponseError(err, resp) + } + return result, nil +} + +// listByServerGroupHandleError handles the ListByServerGroup error response. +func (client *ServersClient) listByServerGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{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/postgresqlhsc/armpostgresqlhsc/zz_generated_time_rfc3339.go b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/zz_generated_time_rfc3339.go new file mode 100644 index 000000000000..a7ed8f26454d --- /dev/null +++ b/sdk/resourcemanager/postgresqlhsc/armpostgresqlhsc/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 armpostgresqlhsc + +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 +}