From 11b70a0306125de33888a65a9f47e642ca71230b Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Mon, 5 Jun 2023 11:17:37 +0800 Subject: [PATCH 1/6] [Release] sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/1.0.0 generation from spec commit: 0d41e635294dce73dfa99b07f3da4b68a9c9e29c --- .../armcosmosforpostgresql/CHANGELOG.md | 7 + .../armcosmosforpostgresql/LICENSE.txt | 21 + .../armcosmosforpostgresql/README.md | 85 + .../armcosmosforpostgresql/autorest.md | 13 + .../armcosmosforpostgresql/build.go | 7 + .../armcosmosforpostgresql/ci.yml | 28 + .../armcosmosforpostgresql/client_factory.go | 79 + .../armcosmosforpostgresql/clusters_client.go | 710 +++++++ .../clusters_client_example_test.go | 1262 ++++++++++++ .../configurations_client.go | 502 +++++ .../configurations_client_example_test.go | 494 +++++ .../armcosmosforpostgresql/constants.go | 147 ++ .../firewallrules_client.go | 304 +++ .../firewallrules_client_example_test.go | 189 ++ .../armcosmosforpostgresql/go.mod | 21 + .../armcosmosforpostgresql/go.sum | 31 + .../armcosmosforpostgresql/models.go | 896 +++++++++ .../armcosmosforpostgresql/models_serde.go | 1689 +++++++++++++++++ .../operations_client.go | 88 + .../operations_client_example_test.go | 230 +++ .../privateendpointconnections_client.go | 305 +++ ...endpointconnections_client_example_test.go | 213 +++ .../privatelinkresources_client.go | 166 ++ ...rivatelinkresources_client_example_test.go | 126 ++ .../armcosmosforpostgresql/response_types.go | 185 ++ .../armcosmosforpostgresql/roles_client.go | 301 +++ .../roles_client_example_test.go | 180 ++ .../armcosmosforpostgresql/servers_client.go | 165 ++ .../servers_client_example_test.go | 182 ++ .../armcosmosforpostgresql/time_rfc3339.go | 87 + 30 files changed, 8713 insertions(+) create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/LICENSE.txt create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/README.md create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/autorest.md create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/build.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/ci.yml create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/client_factory.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/clusters_client.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/clusters_client_example_test.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/configurations_client.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/configurations_client_example_test.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/constants.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/firewallrules_client.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/firewallrules_client_example_test.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.mod create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.sum create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/models.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/models_serde.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/operations_client.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/operations_client_example_test.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privateendpointconnections_client.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privateendpointconnections_client_example_test.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privatelinkresources_client.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privatelinkresources_client_example_test.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/response_types.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/roles_client.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/roles_client_example_test.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/servers_client.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/servers_client_example_test.go create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/time_rfc3339.go diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md new file mode 100644 index 000000000000..4e7cd155f72b --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md @@ -0,0 +1,7 @@ +# Release History + +## 1.0.0 (2023-06-23) + +The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html). + +To learn more, please refer to our documentation [Quick Start](https://aka.ms/azsdk/go/mgmt). \ No newline at end of file diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/LICENSE.txt b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/LICENSE.txt new file mode 100644 index 000000000000..dc0c2ffb3dc1 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/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/cosmosforpostgresql/armcosmosforpostgresql/README.md b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/README.md new file mode 100644 index 000000000000..7f129165bb7a --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/README.md @@ -0,0 +1,85 @@ +# Azure Cosmosforpostgresql Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql) + +The `armcosmosforpostgresql` module provides operations for working with Azure Cosmosforpostgresql. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.18 or above (You could download and install the latest version of Go from [here](https://go.dev/doc/install). It will replace the existing Go on your machine. If you want to install multiple Go versions on the same machine, you could refer this [doc](https://go.dev/doc/manage-install).) + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Cosmosforpostgresql module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Cosmosforpostgresql. 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). + +## Client Factory + +Azure Cosmosforpostgresql module consists of one or more clients. We provide a client factory which could be used to create any client in this module. + +```go +clientFactory, err := armcosmosforpostgresql.NewClientFactory(, 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 { + ClientOptions: azcore.ClientOptions { + Cloud: cloud.AzureChina, + }, +} +client, err := armcosmosforpostgresql.NewClientFactory(, cred, &options) +``` + +## Clients + +A client groups a set of related APIs, providing access to its functionality. Create one or more clients to access the APIs you require using client factory. + +```go +client := clientFactory.NewPrivateLinkResourcesClient() +``` + +## 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 `Cosmosforpostgresql` 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/cosmosforpostgresql/armcosmosforpostgresql/autorest.md b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/autorest.md new file mode 100644 index 000000000000..8003e412260c --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/autorest.md @@ -0,0 +1,13 @@ +### AutoRest Configuration + +> see https://aka.ms/autorest + +``` yaml +azure-arm: true +require: +- https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/readme.md +- https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 1.0.0 +tag: package-2022-11-08 +``` \ No newline at end of file diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/build.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/build.go new file mode 100644 index 000000000000..c641c8ba91ca --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/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 ../../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate -alwaysSetBodyParamRequired -removeUnreferencedTypes resourcemanager/cosmosforpostgresql/armcosmosforpostgresql + +package armcosmosforpostgresql diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/ci.yml b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/ci.yml new file mode 100644 index 000000000000..fbf74672d951 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/ci.yml @@ -0,0 +1,28 @@ +# 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/cosmosforpostgresql/armcosmosforpostgresql/ + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + IncludeRelease: true + ServiceDirectory: 'resourcemanager/cosmosforpostgresql/armcosmosforpostgresql' diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/client_factory.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/client_factory.go new file mode 100644 index 000000000000..4009535a3902 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/client_factory.go @@ -0,0 +1,79 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" +) + +// ClientFactory is a client factory used to create any client in this module. +// Don't use this type directly, use NewClientFactory instead. +type ClientFactory struct { + subscriptionID string + credential azcore.TokenCredential + options *arm.ClientOptions +} + +// NewClientFactory creates a new instance of ClientFactory with the specified values. +// The parameter values will be propagated to any client created from this factory. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewClientFactory(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ClientFactory, error) { + _, err := arm.NewClient(moduleName+".ClientFactory", moduleVersion, credential, options) + if err != nil { + return nil, err + } + return &ClientFactory{ + subscriptionID: subscriptionID, credential: credential, + options: options.Clone(), + }, nil +} + +func (c *ClientFactory) NewClustersClient() *ClustersClient { + subClient, _ := NewClustersClient(c.subscriptionID, c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewServersClient() *ServersClient { + subClient, _ := NewServersClient(c.subscriptionID, c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewConfigurationsClient() *ConfigurationsClient { + subClient, _ := NewConfigurationsClient(c.subscriptionID, c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewFirewallRulesClient() *FirewallRulesClient { + subClient, _ := NewFirewallRulesClient(c.subscriptionID, c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewRolesClient() *RolesClient { + subClient, _ := NewRolesClient(c.subscriptionID, c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewOperationsClient() *OperationsClient { + subClient, _ := NewOperationsClient(c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewPrivateEndpointConnectionsClient() *PrivateEndpointConnectionsClient { + subClient, _ := NewPrivateEndpointConnectionsClient(c.subscriptionID, c.credential, c.options) + return subClient +} + +func (c *ClientFactory) NewPrivateLinkResourcesClient() *PrivateLinkResourcesClient { + subClient, _ := NewPrivateLinkResourcesClient(c.subscriptionID, c.credential, c.options) + return subClient +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/clusters_client.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/clusters_client.go new file mode 100644 index 000000000000..a97853d2abda --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/clusters_client.go @@ -0,0 +1,710 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "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" +) + +// ClustersClient contains the methods for the Clusters group. +// Don't use this type directly, use NewClustersClient() instead. +type ClustersClient struct { + internal *arm.Client + subscriptionID string +} + +// NewClustersClient creates a new instance of ClustersClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewClustersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ClustersClient, error) { + cl, err := arm.NewClient(moduleName+".ClustersClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &ClustersClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// CheckNameAvailability - Checks availability of a cluster name. Cluster names should be globally unique; at least 3 characters +// and at most 40 characters long; they must only contain lowercase letters, numbers, and hyphens; +// and must not start or end with a hyphen. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - nameAvailabilityRequest - The required parameters for checking if cluster name is available. +// - options - ClustersClientCheckNameAvailabilityOptions contains the optional parameters for the ClustersClient.CheckNameAvailability +// method. +func (client *ClustersClient) CheckNameAvailability(ctx context.Context, nameAvailabilityRequest NameAvailabilityRequest, options *ClustersClientCheckNameAvailabilityOptions) (ClustersClientCheckNameAvailabilityResponse, error) { + req, err := client.checkNameAvailabilityCreateRequest(ctx, nameAvailabilityRequest, options) + if err != nil { + return ClustersClientCheckNameAvailabilityResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ClustersClientCheckNameAvailabilityResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ClustersClientCheckNameAvailabilityResponse{}, runtime.NewResponseError(resp) + } + return client.checkNameAvailabilityHandleResponse(resp) +} + +// checkNameAvailabilityCreateRequest creates the CheckNameAvailability request. +func (client *ClustersClient) checkNameAvailabilityCreateRequest(ctx context.Context, nameAvailabilityRequest NameAvailabilityRequest, options *ClustersClientCheckNameAvailabilityOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/checkNameAvailability" + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, nameAvailabilityRequest) +} + +// checkNameAvailabilityHandleResponse handles the CheckNameAvailability response. +func (client *ClustersClient) checkNameAvailabilityHandleResponse(resp *http.Response) (ClustersClientCheckNameAvailabilityResponse, error) { + result := ClustersClientCheckNameAvailabilityResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.NameAvailability); err != nil { + return ClustersClientCheckNameAvailabilityResponse{}, err + } + return result, nil +} + +// BeginCreate - Creates a new cluster with servers. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - parameters - The required parameters for creating or updating a cluster. +// - options - ClustersClientBeginCreateOptions contains the optional parameters for the ClustersClient.BeginCreate method. +func (client *ClustersClient) BeginCreate(ctx context.Context, resourceGroupName string, clusterName string, parameters Cluster, options *ClustersClientBeginCreateOptions) (*runtime.Poller[ClustersClientCreateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.create(ctx, resourceGroupName, clusterName, parameters, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClustersClientCreateResponse]{ + FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + }) + } else { + return runtime.NewPollerFromResumeToken[ClustersClientCreateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Create - Creates a new cluster with servers. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ClustersClient) create(ctx context.Context, resourceGroupName string, clusterName string, parameters Cluster, options *ClustersClientBeginCreateOptions) (*http.Response, error) { + req, err := client.createCreateRequest(ctx, resourceGroupName, clusterName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// createCreateRequest creates the Create request. +func (client *ClustersClient) createCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, parameters Cluster, options *ClustersClientBeginCreateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// BeginDelete - Deletes a cluster together with servers in it. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - ClustersClientBeginDeleteOptions contains the optional parameters for the ClustersClient.BeginDelete method. +func (client *ClustersClient) BeginDelete(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginDeleteOptions) (*runtime.Poller[ClustersClientDeleteResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.deleteOperation(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClustersClientDeleteResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[ClustersClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Delete - Deletes a cluster together with servers in it. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ClustersClient) deleteOperation(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *ClustersClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - Gets information about a cluster such as compute and storage configuration and cluster lifecycle metadata such as +// cluster creation date and time. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - ClustersClientGetOptions contains the optional parameters for the ClustersClient.Get method. +func (client *ClustersClient) Get(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientGetOptions) (ClustersClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return ClustersClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ClustersClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ClustersClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ClustersClient) getCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ClustersClient) getHandleResponse(resp *http.Response) (ClustersClientGetResponse, error) { + result := ClustersClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Cluster); err != nil { + return ClustersClientGetResponse{}, err + } + return result, nil +} + +// NewListPager - Lists all clusters in a subscription. +// +// Generated from API version 2022-11-08 +// - options - ClustersClientListOptions contains the optional parameters for the ClustersClient.NewListPager method. +func (client *ClustersClient) NewListPager(options *ClustersClientListOptions) *runtime.Pager[ClustersClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[ClustersClientListResponse]{ + More: func(page ClustersClientListResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *ClustersClientListResponse) (ClustersClientListResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listCreateRequest(ctx, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return ClustersClientListResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ClustersClientListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ClustersClientListResponse{}, runtime.NewResponseError(resp) + } + return client.listHandleResponse(resp) + }, + }) +} + +// listCreateRequest creates the List request. +func (client *ClustersClient) listCreateRequest(ctx context.Context, options *ClustersClientListOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2" + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *ClustersClient) listHandleResponse(resp *http.Response) (ClustersClientListResponse, error) { + result := ClustersClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ClusterListResult); err != nil { + return ClustersClientListResponse{}, err + } + return result, nil +} + +// NewListByResourceGroupPager - Lists all clusters in a resource group. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - options - ClustersClientListByResourceGroupOptions contains the optional parameters for the ClustersClient.NewListByResourceGroupPager +// method. +func (client *ClustersClient) NewListByResourceGroupPager(resourceGroupName string, options *ClustersClientListByResourceGroupOptions) *runtime.Pager[ClustersClientListByResourceGroupResponse] { + return runtime.NewPager(runtime.PagingHandler[ClustersClientListByResourceGroupResponse]{ + More: func(page ClustersClientListByResourceGroupResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *ClustersClientListByResourceGroupResponse) (ClustersClientListByResourceGroupResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return ClustersClientListByResourceGroupResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ClustersClientListByResourceGroupResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ClustersClientListByResourceGroupResponse{}, runtime.NewResponseError(resp) + } + return client.listByResourceGroupHandleResponse(resp) + }, + }) +} + +// listByResourceGroupCreateRequest creates the ListByResourceGroup request. +func (client *ClustersClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *ClustersClientListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2" + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByResourceGroupHandleResponse handles the ListByResourceGroup response. +func (client *ClustersClient) listByResourceGroupHandleResponse(resp *http.Response) (ClustersClientListByResourceGroupResponse, error) { + result := ClustersClientListByResourceGroupResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ClusterListResult); err != nil { + return ClustersClientListByResourceGroupResponse{}, err + } + return result, nil +} + +// BeginPromoteReadReplica - Promotes read replica cluster to an independent read-write cluster. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - ClustersClientBeginPromoteReadReplicaOptions contains the optional parameters for the ClustersClient.BeginPromoteReadReplica +// method. +func (client *ClustersClient) BeginPromoteReadReplica(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginPromoteReadReplicaOptions) (*runtime.Poller[ClustersClientPromoteReadReplicaResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.promoteReadReplica(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClustersClientPromoteReadReplicaResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[ClustersClientPromoteReadReplicaResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// PromoteReadReplica - Promotes read replica cluster to an independent read-write cluster. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ClustersClient) promoteReadReplica(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginPromoteReadReplicaOptions) (*http.Response, error) { + req, err := client.promoteReadReplicaCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusAccepted) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// promoteReadReplicaCreateRequest creates the PromoteReadReplica request. +func (client *ClustersClient) promoteReadReplicaCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginPromoteReadReplicaOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/promote" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// BeginRestart - Restarts all nodes in the cluster. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - ClustersClientBeginRestartOptions contains the optional parameters for the ClustersClient.BeginRestart method. +func (client *ClustersClient) BeginRestart(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginRestartOptions) (*runtime.Poller[ClustersClientRestartResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.restart(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClustersClientRestartResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[ClustersClientRestartResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Restart - Restarts all nodes in the cluster. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ClustersClient) restart(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginRestartOptions) (*http.Response, error) { + req, err := client.restartCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusAccepted) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// restartCreateRequest creates the Restart request. +func (client *ClustersClient) restartCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginRestartOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/restart" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// BeginStart - Starts stopped compute on all cluster nodes. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - ClustersClientBeginStartOptions contains the optional parameters for the ClustersClient.BeginStart method. +func (client *ClustersClient) BeginStart(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginStartOptions) (*runtime.Poller[ClustersClientStartResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.start(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClustersClientStartResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[ClustersClientStartResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Start - Starts stopped compute on all cluster nodes. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ClustersClient) start(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginStartOptions) (*http.Response, error) { + req, err := client.startCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// startCreateRequest creates the Start request. +func (client *ClustersClient) startCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginStartOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/start" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// BeginStop - Stops compute on all cluster nodes. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - ClustersClientBeginStopOptions contains the optional parameters for the ClustersClient.BeginStop method. +func (client *ClustersClient) BeginStop(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginStopOptions) (*runtime.Poller[ClustersClientStopResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.stop(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClustersClientStopResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[ClustersClientStopResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Stop - Stops compute on all cluster nodes. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ClustersClient) stop(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginStopOptions) (*http.Response, error) { + req, err := client.stopCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// stopCreateRequest creates the Stop request. +func (client *ClustersClient) stopCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *ClustersClientBeginStopOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/stop" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// BeginUpdate - Updates an existing cluster. The request body can contain one or several properties from the cluster definition. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - parameters - The parameters for updating a cluster. +// - options - ClustersClientBeginUpdateOptions contains the optional parameters for the ClustersClient.BeginUpdate method. +func (client *ClustersClient) BeginUpdate(ctx context.Context, resourceGroupName string, clusterName string, parameters ClusterForUpdate, options *ClustersClientBeginUpdateOptions) (*runtime.Poller[ClustersClientUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.update(ctx, resourceGroupName, clusterName, parameters, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ClustersClientUpdateResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[ClustersClientUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Update - Updates an existing cluster. The request body can contain one or several properties from the cluster definition. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ClustersClient) update(ctx context.Context, resourceGroupName string, clusterName string, parameters ClusterForUpdate, options *ClustersClientBeginUpdateOptions) (*http.Response, error) { + req, err := client.updateCreateRequest(ctx, resourceGroupName, clusterName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// updateCreateRequest creates the Update request. +func (client *ClustersClient) updateCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, parameters ClusterForUpdate, options *ClustersClientBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/clusters_client_example_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/clusters_client_example_test.go new file mode 100644 index 000000000000..34c8d15a4640 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/clusters_client_example_test.go @@ -0,0 +1,1262 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql_test + +import ( + "context" + "log" + + "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterList.json +func ExampleClustersClient_NewListPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewClustersClient().NewListPager(nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.ClusterListResult = armcosmosforpostgresql.ClusterListResult{ + // Value: []*armcosmosforpostgresql.Cluster{ + // { + // Name: to.Ptr("testcluster1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("eastus"), + // Tags: map[string]*string{ + // "additionalProp1": to.Ptr("string"), + // }, + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](2097152), + // CoordinatorVCores: to.Ptr[int32](4), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-14T00:00:37.467Z"); return t}()), + // EnableHa: to.Ptr(false), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](2), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](2097152), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("14"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-01"), + // to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-02")}, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster1-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w0.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w1"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w1.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // }, + // { + // Name: to.Ptr("testcluster2"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup2/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster2"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("eastus"), + // Tags: map[string]*string{ + // "additionalProp1": to.Ptr("string"), + // }, + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + // CoordinatorVCores: to.Ptr[int32](4), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-15T00:01:32.317Z"); return t}()), + // EnableHa: to.Ptr(true), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](1), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](524288), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("15"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster2-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster2-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster2-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster2-w0.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // }}, + // } + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterListByResourceGroup.json +func ExampleClustersClient_NewListByResourceGroupPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewClustersClient().NewListByResourceGroupPager("TestGroup", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.ClusterListResult = armcosmosforpostgresql.ClusterListResult{ + // Value: []*armcosmosforpostgresql.Cluster{ + // { + // Name: to.Ptr("testcluster1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("eastus"), + // Tags: map[string]*string{ + // "additionalProp1": to.Ptr("string"), + // }, + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](2097152), + // CoordinatorVCores: to.Ptr[int32](4), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-14T00:00:37.467Z"); return t}()), + // EnableHa: to.Ptr(false), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](3), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](2097152), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("14"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-01"), + // to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-02")}, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster1-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w0.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w1"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w1.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w2"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w2.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // }, + // { + // Name: to.Ptr("testcluster2"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster2"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("eastus"), + // Tags: map[string]*string{ + // "additionalProp1": to.Ptr("string"), + // }, + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + // CoordinatorVCores: to.Ptr[int32](4), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-15T00:01:32.317Z"); return t}()), + // EnableHa: to.Ptr(true), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](2), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](524288), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("15"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster2-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster2-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster2-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster2-w0.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster2-w1"), + // FullyQualifiedDomainName: to.Ptr("testcluster2-w1.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // }}, + // } + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterCreate.json +func ExampleClustersClient_BeginCreate_createANewCluster() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginCreate(ctx, "TestGroup", "testcluster", armcosmosforpostgresql.Cluster{ + Location: to.Ptr("westus"), + Tags: map[string]*string{}, + Properties: &armcosmosforpostgresql.ClusterProperties{ + AdministratorLoginPassword: to.Ptr("password"), + CitusVersion: to.Ptr("11.1"), + CoordinatorEnablePublicIPAccess: to.Ptr(true), + CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + CoordinatorVCores: to.Ptr[int32](4), + EnableHa: to.Ptr(true), + EnableShardsOnCoordinator: to.Ptr(false), + NodeCount: to.Ptr[int32](3), + NodeEnablePublicIPAccess: to.Ptr(false), + NodeServerEdition: to.Ptr("MemoryOptimized"), + NodeStorageQuotaInMb: to.Ptr[int32](524288), + NodeVCores: to.Ptr[int32](8), + PostgresqlVersion: to.Ptr("15"), + PreferredPrimaryZone: to.Ptr("1"), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("westus"), + // Tags: map[string]*string{ + // }, + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + // CoordinatorVCores: to.Ptr[int32](4), + // EnableHa: to.Ptr(true), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](3), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](524288), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("15"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster-c"), + // FullyQualifiedDomainName: to.Ptr("c.testcluster.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster-w0"), + // FullyQualifiedDomainName: to.Ptr("w0.testcluster.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster-w2"), + // FullyQualifiedDomainName: to.Ptr("w0.testcluster.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster-w3"), + // FullyQualifiedDomainName: to.Ptr("w0.testcluster.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Provisioning"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterCreatePITR.json +func ExampleClustersClient_BeginCreate_createANewClusterAsAPointInTimeRestore() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginCreate(ctx, "TestGroup", "testcluster", armcosmosforpostgresql.Cluster{ + Location: to.Ptr("westus"), + Properties: &armcosmosforpostgresql.ClusterProperties{ + PointInTimeUTC: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2017-12-14T00:00:37.467Z"); return t }()), + SourceLocation: to.Ptr("westus"), + SourceResourceID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/source-cluster"), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("westus"), + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + // CoordinatorVCores: to.Ptr[int32](4), + // EnableHa: to.Ptr(true), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](1), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](524288), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("15"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster-c"), + // FullyQualifiedDomainName: to.Ptr("c.testcluster.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster-w0"), + // FullyQualifiedDomainName: to.Ptr("w0.testcluster.postgres.database.azure.com"), + // }}, + // SourceResourceID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/source-cluster"), + // State: to.Ptr("Provisioning"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterCreateReadReplica.json +func ExampleClustersClient_BeginCreate_createANewClusterAsAReadReplica() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginCreate(ctx, "TestGroup", "testcluster", armcosmosforpostgresql.Cluster{ + Location: to.Ptr("westus"), + Properties: &armcosmosforpostgresql.ClusterProperties{ + SourceLocation: to.Ptr("westus"), + SourceResourceID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/sourcecluster"), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("westus"), + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + // CoordinatorVCores: to.Ptr[int32](4), + // EnableHa: to.Ptr(true), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](1), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](524288), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("15"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster-c"), + // FullyQualifiedDomainName: to.Ptr("c.testcluster.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster-w0"), + // FullyQualifiedDomainName: to.Ptr("w0.testcluster.postgres.database.azure.com"), + // }}, + // SourceResourceID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/sourcecluster"), + // State: to.Ptr("Provisioning"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterGet.json +func ExampleClustersClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewClustersClient().Get(ctx, "TestGroup", "testcluster1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("eastus"), + // Tags: map[string]*string{ + // "additionalProp1": to.Ptr("string"), + // "additionalProp2": to.Ptr("string"), + // "additionalProp3": to.Ptr("string"), + // }, + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](2097152), + // CoordinatorVCores: to.Ptr[int32](4), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-14T00:00:37.467Z"); return t}()), + // EnableHa: to.Ptr(false), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](2), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](2097152), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("14"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-01"), + // to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-02")}, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster1-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w0.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w1"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w1.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterDelete.json +func ExampleClustersClient_BeginDelete() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginDelete(ctx, "TestGroup", "testcluster", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterScaleCompute.json +func ExampleClustersClient_BeginUpdate_scaleComputeUpOrDown() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginUpdate(ctx, "TestGroup", "testcluster", armcosmosforpostgresql.ClusterForUpdate{ + Properties: &armcosmosforpostgresql.ClusterPropertiesForUpdate{ + NodeVCores: to.Ptr[int32](16), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("westus"), + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](2097152), + // CoordinatorVCores: to.Ptr[int32](16), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-14T00:00:37.467Z"); return t}()), + // EnableHa: to.Ptr(false), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](3), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](2097152), + // NodeVCores: to.Ptr[int32](16), + // PostgresqlVersion: to.Ptr("14"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster1-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w0.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w1"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w1.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w2"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w2.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterAddNode.json +func ExampleClustersClient_BeginUpdate_scaleOutAddNewWorkerNodes() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginUpdate(ctx, "TestGroup", "testcluster", armcosmosforpostgresql.ClusterForUpdate{ + Properties: &armcosmosforpostgresql.ClusterPropertiesForUpdate{ + NodeCount: to.Ptr[int32](2), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("westus"), + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + // CoordinatorVCores: to.Ptr[int32](4), + // EnableHa: to.Ptr(true), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](2), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](524288), + // NodeVCores: to.Ptr[int32](8), + // PostgresqlVersion: to.Ptr("15"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster-c"), + // FullyQualifiedDomainName: to.Ptr("c.testcluster.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster-w0"), + // FullyQualifiedDomainName: to.Ptr("w0.testcluster.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster-w1"), + // FullyQualifiedDomainName: to.Ptr("w1.testcluster.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Provisioning"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterScaleStorage.json +func ExampleClustersClient_BeginUpdate_scaleUpStorage() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginUpdate(ctx, "TestGroup", "testcluster", armcosmosforpostgresql.ClusterForUpdate{ + Properties: &armcosmosforpostgresql.ClusterPropertiesForUpdate{ + NodeStorageQuotaInMb: to.Ptr[int32](2097152), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("westus"), + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](2097152), + // CoordinatorVCores: to.Ptr[int32](16), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-14T00:00:37.467Z"); return t}()), + // EnableHa: to.Ptr(false), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](3), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](2097152), + // NodeVCores: to.Ptr[int32](16), + // PostgresqlVersion: to.Ptr("14"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster1-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w0.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w1"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w1.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w2"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w2.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterUpdate.json +func ExampleClustersClient_BeginUpdate_updateMultipleConfigurationSettingsOfTheCluster() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginUpdate(ctx, "TestGroup", "testcluster", armcosmosforpostgresql.ClusterForUpdate{ + Properties: &armcosmosforpostgresql.ClusterPropertiesForUpdate{ + AdministratorLoginPassword: to.Ptr("newpassword"), + CoordinatorVCores: to.Ptr[int32](16), + NodeCount: to.Ptr[int32](4), + NodeVCores: to.Ptr[int32](16), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("westus"), + // Tags: map[string]*string{ + // "additionalProp1": to.Ptr("string"), + // "additionalProp2": to.Ptr("string"), + // "additionalProp3": to.Ptr("string"), + // }, + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](2097152), + // CoordinatorVCores: to.Ptr[int32](16), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-14T00:00:37.467Z"); return t}()), + // EnableHa: to.Ptr(false), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Disabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](0), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](4), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](2097152), + // NodeVCores: to.Ptr[int32](16), + // PostgresqlVersion: to.Ptr("14"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-01"), + // to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/testrg/providers/Microsoft.DBForPostgreSQL/serverGroupsv2/testreadreplica-02")}, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster1-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w0.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w1"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w1.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w2"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w2.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w3"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w2.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterUpdateMaintenanceWindow.json +func ExampleClustersClient_BeginUpdate_updateOrDefineMaintenanceWindow() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginUpdate(ctx, "TestGroup", "testcluster", armcosmosforpostgresql.ClusterForUpdate{ + Properties: &armcosmosforpostgresql.ClusterPropertiesForUpdate{ + MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + CustomWindow: to.Ptr("Enabled"), + DayOfWeek: to.Ptr[int32](0), + StartHour: to.Ptr[int32](8), + StartMinute: to.Ptr[int32](0), + }, + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Cluster = armcosmosforpostgresql.Cluster{ + // Name: to.Ptr("testcluster"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Location: to.Ptr("westus"), + // Properties: &armcosmosforpostgresql.ClusterProperties{ + // AdministratorLogin: to.Ptr("citus"), + // CitusVersion: to.Ptr("11.1"), + // CoordinatorEnablePublicIPAccess: to.Ptr(true), + // CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + // CoordinatorStorageQuotaInMb: to.Ptr[int32](2097152), + // CoordinatorVCores: to.Ptr[int32](16), + // EarliestRestoreTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-09-14T00:00:37.467Z"); return t}()), + // EnableHa: to.Ptr(false), + // EnableShardsOnCoordinator: to.Ptr(false), + // MaintenanceWindow: &armcosmosforpostgresql.MaintenanceWindow{ + // CustomWindow: to.Ptr("Enabled"), + // DayOfWeek: to.Ptr[int32](0), + // StartHour: to.Ptr[int32](8), + // StartMinute: to.Ptr[int32](0), + // }, + // NodeCount: to.Ptr[int32](2), + // NodeEnablePublicIPAccess: to.Ptr(false), + // NodeServerEdition: to.Ptr("MemoryOptimized"), + // NodeStorageQuotaInMb: to.Ptr[int32](2097152), + // NodeVCores: to.Ptr[int32](16), + // PostgresqlVersion: to.Ptr("14"), + // PreferredPrimaryZone: to.Ptr("1"), + // PrivateEndpointConnections: []*armcosmosforpostgresql.SimplePrivateEndpointConnection{ + // }, + // ProvisioningState: to.Ptr("Succeeded"), + // ReadReplicas: []*string{ + // }, + // ServerNames: []*armcosmosforpostgresql.ServerNameItem{ + // { + // Name: to.Ptr("testcluster1-c"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w0"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w0.postgres.database.azure.com"), + // }, + // { + // Name: to.Ptr("testcluster1-w1"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w1.postgres.database.azure.com"), + // }}, + // State: to.Ptr("Ready"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterRestart.json +func ExampleClustersClient_BeginRestart() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginRestart(ctx, "TestGroup", "testcluster1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterStart.json +func ExampleClustersClient_BeginStart() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginStart(ctx, "TestGroup", "testcluster1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterStop.json +func ExampleClustersClient_BeginStop() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginStop(ctx, "TestGroup", "testcluster1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ClusterPromoteReadReplica.json +func ExampleClustersClient_BeginPromoteReadReplica() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewClustersClient().BeginPromoteReadReplica(ctx, "TestGroup", "testcluster1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/CheckNameAvailability.json +func ExampleClustersClient_CheckNameAvailability() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewClustersClient().CheckNameAvailability(ctx, armcosmosforpostgresql.NameAvailabilityRequest{ + Name: to.Ptr("name1"), + Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.NameAvailability = armcosmosforpostgresql.NameAvailability{ + // Name: to.Ptr("name1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + // Message: to.Ptr(""), + // NameAvailable: to.Ptr(true), + // } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/configurations_client.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/configurations_client.go new file mode 100644 index 000000000000..3fec92a7da02 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/configurations_client.go @@ -0,0 +1,502 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "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 { + internal *arm.Client + subscriptionID string +} + +// NewConfigurationsClient creates a new instance of ConfigurationsClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewConfigurationsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ConfigurationsClient, error) { + cl, err := arm.NewClient(moduleName+".ConfigurationsClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &ConfigurationsClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// Get - Gets information of a configuration for coordinator and nodes. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - configurationName - The name of the cluster configuration. +// - options - ConfigurationsClientGetOptions contains the optional parameters for the ConfigurationsClient.Get method. +func (client *ConfigurationsClient) Get(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, options *ConfigurationsClientGetOptions) (ConfigurationsClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, clusterName, configurationName, options) + if err != nil { + return ConfigurationsClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ConfigurationsClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ConfigurationsClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ConfigurationsClient) getCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, options *ConfigurationsClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/configurations/{configurationName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ConfigurationsClient) getHandleResponse(resp *http.Response) (ConfigurationsClientGetResponse, error) { + result := ConfigurationsClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Configuration); err != nil { + return ConfigurationsClientGetResponse{}, err + } + return result, nil +} + +// GetCoordinator - Gets information of a configuration for coordinator. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - configurationName - The name of the cluster configuration. +// - options - ConfigurationsClientGetCoordinatorOptions contains the optional parameters for the ConfigurationsClient.GetCoordinator +// method. +func (client *ConfigurationsClient) GetCoordinator(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, options *ConfigurationsClientGetCoordinatorOptions) (ConfigurationsClientGetCoordinatorResponse, error) { + req, err := client.getCoordinatorCreateRequest(ctx, resourceGroupName, clusterName, configurationName, options) + if err != nil { + return ConfigurationsClientGetCoordinatorResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ConfigurationsClientGetCoordinatorResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ConfigurationsClientGetCoordinatorResponse{}, runtime.NewResponseError(resp) + } + return client.getCoordinatorHandleResponse(resp) +} + +// getCoordinatorCreateRequest creates the GetCoordinator request. +func (client *ConfigurationsClient) getCoordinatorCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, options *ConfigurationsClientGetCoordinatorOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getCoordinatorHandleResponse handles the GetCoordinator response. +func (client *ConfigurationsClient) getCoordinatorHandleResponse(resp *http.Response) (ConfigurationsClientGetCoordinatorResponse, error) { + result := ConfigurationsClientGetCoordinatorResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerConfiguration); err != nil { + return ConfigurationsClientGetCoordinatorResponse{}, err + } + return result, nil +} + +// GetNode - Gets information of a configuration for worker nodes. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - configurationName - The name of the cluster configuration. +// - options - ConfigurationsClientGetNodeOptions contains the optional parameters for the ConfigurationsClient.GetNode method. +func (client *ConfigurationsClient) GetNode(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, options *ConfigurationsClientGetNodeOptions) (ConfigurationsClientGetNodeResponse, error) { + req, err := client.getNodeCreateRequest(ctx, resourceGroupName, clusterName, configurationName, options) + if err != nil { + return ConfigurationsClientGetNodeResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ConfigurationsClientGetNodeResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ConfigurationsClientGetNodeResponse{}, runtime.NewResponseError(resp) + } + return client.getNodeHandleResponse(resp) +} + +// getNodeCreateRequest creates the GetNode request. +func (client *ConfigurationsClient) getNodeCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, options *ConfigurationsClientGetNodeOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/nodeConfigurations/{configurationName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getNodeHandleResponse handles the GetNode response. +func (client *ConfigurationsClient) getNodeHandleResponse(resp *http.Response) (ConfigurationsClientGetNodeResponse, error) { + result := ConfigurationsClientGetNodeResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerConfiguration); err != nil { + return ConfigurationsClientGetNodeResponse{}, err + } + return result, nil +} + +// NewListByClusterPager - List all the configurations of a cluster. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - ConfigurationsClientListByClusterOptions contains the optional parameters for the ConfigurationsClient.NewListByClusterPager +// method. +func (client *ConfigurationsClient) NewListByClusterPager(resourceGroupName string, clusterName string, options *ConfigurationsClientListByClusterOptions) *runtime.Pager[ConfigurationsClientListByClusterResponse] { + return runtime.NewPager(runtime.PagingHandler[ConfigurationsClientListByClusterResponse]{ + More: func(page ConfigurationsClientListByClusterResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *ConfigurationsClientListByClusterResponse) (ConfigurationsClientListByClusterResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listByClusterCreateRequest(ctx, resourceGroupName, clusterName, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return ConfigurationsClientListByClusterResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ConfigurationsClientListByClusterResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ConfigurationsClientListByClusterResponse{}, runtime.NewResponseError(resp) + } + return client.listByClusterHandleResponse(resp) + }, + }) +} + +// listByClusterCreateRequest creates the ListByCluster request. +func (client *ConfigurationsClient) listByClusterCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *ConfigurationsClientListByClusterOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/configurations" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByClusterHandleResponse handles the ListByCluster response. +func (client *ConfigurationsClient) listByClusterHandleResponse(resp *http.Response) (ConfigurationsClientListByClusterResponse, error) { + result := ConfigurationsClientListByClusterResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ClusterConfigurationListResult); err != nil { + return ConfigurationsClientListByClusterResponse{}, err + } + return result, nil +} + +// NewListByServerPager - List all the configurations of a server in cluster. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - serverName - The name of the server. +// - options - ConfigurationsClientListByServerOptions contains the optional parameters for the ConfigurationsClient.NewListByServerPager +// method. +func (client *ConfigurationsClient) NewListByServerPager(resourceGroupName string, clusterName string, serverName string, options *ConfigurationsClientListByServerOptions) *runtime.Pager[ConfigurationsClientListByServerResponse] { + return runtime.NewPager(runtime.PagingHandler[ConfigurationsClientListByServerResponse]{ + More: func(page ConfigurationsClientListByServerResponse) bool { + return page.NextLink != nil && len(*page.NextLink) > 0 + }, + Fetcher: func(ctx context.Context, page *ConfigurationsClientListByServerResponse) (ConfigurationsClientListByServerResponse, error) { + var req *policy.Request + var err error + if page == nil { + req, err = client.listByServerCreateRequest(ctx, resourceGroupName, clusterName, serverName, options) + } else { + req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink) + } + if err != nil { + return ConfigurationsClientListByServerResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ConfigurationsClientListByServerResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ConfigurationsClientListByServerResponse{}, runtime.NewResponseError(resp) + } + return client.listByServerHandleResponse(resp) + }, + }) +} + +// listByServerCreateRequest creates the ListByServer request. +func (client *ConfigurationsClient) listByServerCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, serverName string, options *ConfigurationsClientListByServerOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers/{serverName}/configurations" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByServerHandleResponse handles the ListByServer response. +func (client *ConfigurationsClient) listByServerHandleResponse(resp *http.Response) (ConfigurationsClientListByServerResponse, error) { + result := ConfigurationsClientListByServerResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerConfigurationListResult); err != nil { + return ConfigurationsClientListByServerResponse{}, err + } + return result, nil +} + +// BeginUpdateOnCoordinator - Updates configuration of coordinator in a cluster +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - configurationName - The name of the cluster configuration. +// - parameters - The required parameters for updating a cluster configuration. +// - options - ConfigurationsClientBeginUpdateOnCoordinatorOptions contains the optional parameters for the ConfigurationsClient.BeginUpdateOnCoordinator +// method. +func (client *ConfigurationsClient) BeginUpdateOnCoordinator(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, parameters ServerConfiguration, options *ConfigurationsClientBeginUpdateOnCoordinatorOptions) (*runtime.Poller[ConfigurationsClientUpdateOnCoordinatorResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.updateOnCoordinator(ctx, resourceGroupName, clusterName, configurationName, parameters, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConfigurationsClientUpdateOnCoordinatorResponse]{ + FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + }) + } else { + return runtime.NewPollerFromResumeToken[ConfigurationsClientUpdateOnCoordinatorResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// UpdateOnCoordinator - Updates configuration of coordinator in a cluster +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ConfigurationsClient) updateOnCoordinator(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, parameters ServerConfiguration, options *ConfigurationsClientBeginUpdateOnCoordinatorOptions) (*http.Response, error) { + req, err := client.updateOnCoordinatorCreateRequest(ctx, resourceGroupName, clusterName, configurationName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// updateOnCoordinatorCreateRequest creates the UpdateOnCoordinator request. +func (client *ConfigurationsClient) updateOnCoordinatorCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, parameters ServerConfiguration, options *ConfigurationsClientBeginUpdateOnCoordinatorOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// BeginUpdateOnNode - Updates configuration of worker nodes in a cluster +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - configurationName - The name of the cluster configuration. +// - parameters - The required parameters for updating a cluster configuration. +// - options - ConfigurationsClientBeginUpdateOnNodeOptions contains the optional parameters for the ConfigurationsClient.BeginUpdateOnNode +// method. +func (client *ConfigurationsClient) BeginUpdateOnNode(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, parameters ServerConfiguration, options *ConfigurationsClientBeginUpdateOnNodeOptions) (*runtime.Poller[ConfigurationsClientUpdateOnNodeResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.updateOnNode(ctx, resourceGroupName, clusterName, configurationName, parameters, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[ConfigurationsClientUpdateOnNodeResponse]{ + FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + }) + } else { + return runtime.NewPollerFromResumeToken[ConfigurationsClientUpdateOnNodeResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// UpdateOnNode - Updates configuration of worker nodes in a cluster +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *ConfigurationsClient) updateOnNode(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, parameters ServerConfiguration, options *ConfigurationsClientBeginUpdateOnNodeOptions) (*http.Response, error) { + req, err := client.updateOnNodeCreateRequest(ctx, resourceGroupName, clusterName, configurationName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// updateOnNodeCreateRequest creates the UpdateOnNode request. +func (client *ConfigurationsClient) updateOnNodeCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, configurationName string, parameters ServerConfiguration, options *ConfigurationsClientBeginUpdateOnNodeOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/nodeConfigurations/{configurationName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/configurations_client_example_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/configurations_client_example_test.go new file mode 100644 index 000000000000..59dcb7a95e6c --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/configurations_client_example_test.go @@ -0,0 +1,494 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ConfigurationListByServer.json +func ExampleConfigurationsClient_NewListByServerPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewConfigurationsClient().NewListByServerPager("TestResourceGroup", "testcluster", "testserver", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.ServerConfigurationListResult = armcosmosforpostgresql.ServerConfigurationListResult{ + // Value: []*armcosmosforpostgresql.ServerConfiguration{ + // { + // Name: to.Ptr("application_name"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers/configurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/servers/testserver/configurations/application_name"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + // Description: to.Ptr("Sets the application name to be reported in statistics and logs."), + // AllowedValues: to.Ptr("[A-Za-z0-9._-]*"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataType("String")), + // DefaultValue: to.Ptr(""), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // Source: to.Ptr("system-default"), + // Value: to.Ptr(""), + // }, + // }, + // { + // Name: to.Ptr("array_nulls"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers/configurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/servers/testserver/configurations/array_nulls"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + // Description: to.Ptr("Enables input of NULL elements in arrays."), + // AllowedValues: to.Ptr("on,off"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeBoolean), + // DefaultValue: to.Ptr("on"), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // Source: to.Ptr("system-default"), + // Value: to.Ptr("on"), + // }, + // }, + // { + // Name: to.Ptr("autovacuum"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers/configurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/servers/testserver/configurations/autovacuum"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + // Description: to.Ptr("Starts the autovacuum subprocess."), + // AllowedValues: to.Ptr("on,off"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeBoolean), + // DefaultValue: to.Ptr("on"), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // Source: to.Ptr("system-default"), + // Value: to.Ptr("on"), + // }, + // }}, + // } + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ConfigurationListByCluster.json +func ExampleConfigurationsClient_NewListByClusterPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewConfigurationsClient().NewListByClusterPager("TestResourceGroup", "testcluster", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.ClusterConfigurationListResult = armcosmosforpostgresql.ClusterConfigurationListResult{ + // Value: []*armcosmosforpostgresql.Configuration{ + // { + // Name: to.Ptr("array_nulls"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/array_nulls"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ConfigurationProperties{ + // Description: to.Ptr("Enable input of NULL elements in arrays."), + // AllowedValues: to.Ptr("on,off"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeBoolean), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // ServerRoleGroupConfigurations: []*armcosmosforpostgresql.ServerRoleGroupConfiguration{ + // { + // DefaultValue: to.Ptr("on"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleCoordinator), + // Source: to.Ptr("system-default"), + // Value: to.Ptr("on"), + // }, + // { + // DefaultValue: to.Ptr("on"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleWorker), + // Source: to.Ptr("user-override"), + // Value: to.Ptr("off"), + // }}, + // }, + // }, + // { + // Name: to.Ptr("backslash_quote"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/backslash_quote"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ConfigurationProperties{ + // Description: to.Ptr("Sets whether \"\\'\" is allowed in string literals."), + // AllowedValues: to.Ptr("safe_encoding,on,off"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeEnumeration), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // ServerRoleGroupConfigurations: []*armcosmosforpostgresql.ServerRoleGroupConfiguration{ + // { + // DefaultValue: to.Ptr("safe_encoding"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleCoordinator), + // Source: to.Ptr("user-override"), + // Value: to.Ptr("off"), + // }, + // { + // DefaultValue: to.Ptr("safe_encoding"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleWorker), + // Source: to.Ptr("system-default"), + // Value: to.Ptr("safe_encoding"), + // }}, + // }, + // }, + // { + // Name: to.Ptr("work_mem"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/work_mem"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ConfigurationProperties{ + // Description: to.Ptr("Sets the amount of memory to be used by internal sort operations and hash tables before writing to temporary disk files."), + // AllowedValues: to.Ptr("4096-2097151"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeInteger), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // ServerRoleGroupConfigurations: []*armcosmosforpostgresql.ServerRoleGroupConfiguration{ + // { + // DefaultValue: to.Ptr("158720"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleCoordinator), + // Source: to.Ptr("system-default"), + // Value: to.Ptr("158720"), + // }, + // { + // DefaultValue: to.Ptr("115712"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleWorker), + // Source: to.Ptr("system-default"), + // Value: to.Ptr("115712"), + // }}, + // }, + // }, + // { + // Name: to.Ptr("client_encoding"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/client_encoding"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ConfigurationProperties{ + // Description: to.Ptr("Sets the client's character set encoding."), + // AllowedValues: to.Ptr("BIG5,EUC_CN,EUC_JP,EUC_JIS_2004,EUC_KR,EUC_TW,GB18030,GBK,ISO_8859_5,ISO_8859_6,ISO_8859_7,ISO_8859_8,JOHAB,KOI8R,KOI8U,LATIN1,LATIN2,LATIN3,LATIN4,LATIN5,LATIN6,LATIN7,LATIN8,LATIN9,LATIN10,MULE_INTERNAL,SJIS,SHIFT_JIS_2004,SQL_ASCII,UHC,UTF8,WIN866,WIN874,WIN1250,WIN1251,WIN1252,WIN1253,WIN1254,WIN1255,WIN1256,WIN1257,WIN1258"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeEnumeration), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // ServerRoleGroupConfigurations: []*armcosmosforpostgresql.ServerRoleGroupConfiguration{ + // { + // DefaultValue: to.Ptr("sql_ascii"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleCoordinator), + // Source: to.Ptr("user-override"), + // Value: to.Ptr("ISO_8859_7"), + // }, + // { + // DefaultValue: to.Ptr("sql_ascii"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleWorker), + // Source: to.Ptr("user-override"), + // Value: to.Ptr("ISO_8859_7"), + // }}, + // }, + // }}, + // } + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ConfigurationGet.json +func ExampleConfigurationsClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewConfigurationsClient().Get(ctx, "TestResourceGroup", "testcluster", "client_encoding", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Configuration = armcosmosforpostgresql.Configuration{ + // Name: to.Ptr("client_encoding"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/client_encoding"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ConfigurationProperties{ + // Description: to.Ptr("Sets the client's character set encoding."), + // AllowedValues: to.Ptr("BIG5,EUC_CN,EUC_JP,EUC_JIS_2004,EUC_KR,EUC_TW,GB18030,GBK,ISO_8859_5,ISO_8859_6,ISO_8859_7,ISO_8859_8,JOHAB,KOI8R,KOI8U,LATIN1,LATIN2,LATIN3,LATIN4,LATIN5,LATIN6,LATIN7,LATIN8,LATIN9,LATIN10,MULE_INTERNAL,SJIS,SHIFT_JIS_2004,SQL_ASCII,UHC,UTF8,WIN866,WIN874,WIN1250,WIN1251,WIN1252,WIN1253,WIN1254,WIN1255,WIN1256,WIN1257,WIN1258"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeEnumeration), + // ServerRoleGroupConfigurations: []*armcosmosforpostgresql.ServerRoleGroupConfiguration{ + // { + // DefaultValue: to.Ptr("sql_ascii"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleCoordinator), + // Source: to.Ptr("user-override"), + // Value: to.Ptr("ISO_8859_7"), + // }, + // { + // DefaultValue: to.Ptr("sql_ascii"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleWorker), + // Source: to.Ptr("user-override"), + // Value: to.Ptr("ISO_8859_7"), + // }}, + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ConfigurationGetCoordinator.json +func ExampleConfigurationsClient_GetCoordinator() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewConfigurationsClient().GetCoordinator(ctx, "TestResourceGroup", "testcluster", "array_nulls", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.ServerConfiguration = armcosmosforpostgresql.ServerConfiguration{ + // Name: to.Ptr("array_nulls"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/coordinatorConfigurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/coordinatorConfigurations/array_nulls"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + // Value: to.Ptr("on"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ConfigurationUpdateCoordinator.json +func ExampleConfigurationsClient_BeginUpdateOnCoordinator() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewConfigurationsClient().BeginUpdateOnCoordinator(ctx, "TestResourceGroup", "testcluster", "array_nulls", armcosmosforpostgresql.ServerConfiguration{ + Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + Value: to.Ptr("on"), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.ServerConfiguration = armcosmosforpostgresql.ServerConfiguration{ + // Name: to.Ptr("array_nulls"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations/coordinator"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/array_nulls"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + // Description: to.Ptr("Enables input of NULL elements in arrays."), + // AllowedValues: to.Ptr("on,off"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeBoolean), + // DefaultValue: to.Ptr("on"), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // RequiresRestart: to.Ptr(false), + // Source: to.Ptr("user-override"), + // Value: to.Ptr("on"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ConfigurationGetNode.json +func ExampleConfigurationsClient_GetNode() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewConfigurationsClient().GetNode(ctx, "TestResourceGroup", "testcluster", "array_nulls", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.ServerConfiguration = armcosmosforpostgresql.ServerConfiguration{ + // Name: to.Ptr("array_nulls"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/nodeConfigurations"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/nodeConfigurations/array_nulls"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + // Value: to.Ptr("off"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ConfigurationUpdateNode.json +func ExampleConfigurationsClient_BeginUpdateOnNode() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewConfigurationsClient().BeginUpdateOnNode(ctx, "TestResourceGroup", "testcluster", "array_nulls", armcosmosforpostgresql.ServerConfiguration{ + Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + Value: to.Ptr("off"), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.ServerConfiguration = armcosmosforpostgresql.ServerConfiguration{ + // Name: to.Ptr("array_nulls"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations/node"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/configurations/array_nulls"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + // Description: to.Ptr("Enables input of NULL elements in arrays."), + // AllowedValues: to.Ptr("on,off"), + // DataType: to.Ptr(armcosmosforpostgresql.ConfigurationDataTypeBoolean), + // DefaultValue: to.Ptr("on"), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // RequiresRestart: to.Ptr(false), + // Source: to.Ptr("user-override"), + // Value: to.Ptr("off"), + // }, + // } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/constants.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/constants.go new file mode 100644 index 000000000000..cc0349e6099b --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/constants.go @@ -0,0 +1,147 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +const ( + moduleName = "armcosmosforpostgresql" + moduleVersion = "v1.0.0" +) + +// 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, + } +} + +// 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, + } +} + +// 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, + } +} + +// PrivateEndpointConnectionProvisioningState - The current provisioning state. +type PrivateEndpointConnectionProvisioningState string + +const ( + PrivateEndpointConnectionProvisioningStateCreating PrivateEndpointConnectionProvisioningState = "Creating" + PrivateEndpointConnectionProvisioningStateDeleting PrivateEndpointConnectionProvisioningState = "Deleting" + PrivateEndpointConnectionProvisioningStateFailed PrivateEndpointConnectionProvisioningState = "Failed" + PrivateEndpointConnectionProvisioningStateSucceeded PrivateEndpointConnectionProvisioningState = "Succeeded" +) + +// PossiblePrivateEndpointConnectionProvisioningStateValues returns the possible values for the PrivateEndpointConnectionProvisioningState const type. +func PossiblePrivateEndpointConnectionProvisioningStateValues() []PrivateEndpointConnectionProvisioningState { + return []PrivateEndpointConnectionProvisioningState{ + PrivateEndpointConnectionProvisioningStateCreating, + PrivateEndpointConnectionProvisioningStateDeleting, + PrivateEndpointConnectionProvisioningStateFailed, + PrivateEndpointConnectionProvisioningStateSucceeded, + } +} + +// PrivateEndpointServiceConnectionStatus - The private endpoint connection status. +type PrivateEndpointServiceConnectionStatus string + +const ( + PrivateEndpointServiceConnectionStatusApproved PrivateEndpointServiceConnectionStatus = "Approved" + PrivateEndpointServiceConnectionStatusPending PrivateEndpointServiceConnectionStatus = "Pending" + PrivateEndpointServiceConnectionStatusRejected PrivateEndpointServiceConnectionStatus = "Rejected" +) + +// PossiblePrivateEndpointServiceConnectionStatusValues returns the possible values for the PrivateEndpointServiceConnectionStatus const type. +func PossiblePrivateEndpointServiceConnectionStatusValues() []PrivateEndpointServiceConnectionStatus { + return []PrivateEndpointServiceConnectionStatus{ + PrivateEndpointServiceConnectionStatusApproved, + PrivateEndpointServiceConnectionStatusPending, + PrivateEndpointServiceConnectionStatusRejected, + } +} + +// ProvisioningState - The current provisioning state. +type ProvisioningState string + +const ( + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateInProgress ProvisioningState = "InProgress" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" +) + +// PossibleProvisioningStateValues returns the possible values for the ProvisioningState const type. +func PossibleProvisioningStateValues() []ProvisioningState { + return []ProvisioningState{ + ProvisioningStateCanceled, + ProvisioningStateFailed, + ProvisioningStateInProgress, + ProvisioningStateSucceeded, + } +} + +// 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, + } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/firewallrules_client.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/firewallrules_client.go new file mode 100644 index 000000000000..a8dea1765ae0 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/firewallrules_client.go @@ -0,0 +1,304 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "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 { + internal *arm.Client + subscriptionID string +} + +// NewFirewallRulesClient creates a new instance of FirewallRulesClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewFirewallRulesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*FirewallRulesClient, error) { + cl, err := arm.NewClient(moduleName+".FirewallRulesClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &FirewallRulesClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// BeginCreateOrUpdate - Creates a new cluster firewall rule or updates an existing cluster firewall rule. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - firewallRuleName - The name of the cluster firewall rule. +// - parameters - The required parameters for creating or updating a firewall rule. +// - options - FirewallRulesClientBeginCreateOrUpdateOptions contains the optional parameters for the FirewallRulesClient.BeginCreateOrUpdate +// method. +func (client *FirewallRulesClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, clusterName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesClientBeginCreateOrUpdateOptions) (*runtime.Poller[FirewallRulesClientCreateOrUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.createOrUpdate(ctx, resourceGroupName, clusterName, firewallRuleName, parameters, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallRulesClientCreateOrUpdateResponse]{ + FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + }) + } else { + return runtime.NewPollerFromResumeToken[FirewallRulesClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// CreateOrUpdate - Creates a new cluster firewall rule or updates an existing cluster firewall rule. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *FirewallRulesClient) createOrUpdate(ctx context.Context, resourceGroupName string, clusterName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesClientBeginCreateOrUpdateOptions) (*http.Response, error) { + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, clusterName, firewallRuleName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *FirewallRulesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesClientBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// BeginDelete - Deletes a cluster firewall rule. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - firewallRuleName - The name of the cluster firewall rule. +// - options - FirewallRulesClientBeginDeleteOptions contains the optional parameters for the FirewallRulesClient.BeginDelete +// method. +func (client *FirewallRulesClient) BeginDelete(ctx context.Context, resourceGroupName string, clusterName string, firewallRuleName string, options *FirewallRulesClientBeginDeleteOptions) (*runtime.Poller[FirewallRulesClientDeleteResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.deleteOperation(ctx, resourceGroupName, clusterName, firewallRuleName, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[FirewallRulesClientDeleteResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[FirewallRulesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Delete - Deletes a cluster firewall rule. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *FirewallRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, clusterName string, firewallRuleName string, options *FirewallRulesClientBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, clusterName, firewallRuleName, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *FirewallRulesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, firewallRuleName string, options *FirewallRulesClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - Gets information about a cluster firewall rule. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - firewallRuleName - The name of the cluster firewall rule. +// - options - FirewallRulesClientGetOptions contains the optional parameters for the FirewallRulesClient.Get method. +func (client *FirewallRulesClient) Get(ctx context.Context, resourceGroupName string, clusterName string, firewallRuleName string, options *FirewallRulesClientGetOptions) (FirewallRulesClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, clusterName, firewallRuleName, options) + if err != nil { + return FirewallRulesClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return FirewallRulesClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return FirewallRulesClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *FirewallRulesClient) getCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, firewallRuleName string, options *FirewallRulesClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *FirewallRulesClient) getHandleResponse(resp *http.Response) (FirewallRulesClientGetResponse, error) { + result := FirewallRulesClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.FirewallRule); err != nil { + return FirewallRulesClientGetResponse{}, err + } + return result, nil +} + +// NewListByClusterPager - Lists all the firewall rules on cluster. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - FirewallRulesClientListByClusterOptions contains the optional parameters for the FirewallRulesClient.NewListByClusterPager +// method. +func (client *FirewallRulesClient) NewListByClusterPager(resourceGroupName string, clusterName string, options *FirewallRulesClientListByClusterOptions) *runtime.Pager[FirewallRulesClientListByClusterResponse] { + return runtime.NewPager(runtime.PagingHandler[FirewallRulesClientListByClusterResponse]{ + More: func(page FirewallRulesClientListByClusterResponse) bool { + return false + }, + Fetcher: func(ctx context.Context, page *FirewallRulesClientListByClusterResponse) (FirewallRulesClientListByClusterResponse, error) { + req, err := client.listByClusterCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return FirewallRulesClientListByClusterResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return FirewallRulesClientListByClusterResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return FirewallRulesClientListByClusterResponse{}, runtime.NewResponseError(resp) + } + return client.listByClusterHandleResponse(resp) + }, + }) +} + +// listByClusterCreateRequest creates the ListByCluster request. +func (client *FirewallRulesClient) listByClusterCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *FirewallRulesClientListByClusterOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByClusterHandleResponse handles the ListByCluster response. +func (client *FirewallRulesClient) listByClusterHandleResponse(resp *http.Response) (FirewallRulesClientListByClusterResponse, error) { + result := FirewallRulesClientListByClusterResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.FirewallRuleListResult); err != nil { + return FirewallRulesClientListByClusterResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/firewallrules_client_example_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/firewallrules_client_example_test.go new file mode 100644 index 000000000000..2ea49b21a4d9 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/firewallrules_client_example_test.go @@ -0,0 +1,189 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/FirewallRuleCreate.json +func ExampleFirewallRulesClient_BeginCreateOrUpdate() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewFirewallRulesClient().BeginCreateOrUpdate(ctx, "TestGroup", "pgtestsvc4", "rule1", armcosmosforpostgresql.FirewallRule{ + Properties: &armcosmosforpostgresql.FirewallRuleProperties{ + EndIPAddress: to.Ptr("255.255.255.255"), + StartIPAddress: to.Ptr("0.0.0.0"), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.FirewallRule = armcosmosforpostgresql.FirewallRule{ + // Name: to.Ptr("rule1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/firewallRules"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/firewallRules/rule1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.FirewallRuleProperties{ + // EndIPAddress: to.Ptr("255.255.255.255"), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // StartIPAddress: to.Ptr("0.0.0.0"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/FirewallRuleDelete.json +func ExampleFirewallRulesClient_BeginDelete() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewFirewallRulesClient().BeginDelete(ctx, "TestGroup", "pgtestsvc4", "rule1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/FirewallRuleGet.json +func ExampleFirewallRulesClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewFirewallRulesClient().Get(ctx, "TestGroup", "pgtestsvc4", "rule1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.FirewallRule = armcosmosforpostgresql.FirewallRule{ + // Name: to.Ptr("rule1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/firewallRules"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/firewallRules/rule1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.FirewallRuleProperties{ + // EndIPAddress: to.Ptr("255.255.255.255"), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // StartIPAddress: to.Ptr("0.0.0.0"), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/FirewallRuleListByCluster.json +func ExampleFirewallRulesClient_NewListByClusterPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewFirewallRulesClient().NewListByClusterPager("TestGroup", "pgtestsvc4", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.FirewallRuleListResult = armcosmosforpostgresql.FirewallRuleListResult{ + // Value: []*armcosmosforpostgresql.FirewallRule{ + // { + // Name: to.Ptr("rule1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/firewallRules"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/firewallRules/rule1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.FirewallRuleProperties{ + // EndIPAddress: to.Ptr("255.255.255.255"), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // StartIPAddress: to.Ptr("0.0.0.0"), + // }, + // }, + // { + // Name: to.Ptr("rule2"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/firewallRules"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/firewallRules/rule2"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.FirewallRuleProperties{ + // EndIPAddress: to.Ptr("255.0.0.0"), + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // StartIPAddress: to.Ptr("1.0.0.0"), + // }, + // }}, + // } + } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.mod b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.mod new file mode 100644 index 000000000000..d19c72cf3eb4 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.mod @@ -0,0 +1,21 @@ +module github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql + +go 1.18 + +require ( + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 +) + +require ( + github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect + golang.org/x/crypto v0.7.0 // indirect + golang.org/x/net v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect +) diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.sum b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.sum new file mode 100644 index 000000000000..21718b486698 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.sum @@ -0,0 +1,31 @@ +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 h1:8kDqDngH+DmVBiCtIjCFTGa7MBnsIOkF9IccInFEbjk= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybIsqD8sMV8js0NyQM8JDnVtg= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= +github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY= +github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= +github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/models.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/models.go new file mode 100644 index 000000000000..42f0aadcf72c --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/models.go @@ -0,0 +1,896 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import "time" + +// Cluster - Represents a cluster. +type Cluster struct { + // REQUIRED; The geo-location where the resource lives + Location *string + + // Properties of the cluster. + Properties *ClusterProperties + + // Resource tags. + Tags map[string]*string + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// ClusterConfigurationListResult - A list of cluster configurations. +type ClusterConfigurationListResult struct { + // The list of cluster configurations. + Value []*Configuration + + // READ-ONLY; Link to retrieve next page of results. + NextLink *string +} + +// ClusterForUpdate - Represents a cluster for update. +type ClusterForUpdate struct { + // Properties of the cluster. + Properties *ClusterPropertiesForUpdate + + // Application-specific metadata in the form of key-value pairs. + Tags map[string]*string +} + +// ClusterListResult - A list of clusters. +type ClusterListResult struct { + // The list of clusters + Value []*Cluster + + // READ-ONLY; The link used to get the next page of cluster list. + NextLink *string +} + +// ClusterProperties - Properties of the cluster. +type ClusterProperties struct { + // The password of the administrator login. Required for creation. + AdministratorLoginPassword *string + + // The Citus extension version on all cluster servers. + CitusVersion *string + + // If public access is enabled on coordinator. + CoordinatorEnablePublicIPAccess *bool + + // The edition of a coordinator server (default: GeneralPurpose). Required for creation. + CoordinatorServerEdition *string + + // The storage of a server in MB. Required for creation. See https://learn.microsoft.com/azure/cosmos-db/postgresql/resources-compute + // for more information. + CoordinatorStorageQuotaInMb *int32 + + // The vCores count of a server (max: 96). Required for creation. See https://learn.microsoft.com/azure/cosmos-db/postgresql/resources-compute + // for more information. + CoordinatorVCores *int32 + + // If high availability (HA) is enabled or not for the cluster. + EnableHa *bool + + // If shards on coordinator is enabled or not for the cluster. + EnableShardsOnCoordinator *bool + + // Maintenance window of a cluster. + MaintenanceWindow *MaintenanceWindow + + // Worker node count of the cluster. When node count is 0, it represents a single node configuration with the ability to create + // distributed tables on that node. 2 or more worker nodes represent + // multi-node configuration. Node count value cannot be 1. Required for creation. + NodeCount *int32 + + // If public access is enabled on worker nodes. + NodeEnablePublicIPAccess *bool + + // The edition of a node server (default: MemoryOptimized). + NodeServerEdition *string + + // The storage in MB on each worker node. See https://learn.microsoft.com/azure/cosmos-db/postgresql/resources-compute for + // more information. + NodeStorageQuotaInMb *int32 + + // The compute in vCores on each worker node (max: 104). See https://learn.microsoft.com/azure/cosmos-db/postgresql/resources-compute + // for more information. + NodeVCores *int32 + + // Date and time in UTC (ISO8601 format) for cluster restore. + PointInTimeUTC *time.Time + + // The major PostgreSQL version on all cluster servers. + PostgresqlVersion *string + + // Preferred primary availability zone (AZ) for all cluster servers. + PreferredPrimaryZone *string + + // The Azure region of source cluster for read replica clusters. + SourceLocation *string + + // The resource id of source cluster for read replica clusters. + SourceResourceID *string + + // READ-ONLY; The administrator's login name of the servers in the cluster. + AdministratorLogin *string + + // READ-ONLY; The earliest restore point time (ISO8601 format) for the cluster. + EarliestRestoreTime *time.Time + + // READ-ONLY; The private endpoint connections for a cluster. + PrivateEndpointConnections []*SimplePrivateEndpointConnection + + // READ-ONLY; Provisioning state of the cluster + ProvisioningState *string + + // READ-ONLY; The array of read replica clusters. + ReadReplicas []*string + + // READ-ONLY; The list of server names in the cluster + ServerNames []*ServerNameItem + + // READ-ONLY; A state of a cluster/server that is visible to user. + State *string +} + +// ClusterPropertiesForUpdate - The properties used to update a cluster. +type ClusterPropertiesForUpdate struct { + // The password of the administrator login. Each cluster is created with pre-defined administrative role called ‘citus’. + AdministratorLoginPassword *string + + // The Citus extension version on all cluster servers. + CitusVersion *string + + // If public access is enabled on coordinator. + CoordinatorEnablePublicIPAccess *bool + + // The edition of the coordinator (default: GeneralPurpose). + CoordinatorServerEdition *string + + // The storage of the coordinator in MB. + CoordinatorStorageQuotaInMb *int32 + + // The vCores count of the coordinator (max: 96). + CoordinatorVCores *int32 + + // If high availability (HA) is enabled or not for the cluster. + EnableHa *bool + + // If shards on coordinator is enabled or not for the cluster. + EnableShardsOnCoordinator *bool + + // Maintenance window of a cluster. + MaintenanceWindow *MaintenanceWindow + + // Worker node count of the cluster. When node count is 0, it represents a single node configuration with the ability to create + // distributed tables on that node. 2 or more worker nodes represent + // multi-node configuration. Node count value cannot be 1. + NodeCount *int32 + + // The edition of a node (default: MemoryOptimized). + NodeServerEdition *string + + // The storage in MB on each worker node. + NodeStorageQuotaInMb *int32 + + // The compute in vCores on each worker node (max: 104). + NodeVCores *int32 + + // The major PostgreSQL version on all cluster servers. + PostgresqlVersion *string + + // Preferred primary availability zone (AZ) for all cluster servers. + PreferredPrimaryZone *string + + // READ-ONLY; If public access is enabled on worker nodes. + NodeEnablePublicIPAccess *bool +} + +// ClusterServer - Represents a server in a cluster. +type ClusterServer struct { + // The properties of a server in a cluster. + Properties *ClusterServerProperties + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// ClusterServerListResult - A list of servers in a cluster. +type ClusterServerListResult struct { + // The list of servers in a cluster. + Value []*ClusterServer +} + +// ClusterServerProperties - The properties of a server in cluster. +type ClusterServerProperties struct { + // Availability Zone information of the server. + AvailabilityZone *string + + // The Citus extension version of server. + CitusVersion *string + + // If high availability (HA) is enabled or not for the server. + EnableHa *bool + + // The major PostgreSQL version of server. + PostgresqlVersion *string + + // The role of server in the cluster. + Role *ServerRole + + // The edition of a server. + ServerEdition *string + + // The storage of a server in MB. + StorageQuotaInMb *int32 + + // The vCores count of a server. + VCores *int32 + + // READ-ONLY; The administrator's login name of the servers in the cluster. + AdministratorLogin *string + + // READ-ONLY; If public access is enabled on server. + EnablePublicIPAccess *bool + + // READ-ONLY; The fully qualified domain name of a server. + FullyQualifiedDomainName *string + + // READ-ONLY; A state of HA feature for the cluster. + HaState *string + + // READ-ONLY; If server database is set to read-only by system maintenance depending on high disk space usage. + IsReadOnly *bool + + // READ-ONLY; A state of a cluster/server that is visible to user. + State *string +} + +// ClustersClientBeginCreateOptions contains the optional parameters for the ClustersClient.BeginCreate method. +type ClustersClientBeginCreateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ClustersClientBeginDeleteOptions contains the optional parameters for the ClustersClient.BeginDelete method. +type ClustersClientBeginDeleteOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ClustersClientBeginPromoteReadReplicaOptions contains the optional parameters for the ClustersClient.BeginPromoteReadReplica +// method. +type ClustersClientBeginPromoteReadReplicaOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ClustersClientBeginRestartOptions contains the optional parameters for the ClustersClient.BeginRestart method. +type ClustersClientBeginRestartOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ClustersClientBeginStartOptions contains the optional parameters for the ClustersClient.BeginStart method. +type ClustersClientBeginStartOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ClustersClientBeginStopOptions contains the optional parameters for the ClustersClient.BeginStop method. +type ClustersClientBeginStopOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ClustersClientBeginUpdateOptions contains the optional parameters for the ClustersClient.BeginUpdate method. +type ClustersClientBeginUpdateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ClustersClientCheckNameAvailabilityOptions contains the optional parameters for the ClustersClient.CheckNameAvailability +// method. +type ClustersClientCheckNameAvailabilityOptions struct { + // placeholder for future optional parameters +} + +// ClustersClientGetOptions contains the optional parameters for the ClustersClient.Get method. +type ClustersClientGetOptions struct { + // placeholder for future optional parameters +} + +// ClustersClientListByResourceGroupOptions contains the optional parameters for the ClustersClient.NewListByResourceGroupPager +// method. +type ClustersClientListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// ClustersClientListOptions contains the optional parameters for the ClustersClient.NewListPager method. +type ClustersClientListOptions struct { + // placeholder for future optional parameters +} + +// Configuration - Represents configuration details for coordinator and node. +type Configuration struct { + // The properties of configuration. + Properties *ConfigurationProperties + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// ConfigurationProperties - The properties of configuration. +type ConfigurationProperties struct { + // REQUIRED; The list of server role group configuration values. + ServerRoleGroupConfigurations []*ServerRoleGroupConfiguration + + // If configuration change requires restart. + RequiresRestart *bool + + // READ-ONLY; Allowed values of the configuration. + AllowedValues *string + + // READ-ONLY; Data type of the configuration. + DataType *ConfigurationDataType + + // READ-ONLY; Description of the configuration. + Description *string + + // READ-ONLY; Provisioning state of the configuration + ProvisioningState *ProvisioningState +} + +// ConfigurationsClientBeginUpdateOnCoordinatorOptions contains the optional parameters for the ConfigurationsClient.BeginUpdateOnCoordinator +// method. +type ConfigurationsClientBeginUpdateOnCoordinatorOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ConfigurationsClientBeginUpdateOnNodeOptions contains the optional parameters for the ConfigurationsClient.BeginUpdateOnNode +// method. +type ConfigurationsClientBeginUpdateOnNodeOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// ConfigurationsClientGetCoordinatorOptions contains the optional parameters for the ConfigurationsClient.GetCoordinator +// method. +type ConfigurationsClientGetCoordinatorOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsClientGetNodeOptions contains the optional parameters for the ConfigurationsClient.GetNode method. +type ConfigurationsClientGetNodeOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsClientGetOptions contains the optional parameters for the ConfigurationsClient.Get method. +type ConfigurationsClientGetOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsClientListByClusterOptions contains the optional parameters for the ConfigurationsClient.NewListByClusterPager +// method. +type ConfigurationsClientListByClusterOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsClientListByServerOptions contains the optional parameters for the ConfigurationsClient.NewListByServerPager +// method. +type ConfigurationsClientListByServerOptions struct { + // placeholder for future optional parameters +} + +// FirewallRule - Represents a cluster firewall rule. +type FirewallRule struct { + // REQUIRED; The properties of a firewall rule. + Properties *FirewallRuleProperties + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// FirewallRuleListResult - A list of firewall rules. +type FirewallRuleListResult struct { + // The list of firewall rules in a cluster. + Value []*FirewallRule +} + +// FirewallRuleProperties - The properties of a cluster firewall rule. +type FirewallRuleProperties struct { + // REQUIRED; The end IP address of the cluster firewall rule. Must be IPv4 format. + EndIPAddress *string + + // REQUIRED; The start IP address of the cluster firewall rule. Must be IPv4 format. + StartIPAddress *string + + // READ-ONLY; Provisioning state of the firewall rule. + ProvisioningState *ProvisioningState +} + +// FirewallRulesClientBeginCreateOrUpdateOptions contains the optional parameters for the FirewallRulesClient.BeginCreateOrUpdate +// method. +type FirewallRulesClientBeginCreateOrUpdateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// FirewallRulesClientBeginDeleteOptions contains the optional parameters for the FirewallRulesClient.BeginDelete method. +type FirewallRulesClientBeginDeleteOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// FirewallRulesClientGetOptions contains the optional parameters for the FirewallRulesClient.Get method. +type FirewallRulesClientGetOptions struct { + // placeholder for future optional parameters +} + +// FirewallRulesClientListByClusterOptions contains the optional parameters for the FirewallRulesClient.NewListByClusterPager +// method. +type FirewallRulesClientListByClusterOptions struct { + // placeholder for future optional parameters +} + +// MaintenanceWindow - Schedule settings for regular cluster updates. +type MaintenanceWindow struct { + // Indicates whether custom maintenance window is enabled or not. + CustomWindow *string + + // Preferred day of the week for maintenance window. + DayOfWeek *int32 + + // Start hour within preferred day of the week for maintenance window. + StartHour *int32 + + // Start minute within the start hour for maintenance window. + StartMinute *int32 +} + +// NameAvailability - Represents cluster name availability. +type NameAvailability struct { + // Error message. + Message *string + + // Name of the cluster. + Name *string + + // Indicates whether the cluster name is available. + NameAvailable *bool + + // Type of the cluster. + Type *string +} + +// NameAvailabilityRequest - Request from client to check cluster name availability. +type NameAvailabilityRequest struct { + // REQUIRED; Cluster name to verify. + Name *string + + // CONSTANT; Resource type used for verification. + // Field has constant value "Microsoft.DBforPostgreSQL/serverGroupsv2", any specified value is ignored. + Type *string +} + +// Operation - REST API operation definition. +type Operation struct { + // Indicates whether the operation is a data action. + IsDataAction *bool + + // READ-ONLY; The localized display information for this particular operation or action. + Display *OperationDisplay + + // READ-ONLY; The name of the operation being performed on this particular object. + Name *string + + // READ-ONLY; The intended executor of the operation. + Origin *OperationOrigin + + // READ-ONLY; Additional descriptions for the operation. + Properties map[string]any +} + +// OperationDisplay - Display metadata associated with the operation. +type OperationDisplay struct { + // READ-ONLY; Operation description. + Description *string + + // READ-ONLY; Localized friendly name for the operation. + Operation *string + + // READ-ONLY; Operation resource provider name. + Provider *string + + // READ-ONLY; Resource on which the operation is performed. + Resource *string +} + +// OperationListResult - A list of resource provider operations. +type OperationListResult struct { + // Collection of available operation details. + Value []*Operation + + // 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 +} + +// OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +type OperationsClientListOptions struct { + // placeholder for future optional parameters +} + +// PrivateEndpoint - The private endpoint resource. +type PrivateEndpoint struct { + // READ-ONLY; The ARM identifier for private endpoint. + ID *string +} + +// PrivateEndpointConnection - The private endpoint connection resource. +type PrivateEndpointConnection struct { + // Resource properties. + Properties *PrivateEndpointConnectionProperties + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// PrivateEndpointConnectionListResult - List of private endpoint connections associated with the specified resource. +type PrivateEndpointConnectionListResult struct { + // Array of private endpoint connections. + Value []*PrivateEndpointConnection +} + +// PrivateEndpointConnectionProperties - Properties of the private endpoint connection. +type PrivateEndpointConnectionProperties struct { + // REQUIRED; A collection of information about the state of the connection between service consumer and provider. + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState + + // The private endpoint resource. + PrivateEndpoint *PrivateEndpoint + + // READ-ONLY; The group ids for the private endpoint resource. + GroupIDs []*string + + // READ-ONLY; The provisioning state of the private endpoint connection resource. + ProvisioningState *PrivateEndpointConnectionProvisioningState +} + +// PrivateEndpointConnectionSimpleProperties - The properties in private endpoint connection +type PrivateEndpointConnectionSimpleProperties struct { + // Group ids of the private endpoint connection. + GroupIDs []*string + + // Private endpoint which the connection belongs to. + PrivateEndpoint *PrivateEndpointProperty + + // A collection of information about the state of the connection between service consumer and provider. + PrivateLinkServiceConnectionState *PrivateLinkServiceConnectionState +} + +// PrivateEndpointConnectionsClientBeginCreateOrUpdateOptions contains the optional parameters for the PrivateEndpointConnectionsClient.BeginCreateOrUpdate +// method. +type PrivateEndpointConnectionsClientBeginCreateOrUpdateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// PrivateEndpointConnectionsClientBeginDeleteOptions contains the optional parameters for the PrivateEndpointConnectionsClient.BeginDelete +// method. +type PrivateEndpointConnectionsClientBeginDeleteOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// PrivateEndpointConnectionsClientGetOptions contains the optional parameters for the PrivateEndpointConnectionsClient.Get +// method. +type PrivateEndpointConnectionsClientGetOptions struct { + // placeholder for future optional parameters +} + +// PrivateEndpointConnectionsClientListByClusterOptions contains the optional parameters for the PrivateEndpointConnectionsClient.NewListByClusterPager +// method. +type PrivateEndpointConnectionsClientListByClusterOptions struct { + // placeholder for future optional parameters +} + +// PrivateEndpointProperty - Property to represent resource id of the private endpoint. +type PrivateEndpointProperty struct { + // Resource id of the private endpoint. + ID *string +} + +// PrivateLinkResource - A private link resource. +type PrivateLinkResource struct { + // Resource properties. + Properties *PrivateLinkResourceProperties + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// PrivateLinkResourceListResult - A list of private link resources. +type PrivateLinkResourceListResult struct { + // Array of private link resources + Value []*PrivateLinkResource +} + +// PrivateLinkResourceProperties - Properties of a private link resource. +type PrivateLinkResourceProperties struct { + // The private link resource private link DNS zone name. + RequiredZoneNames []*string + + // READ-ONLY; The private link resource group id. + GroupID *string + + // READ-ONLY; The private link resource required member names. + RequiredMembers []*string +} + +// PrivateLinkResourcesClientGetOptions contains the optional parameters for the PrivateLinkResourcesClient.Get method. +type PrivateLinkResourcesClientGetOptions struct { + // placeholder for future optional parameters +} + +// PrivateLinkResourcesClientListByClusterOptions contains the optional parameters for the PrivateLinkResourcesClient.NewListByClusterPager +// method. +type PrivateLinkResourcesClientListByClusterOptions struct { + // placeholder for future optional parameters +} + +// PrivateLinkServiceConnectionState - A collection of information about the state of the connection between service consumer +// and provider. +type PrivateLinkServiceConnectionState struct { + // A message indicating if changes on the service provider require any updates on the consumer. + ActionsRequired *string + + // The reason for approval/rejection of the connection. + Description *string + + // Indicates whether the connection has been Approved/Rejected/Removed by the owner of the service. + Status *PrivateEndpointServiceConnectionStatus +} + +// Role - Represents a cluster role. +type Role struct { + // REQUIRED; The properties of a role. + Properties *RoleProperties + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// RoleListResult - A list of roles. +type RoleListResult struct { + // The list of roles in a cluster. + Value []*Role +} + +// RoleProperties - The properties of a cluster role. +type RoleProperties struct { + // REQUIRED; The password of the cluster role. + Password *string + + // READ-ONLY; Provisioning state of the role + ProvisioningState *ProvisioningState +} + +// RolesClientBeginCreateOptions contains the optional parameters for the RolesClient.BeginCreate method. +type RolesClientBeginCreateOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// RolesClientBeginDeleteOptions contains the optional parameters for the RolesClient.BeginDelete method. +type RolesClientBeginDeleteOptions struct { + // Resumes the LRO from the provided token. + ResumeToken string +} + +// RolesClientGetOptions contains the optional parameters for the RolesClient.Get method. +type RolesClientGetOptions struct { + // placeholder for future optional parameters +} + +// RolesClientListByClusterOptions contains the optional parameters for the RolesClient.NewListByClusterPager method. +type RolesClientListByClusterOptions struct { + // placeholder for future optional parameters +} + +// ServerConfiguration - Represents a configuration. +type ServerConfiguration struct { + // The properties of a configuration. + Properties *ServerConfigurationProperties + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// ServerConfigurationListResult - A list of server configurations. +type ServerConfigurationListResult struct { + // The list of server configurations. + Value []*ServerConfiguration + + // READ-ONLY; Link to retrieve next page of results. + NextLink *string +} + +// ServerConfigurationProperties - The properties of a configuration. +type ServerConfigurationProperties struct { + // REQUIRED; Value of the configuration. + Value *string + + // READ-ONLY; Allowed values of the configuration. + AllowedValues *string + + // READ-ONLY; Data type of the configuration. + DataType *ConfigurationDataType + + // READ-ONLY; Default value of the configuration. + DefaultValue *string + + // READ-ONLY; Description of the configuration. + Description *string + + // READ-ONLY; Provisioning state of the configuration. + ProvisioningState *ProvisioningState + + // READ-ONLY; If configuration change requires restart. + RequiresRestart *bool + + // READ-ONLY; Source of the configuration. + Source *string +} + +// ServerNameItem - The name object for a server. +type ServerNameItem struct { + // The name of a server. + Name *string + + // READ-ONLY; The fully qualified domain name of a server. + FullyQualifiedDomainName *string +} + +// ServerRoleGroupConfiguration - Represents server role group configuration value. +type ServerRoleGroupConfiguration struct { + // REQUIRED; The role of servers in the server role group. + Role *ServerRole + + // REQUIRED; Value of the configuration. + Value *string + + // READ-ONLY; Default value of the configuration. + DefaultValue *string + + // READ-ONLY; Source of the configuration. + Source *string +} + +// ServersClientGetOptions contains the optional parameters for the ServersClient.Get method. +type ServersClientGetOptions struct { + // placeholder for future optional parameters +} + +// ServersClientListByClusterOptions contains the optional parameters for the ServersClient.NewListByClusterPager method. +type ServersClientListByClusterOptions struct { + // placeholder for future optional parameters +} + +// SimplePrivateEndpointConnection - A private endpoint connection. +type SimplePrivateEndpointConnection struct { + // Properties of the private endpoint connection. + Properties *PrivateEndpointConnectionSimpleProperties + + // READ-ONLY; Fully qualified resource ID for the resource. E.g. "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}" + ID *string + + // READ-ONLY; The name of the resource + Name *string + + // READ-ONLY; Azure Resource Manager metadata containing createdBy and modifiedBy information. + SystemData *SystemData + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string +} + +// SystemData - Metadata pertaining to creation and last modification of the resource. +type SystemData struct { + // The timestamp of resource creation (UTC). + CreatedAt *time.Time + + // The identity that created the resource. + CreatedBy *string + + // The type of identity that created the resource. + CreatedByType *CreatedByType + + // The timestamp of resource last modification (UTC) + LastModifiedAt *time.Time + + // The identity that last modified the resource. + LastModifiedBy *string + + // The type of identity that last modified the resource. + LastModifiedByType *CreatedByType +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/models_serde.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/models_serde.go new file mode 100644 index 000000000000..de2ef96ea2f5 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/models_serde.go @@ -0,0 +1,1689 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "encoding/json" + "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "reflect" +) + +// MarshalJSON implements the json.Marshaller interface for type Cluster. +func (c Cluster) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", c.ID) + populate(objectMap, "location", c.Location) + populate(objectMap, "name", c.Name) + populate(objectMap, "properties", c.Properties) + populate(objectMap, "systemData", c.SystemData) + populate(objectMap, "tags", c.Tags) + populate(objectMap, "type", c.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Cluster. +func (c *Cluster) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &c.ID) + delete(rawMsg, key) + case "location": + err = unpopulate(val, "Location", &c.Location) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &c.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &c.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &c.SystemData) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &c.Tags) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &c.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ClusterConfigurationListResult. +func (c ClusterConfigurationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", c.NextLink) + populate(objectMap, "value", c.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ClusterConfigurationListResult. +func (c *ClusterConfigurationListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &c.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &c.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ClusterForUpdate. +func (c ClusterForUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "properties", c.Properties) + populate(objectMap, "tags", c.Tags) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ClusterForUpdate. +func (c *ClusterForUpdate) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "properties": + err = unpopulate(val, "Properties", &c.Properties) + delete(rawMsg, key) + case "tags": + err = unpopulate(val, "Tags", &c.Tags) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ClusterListResult. +func (c ClusterListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", c.NextLink) + populate(objectMap, "value", c.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ClusterListResult. +func (c *ClusterListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &c.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &c.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ClusterProperties. +func (c ClusterProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "administratorLogin", c.AdministratorLogin) + populate(objectMap, "administratorLoginPassword", c.AdministratorLoginPassword) + populate(objectMap, "citusVersion", c.CitusVersion) + populate(objectMap, "coordinatorEnablePublicIpAccess", c.CoordinatorEnablePublicIPAccess) + populate(objectMap, "coordinatorServerEdition", c.CoordinatorServerEdition) + populate(objectMap, "coordinatorStorageQuotaInMb", c.CoordinatorStorageQuotaInMb) + populate(objectMap, "coordinatorVCores", c.CoordinatorVCores) + populateTimeRFC3339(objectMap, "earliestRestoreTime", c.EarliestRestoreTime) + populate(objectMap, "enableHa", c.EnableHa) + populate(objectMap, "enableShardsOnCoordinator", c.EnableShardsOnCoordinator) + populate(objectMap, "maintenanceWindow", c.MaintenanceWindow) + populate(objectMap, "nodeCount", c.NodeCount) + populate(objectMap, "nodeEnablePublicIpAccess", c.NodeEnablePublicIPAccess) + populate(objectMap, "nodeServerEdition", c.NodeServerEdition) + populate(objectMap, "nodeStorageQuotaInMb", c.NodeStorageQuotaInMb) + populate(objectMap, "nodeVCores", c.NodeVCores) + populateTimeRFC3339(objectMap, "pointInTimeUTC", c.PointInTimeUTC) + populate(objectMap, "postgresqlVersion", c.PostgresqlVersion) + populate(objectMap, "preferredPrimaryZone", c.PreferredPrimaryZone) + populate(objectMap, "privateEndpointConnections", c.PrivateEndpointConnections) + populate(objectMap, "provisioningState", c.ProvisioningState) + populate(objectMap, "readReplicas", c.ReadReplicas) + populate(objectMap, "serverNames", c.ServerNames) + populate(objectMap, "sourceLocation", c.SourceLocation) + populate(objectMap, "sourceResourceId", c.SourceResourceID) + populate(objectMap, "state", c.State) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ClusterProperties. +func (c *ClusterProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "administratorLogin": + err = unpopulate(val, "AdministratorLogin", &c.AdministratorLogin) + delete(rawMsg, key) + case "administratorLoginPassword": + err = unpopulate(val, "AdministratorLoginPassword", &c.AdministratorLoginPassword) + delete(rawMsg, key) + case "citusVersion": + err = unpopulate(val, "CitusVersion", &c.CitusVersion) + delete(rawMsg, key) + case "coordinatorEnablePublicIpAccess": + err = unpopulate(val, "CoordinatorEnablePublicIPAccess", &c.CoordinatorEnablePublicIPAccess) + delete(rawMsg, key) + case "coordinatorServerEdition": + err = unpopulate(val, "CoordinatorServerEdition", &c.CoordinatorServerEdition) + delete(rawMsg, key) + case "coordinatorStorageQuotaInMb": + err = unpopulate(val, "CoordinatorStorageQuotaInMb", &c.CoordinatorStorageQuotaInMb) + delete(rawMsg, key) + case "coordinatorVCores": + err = unpopulate(val, "CoordinatorVCores", &c.CoordinatorVCores) + delete(rawMsg, key) + case "earliestRestoreTime": + err = unpopulateTimeRFC3339(val, "EarliestRestoreTime", &c.EarliestRestoreTime) + delete(rawMsg, key) + case "enableHa": + err = unpopulate(val, "EnableHa", &c.EnableHa) + delete(rawMsg, key) + case "enableShardsOnCoordinator": + err = unpopulate(val, "EnableShardsOnCoordinator", &c.EnableShardsOnCoordinator) + delete(rawMsg, key) + case "maintenanceWindow": + err = unpopulate(val, "MaintenanceWindow", &c.MaintenanceWindow) + delete(rawMsg, key) + case "nodeCount": + err = unpopulate(val, "NodeCount", &c.NodeCount) + delete(rawMsg, key) + case "nodeEnablePublicIpAccess": + err = unpopulate(val, "NodeEnablePublicIPAccess", &c.NodeEnablePublicIPAccess) + delete(rawMsg, key) + case "nodeServerEdition": + err = unpopulate(val, "NodeServerEdition", &c.NodeServerEdition) + delete(rawMsg, key) + case "nodeStorageQuotaInMb": + err = unpopulate(val, "NodeStorageQuotaInMb", &c.NodeStorageQuotaInMb) + delete(rawMsg, key) + case "nodeVCores": + err = unpopulate(val, "NodeVCores", &c.NodeVCores) + delete(rawMsg, key) + case "pointInTimeUTC": + err = unpopulateTimeRFC3339(val, "PointInTimeUTC", &c.PointInTimeUTC) + delete(rawMsg, key) + case "postgresqlVersion": + err = unpopulate(val, "PostgresqlVersion", &c.PostgresqlVersion) + delete(rawMsg, key) + case "preferredPrimaryZone": + err = unpopulate(val, "PreferredPrimaryZone", &c.PreferredPrimaryZone) + delete(rawMsg, key) + case "privateEndpointConnections": + err = unpopulate(val, "PrivateEndpointConnections", &c.PrivateEndpointConnections) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &c.ProvisioningState) + delete(rawMsg, key) + case "readReplicas": + err = unpopulate(val, "ReadReplicas", &c.ReadReplicas) + delete(rawMsg, key) + case "serverNames": + err = unpopulate(val, "ServerNames", &c.ServerNames) + delete(rawMsg, key) + case "sourceLocation": + err = unpopulate(val, "SourceLocation", &c.SourceLocation) + delete(rawMsg, key) + case "sourceResourceId": + err = unpopulate(val, "SourceResourceID", &c.SourceResourceID) + delete(rawMsg, key) + case "state": + err = unpopulate(val, "State", &c.State) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ClusterPropertiesForUpdate. +func (c ClusterPropertiesForUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "administratorLoginPassword", c.AdministratorLoginPassword) + populate(objectMap, "citusVersion", c.CitusVersion) + populate(objectMap, "coordinatorEnablePublicIpAccess", c.CoordinatorEnablePublicIPAccess) + populate(objectMap, "coordinatorServerEdition", c.CoordinatorServerEdition) + populate(objectMap, "coordinatorStorageQuotaInMb", c.CoordinatorStorageQuotaInMb) + populate(objectMap, "coordinatorVCores", c.CoordinatorVCores) + populate(objectMap, "enableHa", c.EnableHa) + populate(objectMap, "enableShardsOnCoordinator", c.EnableShardsOnCoordinator) + populate(objectMap, "maintenanceWindow", c.MaintenanceWindow) + populate(objectMap, "nodeCount", c.NodeCount) + populate(objectMap, "nodeEnablePublicIpAccess", c.NodeEnablePublicIPAccess) + populate(objectMap, "nodeServerEdition", c.NodeServerEdition) + populate(objectMap, "nodeStorageQuotaInMb", c.NodeStorageQuotaInMb) + populate(objectMap, "nodeVCores", c.NodeVCores) + populate(objectMap, "postgresqlVersion", c.PostgresqlVersion) + populate(objectMap, "preferredPrimaryZone", c.PreferredPrimaryZone) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ClusterPropertiesForUpdate. +func (c *ClusterPropertiesForUpdate) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "administratorLoginPassword": + err = unpopulate(val, "AdministratorLoginPassword", &c.AdministratorLoginPassword) + delete(rawMsg, key) + case "citusVersion": + err = unpopulate(val, "CitusVersion", &c.CitusVersion) + delete(rawMsg, key) + case "coordinatorEnablePublicIpAccess": + err = unpopulate(val, "CoordinatorEnablePublicIPAccess", &c.CoordinatorEnablePublicIPAccess) + delete(rawMsg, key) + case "coordinatorServerEdition": + err = unpopulate(val, "CoordinatorServerEdition", &c.CoordinatorServerEdition) + delete(rawMsg, key) + case "coordinatorStorageQuotaInMb": + err = unpopulate(val, "CoordinatorStorageQuotaInMb", &c.CoordinatorStorageQuotaInMb) + delete(rawMsg, key) + case "coordinatorVCores": + err = unpopulate(val, "CoordinatorVCores", &c.CoordinatorVCores) + delete(rawMsg, key) + case "enableHa": + err = unpopulate(val, "EnableHa", &c.EnableHa) + delete(rawMsg, key) + case "enableShardsOnCoordinator": + err = unpopulate(val, "EnableShardsOnCoordinator", &c.EnableShardsOnCoordinator) + delete(rawMsg, key) + case "maintenanceWindow": + err = unpopulate(val, "MaintenanceWindow", &c.MaintenanceWindow) + delete(rawMsg, key) + case "nodeCount": + err = unpopulate(val, "NodeCount", &c.NodeCount) + delete(rawMsg, key) + case "nodeEnablePublicIpAccess": + err = unpopulate(val, "NodeEnablePublicIPAccess", &c.NodeEnablePublicIPAccess) + delete(rawMsg, key) + case "nodeServerEdition": + err = unpopulate(val, "NodeServerEdition", &c.NodeServerEdition) + delete(rawMsg, key) + case "nodeStorageQuotaInMb": + err = unpopulate(val, "NodeStorageQuotaInMb", &c.NodeStorageQuotaInMb) + delete(rawMsg, key) + case "nodeVCores": + err = unpopulate(val, "NodeVCores", &c.NodeVCores) + delete(rawMsg, key) + case "postgresqlVersion": + err = unpopulate(val, "PostgresqlVersion", &c.PostgresqlVersion) + delete(rawMsg, key) + case "preferredPrimaryZone": + err = unpopulate(val, "PreferredPrimaryZone", &c.PreferredPrimaryZone) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ClusterServer. +func (c ClusterServer) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", c.ID) + populate(objectMap, "name", c.Name) + populate(objectMap, "properties", c.Properties) + populate(objectMap, "systemData", c.SystemData) + populate(objectMap, "type", c.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ClusterServer. +func (c *ClusterServer) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &c.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &c.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &c.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &c.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &c.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ClusterServerListResult. +func (c ClusterServerListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "value", c.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ClusterServerListResult. +func (c *ClusterServerListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "value": + err = unpopulate(val, "Value", &c.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ClusterServerProperties. +func (c ClusterServerProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "administratorLogin", c.AdministratorLogin) + populate(objectMap, "availabilityZone", c.AvailabilityZone) + populate(objectMap, "citusVersion", c.CitusVersion) + populate(objectMap, "enableHa", c.EnableHa) + populate(objectMap, "enablePublicIpAccess", c.EnablePublicIPAccess) + populate(objectMap, "fullyQualifiedDomainName", c.FullyQualifiedDomainName) + populate(objectMap, "haState", c.HaState) + populate(objectMap, "isReadOnly", c.IsReadOnly) + populate(objectMap, "postgresqlVersion", c.PostgresqlVersion) + populate(objectMap, "role", c.Role) + populate(objectMap, "serverEdition", c.ServerEdition) + populate(objectMap, "state", c.State) + populate(objectMap, "storageQuotaInMb", c.StorageQuotaInMb) + populate(objectMap, "vCores", c.VCores) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ClusterServerProperties. +func (c *ClusterServerProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "administratorLogin": + err = unpopulate(val, "AdministratorLogin", &c.AdministratorLogin) + delete(rawMsg, key) + case "availabilityZone": + err = unpopulate(val, "AvailabilityZone", &c.AvailabilityZone) + delete(rawMsg, key) + case "citusVersion": + err = unpopulate(val, "CitusVersion", &c.CitusVersion) + delete(rawMsg, key) + case "enableHa": + err = unpopulate(val, "EnableHa", &c.EnableHa) + delete(rawMsg, key) + case "enablePublicIpAccess": + err = unpopulate(val, "EnablePublicIPAccess", &c.EnablePublicIPAccess) + delete(rawMsg, key) + case "fullyQualifiedDomainName": + err = unpopulate(val, "FullyQualifiedDomainName", &c.FullyQualifiedDomainName) + delete(rawMsg, key) + case "haState": + err = unpopulate(val, "HaState", &c.HaState) + delete(rawMsg, key) + case "isReadOnly": + err = unpopulate(val, "IsReadOnly", &c.IsReadOnly) + delete(rawMsg, key) + case "postgresqlVersion": + err = unpopulate(val, "PostgresqlVersion", &c.PostgresqlVersion) + delete(rawMsg, key) + case "role": + err = unpopulate(val, "Role", &c.Role) + delete(rawMsg, key) + case "serverEdition": + err = unpopulate(val, "ServerEdition", &c.ServerEdition) + delete(rawMsg, key) + case "state": + err = unpopulate(val, "State", &c.State) + delete(rawMsg, key) + case "storageQuotaInMb": + err = unpopulate(val, "StorageQuotaInMb", &c.StorageQuotaInMb) + delete(rawMsg, key) + case "vCores": + err = unpopulate(val, "VCores", &c.VCores) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Configuration. +func (c Configuration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", c.ID) + populate(objectMap, "name", c.Name) + populate(objectMap, "properties", c.Properties) + populate(objectMap, "systemData", c.SystemData) + populate(objectMap, "type", c.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Configuration. +func (c *Configuration) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &c.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &c.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &c.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &c.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &c.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ConfigurationProperties. +func (c ConfigurationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "allowedValues", c.AllowedValues) + populate(objectMap, "dataType", c.DataType) + populate(objectMap, "description", c.Description) + populate(objectMap, "provisioningState", c.ProvisioningState) + populate(objectMap, "requiresRestart", c.RequiresRestart) + populate(objectMap, "serverRoleGroupConfigurations", c.ServerRoleGroupConfigurations) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ConfigurationProperties. +func (c *ConfigurationProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "allowedValues": + err = unpopulate(val, "AllowedValues", &c.AllowedValues) + delete(rawMsg, key) + case "dataType": + err = unpopulate(val, "DataType", &c.DataType) + delete(rawMsg, key) + case "description": + err = unpopulate(val, "Description", &c.Description) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &c.ProvisioningState) + delete(rawMsg, key) + case "requiresRestart": + err = unpopulate(val, "RequiresRestart", &c.RequiresRestart) + delete(rawMsg, key) + case "serverRoleGroupConfigurations": + err = unpopulate(val, "ServerRoleGroupConfigurations", &c.ServerRoleGroupConfigurations) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", c, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type FirewallRule. +func (f FirewallRule) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", f.ID) + populate(objectMap, "name", f.Name) + populate(objectMap, "properties", f.Properties) + populate(objectMap, "systemData", f.SystemData) + populate(objectMap, "type", f.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type FirewallRule. +func (f *FirewallRule) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &f.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &f.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &f.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &f.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &f.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type FirewallRuleListResult. +func (f FirewallRuleListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "value", f.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type FirewallRuleListResult. +func (f *FirewallRuleListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "value": + err = unpopulate(val, "Value", &f.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type FirewallRuleProperties. +func (f FirewallRuleProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "endIpAddress", f.EndIPAddress) + populate(objectMap, "provisioningState", f.ProvisioningState) + populate(objectMap, "startIpAddress", f.StartIPAddress) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type FirewallRuleProperties. +func (f *FirewallRuleProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "endIpAddress": + err = unpopulate(val, "EndIPAddress", &f.EndIPAddress) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &f.ProvisioningState) + delete(rawMsg, key) + case "startIpAddress": + err = unpopulate(val, "StartIPAddress", &f.StartIPAddress) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", f, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type MaintenanceWindow. +func (m MaintenanceWindow) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "customWindow", m.CustomWindow) + populate(objectMap, "dayOfWeek", m.DayOfWeek) + populate(objectMap, "startHour", m.StartHour) + populate(objectMap, "startMinute", m.StartMinute) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type MaintenanceWindow. +func (m *MaintenanceWindow) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "customWindow": + err = unpopulate(val, "CustomWindow", &m.CustomWindow) + delete(rawMsg, key) + case "dayOfWeek": + err = unpopulate(val, "DayOfWeek", &m.DayOfWeek) + delete(rawMsg, key) + case "startHour": + err = unpopulate(val, "StartHour", &m.StartHour) + delete(rawMsg, key) + case "startMinute": + err = unpopulate(val, "StartMinute", &m.StartMinute) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", m, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type NameAvailability. +func (n NameAvailability) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "message", n.Message) + populate(objectMap, "name", n.Name) + populate(objectMap, "nameAvailable", n.NameAvailable) + populate(objectMap, "type", n.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type NameAvailability. +func (n *NameAvailability) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", n, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "message": + err = unpopulate(val, "Message", &n.Message) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &n.Name) + delete(rawMsg, key) + case "nameAvailable": + err = unpopulate(val, "NameAvailable", &n.NameAvailable) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &n.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", n, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type NameAvailabilityRequest. +func (n NameAvailabilityRequest) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "name", n.Name) + objectMap["type"] = "Microsoft.DBforPostgreSQL/serverGroupsv2" + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type NameAvailabilityRequest. +func (n *NameAvailabilityRequest) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", n, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "name": + err = unpopulate(val, "Name", &n.Name) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &n.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", n, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Operation. +func (o Operation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + 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) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Operation. +func (o *Operation) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "display": + err = unpopulate(val, "Display", &o.Display) + delete(rawMsg, key) + case "isDataAction": + err = unpopulate(val, "IsDataAction", &o.IsDataAction) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &o.Name) + delete(rawMsg, key) + case "origin": + err = unpopulate(val, "Origin", &o.Origin) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &o.Properties) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationDisplay. +func (o OperationDisplay) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "description", o.Description) + populate(objectMap, "operation", o.Operation) + populate(objectMap, "provider", o.Provider) + populate(objectMap, "resource", o.Resource) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationDisplay. +func (o *OperationDisplay) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "description": + err = unpopulate(val, "Description", &o.Description) + delete(rawMsg, key) + case "operation": + err = unpopulate(val, "Operation", &o.Operation) + delete(rawMsg, key) + case "provider": + err = unpopulate(val, "Provider", &o.Provider) + delete(rawMsg, key) + case "resource": + err = unpopulate(val, "Resource", &o.Resource) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type OperationListResult. +func (o *OperationListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &o.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &o.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", o, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateEndpoint. +func (p PrivateEndpoint) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", p.ID) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateEndpoint. +func (p *PrivateEndpoint) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &p.ID) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateEndpointConnection. +func (p PrivateEndpointConnection) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", p.ID) + populate(objectMap, "name", p.Name) + populate(objectMap, "properties", p.Properties) + populate(objectMap, "systemData", p.SystemData) + populate(objectMap, "type", p.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateEndpointConnection. +func (p *PrivateEndpointConnection) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &p.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &p.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &p.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &p.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &p.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateEndpointConnectionListResult. +func (p PrivateEndpointConnectionListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "value", p.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateEndpointConnectionListResult. +func (p *PrivateEndpointConnectionListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "value": + err = unpopulate(val, "Value", &p.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateEndpointConnectionProperties. +func (p PrivateEndpointConnectionProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "groupIds", p.GroupIDs) + populate(objectMap, "privateEndpoint", p.PrivateEndpoint) + populate(objectMap, "privateLinkServiceConnectionState", p.PrivateLinkServiceConnectionState) + populate(objectMap, "provisioningState", p.ProvisioningState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateEndpointConnectionProperties. +func (p *PrivateEndpointConnectionProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "groupIds": + err = unpopulate(val, "GroupIDs", &p.GroupIDs) + delete(rawMsg, key) + case "privateEndpoint": + err = unpopulate(val, "PrivateEndpoint", &p.PrivateEndpoint) + delete(rawMsg, key) + case "privateLinkServiceConnectionState": + err = unpopulate(val, "PrivateLinkServiceConnectionState", &p.PrivateLinkServiceConnectionState) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &p.ProvisioningState) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateEndpointConnectionSimpleProperties. +func (p PrivateEndpointConnectionSimpleProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "groupIds", p.GroupIDs) + populate(objectMap, "privateEndpoint", p.PrivateEndpoint) + populate(objectMap, "privateLinkServiceConnectionState", p.PrivateLinkServiceConnectionState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateEndpointConnectionSimpleProperties. +func (p *PrivateEndpointConnectionSimpleProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "groupIds": + err = unpopulate(val, "GroupIDs", &p.GroupIDs) + delete(rawMsg, key) + case "privateEndpoint": + err = unpopulate(val, "PrivateEndpoint", &p.PrivateEndpoint) + delete(rawMsg, key) + case "privateLinkServiceConnectionState": + err = unpopulate(val, "PrivateLinkServiceConnectionState", &p.PrivateLinkServiceConnectionState) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateEndpointProperty. +func (p PrivateEndpointProperty) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", p.ID) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateEndpointProperty. +func (p *PrivateEndpointProperty) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &p.ID) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateLinkResource. +func (p PrivateLinkResource) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", p.ID) + populate(objectMap, "name", p.Name) + populate(objectMap, "properties", p.Properties) + populate(objectMap, "systemData", p.SystemData) + populate(objectMap, "type", p.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateLinkResource. +func (p *PrivateLinkResource) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &p.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &p.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &p.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &p.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &p.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateLinkResourceListResult. +func (p PrivateLinkResourceListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "value", p.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateLinkResourceListResult. +func (p *PrivateLinkResourceListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "value": + err = unpopulate(val, "Value", &p.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateLinkResourceProperties. +func (p PrivateLinkResourceProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "groupId", p.GroupID) + populate(objectMap, "requiredMembers", p.RequiredMembers) + populate(objectMap, "requiredZoneNames", p.RequiredZoneNames) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateLinkResourceProperties. +func (p *PrivateLinkResourceProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "groupId": + err = unpopulate(val, "GroupID", &p.GroupID) + delete(rawMsg, key) + case "requiredMembers": + err = unpopulate(val, "RequiredMembers", &p.RequiredMembers) + delete(rawMsg, key) + case "requiredZoneNames": + err = unpopulate(val, "RequiredZoneNames", &p.RequiredZoneNames) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type PrivateLinkServiceConnectionState. +func (p PrivateLinkServiceConnectionState) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "actionsRequired", p.ActionsRequired) + populate(objectMap, "description", p.Description) + populate(objectMap, "status", p.Status) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type PrivateLinkServiceConnectionState. +func (p *PrivateLinkServiceConnectionState) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "actionsRequired": + err = unpopulate(val, "ActionsRequired", &p.ActionsRequired) + delete(rawMsg, key) + case "description": + err = unpopulate(val, "Description", &p.Description) + delete(rawMsg, key) + case "status": + err = unpopulate(val, "Status", &p.Status) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", p, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type Role. +func (r Role) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", r.ID) + populate(objectMap, "name", r.Name) + populate(objectMap, "properties", r.Properties) + populate(objectMap, "systemData", r.SystemData) + populate(objectMap, "type", r.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Role. +func (r *Role) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &r.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &r.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &r.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &r.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &r.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type RoleListResult. +func (r RoleListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "value", r.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type RoleListResult. +func (r *RoleListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "value": + err = unpopulate(val, "Value", &r.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type RoleProperties. +func (r RoleProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "password", r.Password) + populate(objectMap, "provisioningState", r.ProvisioningState) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type RoleProperties. +func (r *RoleProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "password": + err = unpopulate(val, "Password", &r.Password) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &r.ProvisioningState) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", r, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ServerConfiguration. +func (s ServerConfiguration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", s.ID) + populate(objectMap, "name", s.Name) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + populate(objectMap, "type", s.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ServerConfiguration. +func (s *ServerConfiguration) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &s.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &s.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &s.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &s.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ServerConfigurationListResult. +func (s ServerConfigurationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ServerConfigurationListResult. +func (s *ServerConfigurationListResult) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "nextLink": + err = unpopulate(val, "NextLink", &s.NextLink) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &s.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ServerConfigurationProperties. +func (s ServerConfigurationProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "allowedValues", s.AllowedValues) + populate(objectMap, "dataType", s.DataType) + populate(objectMap, "defaultValue", s.DefaultValue) + populate(objectMap, "description", s.Description) + populate(objectMap, "provisioningState", s.ProvisioningState) + populate(objectMap, "requiresRestart", s.RequiresRestart) + populate(objectMap, "source", s.Source) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ServerConfigurationProperties. +func (s *ServerConfigurationProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "allowedValues": + err = unpopulate(val, "AllowedValues", &s.AllowedValues) + delete(rawMsg, key) + case "dataType": + err = unpopulate(val, "DataType", &s.DataType) + delete(rawMsg, key) + case "defaultValue": + err = unpopulate(val, "DefaultValue", &s.DefaultValue) + delete(rawMsg, key) + case "description": + err = unpopulate(val, "Description", &s.Description) + delete(rawMsg, key) + case "provisioningState": + err = unpopulate(val, "ProvisioningState", &s.ProvisioningState) + delete(rawMsg, key) + case "requiresRestart": + err = unpopulate(val, "RequiresRestart", &s.RequiresRestart) + delete(rawMsg, key) + case "source": + err = unpopulate(val, "Source", &s.Source) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &s.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ServerNameItem. +func (s ServerNameItem) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "fullyQualifiedDomainName", s.FullyQualifiedDomainName) + populate(objectMap, "name", s.Name) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ServerNameItem. +func (s *ServerNameItem) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "fullyQualifiedDomainName": + err = unpopulate(val, "FullyQualifiedDomainName", &s.FullyQualifiedDomainName) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type ServerRoleGroupConfiguration. +func (s ServerRoleGroupConfiguration) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "defaultValue", s.DefaultValue) + populate(objectMap, "role", s.Role) + populate(objectMap, "source", s.Source) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ServerRoleGroupConfiguration. +func (s *ServerRoleGroupConfiguration) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "defaultValue": + err = unpopulate(val, "DefaultValue", &s.DefaultValue) + delete(rawMsg, key) + case "role": + err = unpopulate(val, "Role", &s.Role) + delete(rawMsg, key) + case "source": + err = unpopulate(val, "Source", &s.Source) + delete(rawMsg, key) + case "value": + err = unpopulate(val, "Value", &s.Value) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SimplePrivateEndpointConnection. +func (s SimplePrivateEndpointConnection) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + populate(objectMap, "id", s.ID) + populate(objectMap, "name", s.Name) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + populate(objectMap, "type", s.Type) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SimplePrivateEndpointConnection. +func (s *SimplePrivateEndpointConnection) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "id": + err = unpopulate(val, "ID", &s.ID) + delete(rawMsg, key) + case "name": + err = unpopulate(val, "Name", &s.Name) + delete(rawMsg, key) + case "properties": + err = unpopulate(val, "Properties", &s.Properties) + delete(rawMsg, key) + case "systemData": + err = unpopulate(val, "SystemData", &s.SystemData) + delete(rawMsg, key) + case "type": + err = unpopulate(val, "Type", &s.Type) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +// MarshalJSON implements the json.Marshaller interface for type SystemData. +func (s SystemData) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]any) + 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 fmt.Errorf("unmarshalling type %T: %v", s, err) + } + for key, val := range rawMsg { + var err error + switch key { + case "createdAt": + err = unpopulateTimeRFC3339(val, "CreatedAt", &s.CreatedAt) + delete(rawMsg, key) + case "createdBy": + err = unpopulate(val, "CreatedBy", &s.CreatedBy) + delete(rawMsg, key) + case "createdByType": + err = unpopulate(val, "CreatedByType", &s.CreatedByType) + delete(rawMsg, key) + case "lastModifiedAt": + err = unpopulateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt) + delete(rawMsg, key) + case "lastModifiedBy": + err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy) + delete(rawMsg, key) + case "lastModifiedByType": + err = unpopulate(val, "LastModifiedByType", &s.LastModifiedByType) + delete(rawMsg, key) + } + if err != nil { + return fmt.Errorf("unmarshalling type %T: %v", s, err) + } + } + return nil +} + +func populate(m map[string]any, k string, v any) { + 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, fn string, v any) error { + if data == nil { + return nil + } + if err := json.Unmarshal(data, v); err != nil { + return fmt.Errorf("struct field %s: %v", fn, err) + } + return nil +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/operations_client.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/operations_client.go new file mode 100644 index 000000000000..3161a7d02e20 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/operations_client.go @@ -0,0 +1,88 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "context" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "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 { + internal *arm.Client +} + +// NewOperationsClient creates a new instance of OperationsClient with the specified values. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewOperationsClient(credential azcore.TokenCredential, options *arm.ClientOptions) (*OperationsClient, error) { + cl, err := arm.NewClient(moduleName+".OperationsClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &OperationsClient{ + internal: cl, + } + return client, nil +} + +// NewListPager - Lists all of the available REST API operations. +// +// Generated from API version 2022-11-08 +// - options - OperationsClientListOptions contains the optional parameters for the OperationsClient.NewListPager method. +func (client *OperationsClient) NewListPager(options *OperationsClientListOptions) *runtime.Pager[OperationsClientListResponse] { + return runtime.NewPager(runtime.PagingHandler[OperationsClientListResponse]{ + More: func(page OperationsClientListResponse) bool { + return false + }, + Fetcher: func(ctx context.Context, page *OperationsClientListResponse) (OperationsClientListResponse, error) { + req, err := client.listCreateRequest(ctx, options) + if err != nil { + return OperationsClientListResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return OperationsClientListResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return OperationsClientListResponse{}, runtime.NewResponseError(resp) + } + return client.listHandleResponse(resp) + }, + }) +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsClientListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.DBforPostgreSQL/operations" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsClientListResponse, error) { + result := OperationsClientListResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.OperationListResult); err != nil { + return OperationsClientListResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/operations_client_example_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/operations_client_example_test.go new file mode 100644 index 000000000000..dc8173b551be --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/operations_client_example_test.go @@ -0,0 +1,230 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/OperationList.json +func ExampleOperationsClient_NewListPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewOperationsClient().NewListPager(nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.OperationListResult = armcosmosforpostgresql.OperationListResult{ + // Value: []*armcosmosforpostgresql.Operation{ + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/read"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Return the list of clusters or gets the properties for the specified cluster."), + // Operation: to.Ptr("List/Get PostgreSQL Clusters"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("PostgreSQL Cluster"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/write"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Creates a cluster with the specified parameters or update the properties or tags for the specified cluster."), + // Operation: to.Ptr("Create/Update PostgreSQL Cluster"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("PostgreSQL Cluster"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/delete"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Deletes an existing cluster."), + // Operation: to.Ptr("Delete PostgreSQL Cluster"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("PostgreSQL Cluster"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers/read"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Return the list of servers of cluster or gets the properties for the specified server from cluster."), + // Operation: to.Ptr("List/Get PostgreSQL Servers of Cluster"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("PostgreSQL Server"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers/configurations/read"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Return the list of configurations for a server or gets the value for the specified configuration."), + // Operation: to.Ptr("List/Get Configurations of Server"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Configurations"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations/read"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Return the list of configurations for a cluster or gets the value for the specified configuration."), + // Operation: to.Ptr("List/Get Configurations of Cluster"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Configurations"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/configurations/write"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Update an value of configurations."), + // Operation: to.Ptr("Update Configurations of Cluster"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Configurations"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/firewallRules/read"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Return the list of firewall rules for a cluster or gets the properties for the specified firewall rule."), + // Operation: to.Ptr("List/Get Firewall Rules"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Firewall Rules"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/firewallRules/write"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Creates a firewall rule with the specified parameters or update an existing rule."), + // Operation: to.Ptr("Create/Update Firewall Rule"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Firewall Rules"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/firewallRules/delete"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Deletes an existing firewall rule."), + // Operation: to.Ptr("Delete Firewall Rule"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Firewall Rules"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/providers/Microsoft.Insights/metricDefinitions/read"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Return types of metrics that are available for databases"), + // Operation: to.Ptr("Get database metric definitions"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Database Metric Definition"), + // }, + // Properties: map[string]any{ + // "serviceSpecification": map[string]any{ + // "metricSpecifications":[]any{ + // map[string]any{ + // "name": "cpu_percent", + // "aggregationType": "Average", + // "displayDescription": "CPU percent", + // "displayName": "CPU percent", + // "fillGapWithZero": true, + // "unit": "Percent", + // }, + // map[string]any{ + // "name": "memory_percent", + // "aggregationType": "Average", + // "displayDescription": "Memory percent", + // "displayName": "Memory percent", + // "fillGapWithZero": true, + // "unit": "Percent", + // }, + // map[string]any{ + // "name": "io_consumption_percent", + // "aggregationType": "Average", + // "displayDescription": "IO percent", + // "displayName": "IO percent", + // "fillGapWithZero": true, + // "unit": "Percent", + // }, + // map[string]any{ + // "name": "storage_percent", + // "aggregationType": "Average", + // "displayDescription": "Storage percentage", + // "displayName": "Storage percentage", + // "unit": "Percent", + // }, + // map[string]any{ + // "name": "storage_used", + // "aggregationType": "Average", + // "displayDescription": "Storage used", + // "displayName": "Storage used", + // "unit": "Bytes", + // }, + // map[string]any{ + // "name": "storage_limit", + // "aggregationType": "Average", + // "displayDescription": "Storage limit", + // "displayName": "Storage limit", + // "unit": "Bytes", + // }, + // map[string]any{ + // "name": "active_connections", + // "aggregationType": "Average", + // "displayDescription": "Total active connections", + // "displayName": "Total active connections", + // "fillGapWithZero": true, + // "unit": "Count", + // }, + // map[string]any{ + // "name": "connections_failed", + // "aggregationType": "Average", + // "displayDescription": "Total failed connections", + // "displayName": "Total failed connections", + // "fillGapWithZero": true, + // "unit": "Count", + // }, + // }, + // }, + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/providers/Microsoft.Insights/diagnosticSettings/read"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Gets the disagnostic setting for the resource"), + // Operation: to.Ptr("Read diagnostic setting"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Database Metric Definition"), + // }, + // }, + // { + // Name: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/providers/Microsoft.Insights/diagnosticSettings/write"), + // Display: &armcosmosforpostgresql.OperationDisplay{ + // Description: to.Ptr("Creates or updates the diagnostic setting for the resource"), + // Operation: to.Ptr("Write diagnostic setting"), + // Provider: to.Ptr("Microsoft DB for PostgreSQL"), + // Resource: to.Ptr("Database Metric Definition"), + // }, + // }}, + // } + } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privateendpointconnections_client.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privateendpointconnections_client.go new file mode 100644 index 000000000000..d90a8181ae57 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privateendpointconnections_client.go @@ -0,0 +1,305 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "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" +) + +// PrivateEndpointConnectionsClient contains the methods for the PrivateEndpointConnections group. +// Don't use this type directly, use NewPrivateEndpointConnectionsClient() instead. +type PrivateEndpointConnectionsClient struct { + internal *arm.Client + subscriptionID string +} + +// NewPrivateEndpointConnectionsClient creates a new instance of PrivateEndpointConnectionsClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewPrivateEndpointConnectionsClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*PrivateEndpointConnectionsClient, error) { + cl, err := arm.NewClient(moduleName+".PrivateEndpointConnectionsClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &PrivateEndpointConnectionsClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// BeginCreateOrUpdate - Approves or Rejects a private endpoint connection with a given name. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - privateEndpointConnectionName - The name of the private endpoint connection associated with the cluster. +// - parameters - The required parameters for approving a private endpoint connection. +// - options - PrivateEndpointConnectionsClientBeginCreateOrUpdateOptions contains the optional parameters for the PrivateEndpointConnectionsClient.BeginCreateOrUpdate +// method. +func (client *PrivateEndpointConnectionsClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, clusterName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection, options *PrivateEndpointConnectionsClientBeginCreateOrUpdateOptions) (*runtime.Poller[PrivateEndpointConnectionsClientCreateOrUpdateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.createOrUpdate(ctx, resourceGroupName, clusterName, privateEndpointConnectionName, parameters, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateEndpointConnectionsClientCreateOrUpdateResponse]{ + FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + }) + } else { + return runtime.NewPollerFromResumeToken[PrivateEndpointConnectionsClientCreateOrUpdateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// CreateOrUpdate - Approves or Rejects a private endpoint connection with a given name. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *PrivateEndpointConnectionsClient) createOrUpdate(ctx context.Context, resourceGroupName string, clusterName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection, options *PrivateEndpointConnectionsClientBeginCreateOrUpdateOptions) (*http.Response, error) { + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, clusterName, privateEndpointConnectionName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *PrivateEndpointConnectionsClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, privateEndpointConnectionName string, parameters PrivateEndpointConnection, options *PrivateEndpointConnectionsClientBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + if privateEndpointConnectionName == "" { + return nil, errors.New("parameter privateEndpointConnectionName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{privateEndpointConnectionName}", url.PathEscape(privateEndpointConnectionName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// BeginDelete - Deletes a private endpoint connection with a given name. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - privateEndpointConnectionName - The name of the private endpoint connection associated with the cluster. +// - options - PrivateEndpointConnectionsClientBeginDeleteOptions contains the optional parameters for the PrivateEndpointConnectionsClient.BeginDelete +// method. +func (client *PrivateEndpointConnectionsClient) BeginDelete(ctx context.Context, resourceGroupName string, clusterName string, privateEndpointConnectionName string, options *PrivateEndpointConnectionsClientBeginDeleteOptions) (*runtime.Poller[PrivateEndpointConnectionsClientDeleteResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.deleteOperation(ctx, resourceGroupName, clusterName, privateEndpointConnectionName, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[PrivateEndpointConnectionsClientDeleteResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[PrivateEndpointConnectionsClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Delete - Deletes a private endpoint connection with a given name. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *PrivateEndpointConnectionsClient) deleteOperation(ctx context.Context, resourceGroupName string, clusterName string, privateEndpointConnectionName string, options *PrivateEndpointConnectionsClientBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, clusterName, privateEndpointConnectionName, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *PrivateEndpointConnectionsClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, privateEndpointConnectionName string, options *PrivateEndpointConnectionsClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + if privateEndpointConnectionName == "" { + return nil, errors.New("parameter privateEndpointConnectionName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{privateEndpointConnectionName}", url.PathEscape(privateEndpointConnectionName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - Gets private endpoint connection. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - privateEndpointConnectionName - The name of the private endpoint connection associated with the cluster. +// - options - PrivateEndpointConnectionsClientGetOptions contains the optional parameters for the PrivateEndpointConnectionsClient.Get +// method. +func (client *PrivateEndpointConnectionsClient) Get(ctx context.Context, resourceGroupName string, clusterName string, privateEndpointConnectionName string, options *PrivateEndpointConnectionsClientGetOptions) (PrivateEndpointConnectionsClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, clusterName, privateEndpointConnectionName, options) + if err != nil { + return PrivateEndpointConnectionsClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return PrivateEndpointConnectionsClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return PrivateEndpointConnectionsClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *PrivateEndpointConnectionsClient) getCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, privateEndpointConnectionName string, options *PrivateEndpointConnectionsClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + if privateEndpointConnectionName == "" { + return nil, errors.New("parameter privateEndpointConnectionName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{privateEndpointConnectionName}", url.PathEscape(privateEndpointConnectionName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *PrivateEndpointConnectionsClient) getHandleResponse(resp *http.Response) (PrivateEndpointConnectionsClientGetResponse, error) { + result := PrivateEndpointConnectionsClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.PrivateEndpointConnection); err != nil { + return PrivateEndpointConnectionsClientGetResponse{}, err + } + return result, nil +} + +// NewListByClusterPager - Gets list of private endpoint connections on a cluster. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - PrivateEndpointConnectionsClientListByClusterOptions contains the optional parameters for the PrivateEndpointConnectionsClient.NewListByClusterPager +// method. +func (client *PrivateEndpointConnectionsClient) NewListByClusterPager(resourceGroupName string, clusterName string, options *PrivateEndpointConnectionsClientListByClusterOptions) *runtime.Pager[PrivateEndpointConnectionsClientListByClusterResponse] { + return runtime.NewPager(runtime.PagingHandler[PrivateEndpointConnectionsClientListByClusterResponse]{ + More: func(page PrivateEndpointConnectionsClientListByClusterResponse) bool { + return false + }, + Fetcher: func(ctx context.Context, page *PrivateEndpointConnectionsClientListByClusterResponse) (PrivateEndpointConnectionsClientListByClusterResponse, error) { + req, err := client.listByClusterCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return PrivateEndpointConnectionsClientListByClusterResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return PrivateEndpointConnectionsClientListByClusterResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return PrivateEndpointConnectionsClientListByClusterResponse{}, runtime.NewResponseError(resp) + } + return client.listByClusterHandleResponse(resp) + }, + }) +} + +// listByClusterCreateRequest creates the ListByCluster request. +func (client *PrivateEndpointConnectionsClient) listByClusterCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *PrivateEndpointConnectionsClientListByClusterOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByClusterHandleResponse handles the ListByCluster response. +func (client *PrivateEndpointConnectionsClient) listByClusterHandleResponse(resp *http.Response) (PrivateEndpointConnectionsClientListByClusterResponse, error) { + result := PrivateEndpointConnectionsClientListByClusterResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.PrivateEndpointConnectionListResult); err != nil { + return PrivateEndpointConnectionsClientListByClusterResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privateendpointconnections_client_example_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privateendpointconnections_client_example_test.go new file mode 100644 index 000000000000..69823c317d00 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privateendpointconnections_client_example_test.go @@ -0,0 +1,213 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/PrivateEndpointConnectionsListByCluster.json +func ExamplePrivateEndpointConnectionsClient_NewListByClusterPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewPrivateEndpointConnectionsClient().NewListByClusterPager("TestResourceGroup", "testcluster", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.PrivateEndpointConnectionListResult = armcosmosforpostgresql.PrivateEndpointConnectionListResult{ + // Value: []*armcosmosforpostgresql.PrivateEndpointConnection{ + // { + // Name: to.Ptr("private-endpoint-connection-name"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/privateEndpointConnections"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateEndpointConnections/private-endpoint-connection-name"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.PrivateEndpointConnectionProperties{ + // GroupIDs: []*string{ + // to.Ptr("coordinator")}, + // PrivateEndpoint: &armcosmosforpostgresql.PrivateEndpoint{ + // ID: to.Ptr("/subscriptions/55555555-6666-7777-8888-999999999999/resourceGroups/Default-Network/providers/Microsoft.Network/privateEndpoints/private-endpoint-name"), + // }, + // PrivateLinkServiceConnectionState: &armcosmosforpostgresql.PrivateLinkServiceConnectionState{ + // Description: to.Ptr("Auto-approved"), + // ActionsRequired: to.Ptr("None"), + // Status: to.Ptr(armcosmosforpostgresql.PrivateEndpointServiceConnectionStatusApproved), + // }, + // ProvisioningState: to.Ptr(armcosmosforpostgresql.PrivateEndpointConnectionProvisioningStateSucceeded), + // }, + // }, + // { + // Name: to.Ptr("private-endpoint-connection-name-2"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/privateEndpointConnections"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateEndpointConnections/private-endpoint-connection-name-2"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.PrivateEndpointConnectionProperties{ + // GroupIDs: []*string{ + // to.Ptr("worker-0")}, + // PrivateEndpoint: &armcosmosforpostgresql.PrivateEndpoint{ + // ID: to.Ptr("/subscriptions/55555555-6666-7777-8888-999999999999/resourceGroups/Default-Network/providers/Microsoft.Network/privateEndpoints/private-endpoint-name-2"), + // }, + // PrivateLinkServiceConnectionState: &armcosmosforpostgresql.PrivateLinkServiceConnectionState{ + // Description: to.Ptr("Auto-approved"), + // ActionsRequired: to.Ptr("None"), + // Status: to.Ptr(armcosmosforpostgresql.PrivateEndpointServiceConnectionStatusApproved), + // }, + // ProvisioningState: to.Ptr(armcosmosforpostgresql.PrivateEndpointConnectionProvisioningStateSucceeded), + // }, + // }}, + // } + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/PrivateEndpointConnectionsGet.json +func ExamplePrivateEndpointConnectionsClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewPrivateEndpointConnectionsClient().Get(ctx, "TestGroup", "testcluster", "private-endpoint-connection-name", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.PrivateEndpointConnection = armcosmosforpostgresql.PrivateEndpointConnection{ + // Name: to.Ptr("private-endpoint-connection-name"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/privateEndpointConnections"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateEndpointConnections/private-endpoint-connection-name"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.PrivateEndpointConnectionProperties{ + // GroupIDs: []*string{ + // to.Ptr("coordinator")}, + // PrivateEndpoint: &armcosmosforpostgresql.PrivateEndpoint{ + // ID: to.Ptr("/subscriptions/55555555-6666-7777-8888-999999999999/resourceGroups/Default-Network/providers/Microsoft.Network/privateEndpoints/private-endpoint-name"), + // }, + // PrivateLinkServiceConnectionState: &armcosmosforpostgresql.PrivateLinkServiceConnectionState{ + // Description: to.Ptr("Auto-approved"), + // ActionsRequired: to.Ptr("None"), + // Status: to.Ptr(armcosmosforpostgresql.PrivateEndpointServiceConnectionStatusApproved), + // }, + // ProvisioningState: to.Ptr(armcosmosforpostgresql.PrivateEndpointConnectionProvisioningStateSucceeded), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/PrivateEndpointConnectionCreateOrUpdate.json +func ExamplePrivateEndpointConnectionsClient_BeginCreateOrUpdate() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewPrivateEndpointConnectionsClient().BeginCreateOrUpdate(ctx, "TestGroup", "testcluster", "private-endpoint-connection-name", armcosmosforpostgresql.PrivateEndpointConnection{ + Properties: &armcosmosforpostgresql.PrivateEndpointConnectionProperties{ + PrivateLinkServiceConnectionState: &armcosmosforpostgresql.PrivateLinkServiceConnectionState{ + Description: to.Ptr("Approved by johndoe@contoso.com"), + Status: to.Ptr(armcosmosforpostgresql.PrivateEndpointServiceConnectionStatusApproved), + }, + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.PrivateEndpointConnection = armcosmosforpostgresql.PrivateEndpointConnection{ + // Name: to.Ptr("private-endpoint-connection-name"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/privateEndpointConnections"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateEndpointConnections/private-endpoint-connection-name"), + // Properties: &armcosmosforpostgresql.PrivateEndpointConnectionProperties{ + // PrivateEndpoint: &armcosmosforpostgresql.PrivateEndpoint{ + // ID: to.Ptr("/subscriptions/55555555-6666-7777-8888-999999999999/resourceGroups/Default-Network/providers/Microsoft.Network/privateEndpoints/private-endpoint-name"), + // }, + // PrivateLinkServiceConnectionState: &armcosmosforpostgresql.PrivateLinkServiceConnectionState{ + // Description: to.Ptr("Approved by johndoe@contoso.com"), + // ActionsRequired: to.Ptr("None"), + // Status: to.Ptr(armcosmosforpostgresql.PrivateEndpointServiceConnectionStatusApproved), + // }, + // ProvisioningState: to.Ptr(armcosmosforpostgresql.PrivateEndpointConnectionProvisioningStateSucceeded), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/PrivateEndpointConnectionsDelete.json +func ExamplePrivateEndpointConnectionsClient_BeginDelete() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewPrivateEndpointConnectionsClient().BeginDelete(ctx, "TestGroup", "testcluster", "private-endpoint-connection-name", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privatelinkresources_client.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privatelinkresources_client.go new file mode 100644 index 000000000000..b0e16d719469 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privatelinkresources_client.go @@ -0,0 +1,166 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "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" +) + +// PrivateLinkResourcesClient contains the methods for the PrivateLinkResources group. +// Don't use this type directly, use NewPrivateLinkResourcesClient() instead. +type PrivateLinkResourcesClient struct { + internal *arm.Client + subscriptionID string +} + +// NewPrivateLinkResourcesClient creates a new instance of PrivateLinkResourcesClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewPrivateLinkResourcesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*PrivateLinkResourcesClient, error) { + cl, err := arm.NewClient(moduleName+".PrivateLinkResourcesClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &PrivateLinkResourcesClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// Get - Gets a private link resource for cluster. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - privateLinkResourceName - The name of the private link resource. +// - options - PrivateLinkResourcesClientGetOptions contains the optional parameters for the PrivateLinkResourcesClient.Get +// method. +func (client *PrivateLinkResourcesClient) Get(ctx context.Context, resourceGroupName string, clusterName string, privateLinkResourceName string, options *PrivateLinkResourcesClientGetOptions) (PrivateLinkResourcesClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, clusterName, privateLinkResourceName, options) + if err != nil { + return PrivateLinkResourcesClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return PrivateLinkResourcesClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return PrivateLinkResourcesClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *PrivateLinkResourcesClient) getCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, privateLinkResourceName string, options *PrivateLinkResourcesClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateLinkResources/{privateLinkResourceName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + if privateLinkResourceName == "" { + return nil, errors.New("parameter privateLinkResourceName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{privateLinkResourceName}", url.PathEscape(privateLinkResourceName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *PrivateLinkResourcesClient) getHandleResponse(resp *http.Response) (PrivateLinkResourcesClientGetResponse, error) { + result := PrivateLinkResourcesClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.PrivateLinkResource); err != nil { + return PrivateLinkResourcesClientGetResponse{}, err + } + return result, nil +} + +// NewListByClusterPager - Gets the private link resources for cluster. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - PrivateLinkResourcesClientListByClusterOptions contains the optional parameters for the PrivateLinkResourcesClient.NewListByClusterPager +// method. +func (client *PrivateLinkResourcesClient) NewListByClusterPager(resourceGroupName string, clusterName string, options *PrivateLinkResourcesClientListByClusterOptions) *runtime.Pager[PrivateLinkResourcesClientListByClusterResponse] { + return runtime.NewPager(runtime.PagingHandler[PrivateLinkResourcesClientListByClusterResponse]{ + More: func(page PrivateLinkResourcesClientListByClusterResponse) bool { + return false + }, + Fetcher: func(ctx context.Context, page *PrivateLinkResourcesClientListByClusterResponse) (PrivateLinkResourcesClientListByClusterResponse, error) { + req, err := client.listByClusterCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return PrivateLinkResourcesClientListByClusterResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return PrivateLinkResourcesClientListByClusterResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return PrivateLinkResourcesClientListByClusterResponse{}, runtime.NewResponseError(resp) + } + return client.listByClusterHandleResponse(resp) + }, + }) +} + +// listByClusterCreateRequest creates the ListByCluster request. +func (client *PrivateLinkResourcesClient) listByClusterCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *PrivateLinkResourcesClientListByClusterOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateLinkResources" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByClusterHandleResponse handles the ListByCluster response. +func (client *PrivateLinkResourcesClient) listByClusterHandleResponse(resp *http.Response) (PrivateLinkResourcesClientListByClusterResponse, error) { + result := PrivateLinkResourcesClientListByClusterResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.PrivateLinkResourceListResult); err != nil { + return PrivateLinkResourcesClientListByClusterResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privatelinkresources_client_example_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privatelinkresources_client_example_test.go new file mode 100644 index 000000000000..81495488f10f --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/privatelinkresources_client_example_test.go @@ -0,0 +1,126 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/PrivateLinkResourceListByCluster.json +func ExamplePrivateLinkResourcesClient_NewListByClusterPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewPrivateLinkResourcesClient().NewListByClusterPager("TestResourceGroup", "testcluster", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.PrivateLinkResourceListResult = armcosmosforpostgresql.PrivateLinkResourceListResult{ + // Value: []*armcosmosforpostgresql.PrivateLinkResource{ + // { + // Name: to.Ptr("coordinator"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/privateLinkResources"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateLinkResources/coordinator"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.PrivateLinkResourceProperties{ + // GroupID: to.Ptr("coordinator"), + // RequiredMembers: []*string{ + // to.Ptr("coordinator")}, + // RequiredZoneNames: []*string{ + // to.Ptr("privatelink.testcluster.postgres.database.azure.com")}, + // }, + // }, + // { + // Name: to.Ptr("worker-0"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/privateLinkResources"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateLinkResources/worker-0"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.PrivateLinkResourceProperties{ + // GroupID: to.Ptr("worker-0"), + // RequiredMembers: []*string{ + // to.Ptr("worker-0")}, + // RequiredZoneNames: []*string{ + // to.Ptr("privatelink.testcluster.postgres.database.azure.com")}, + // }, + // }}, + // } + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/PrivateLinkResourcesGet.json +func ExamplePrivateLinkResourcesClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewPrivateLinkResourcesClient().Get(ctx, "TestGroup", "testcluster", "plr", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.PrivateLinkResource = armcosmosforpostgresql.PrivateLinkResource{ + // Name: to.Ptr("plr"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/privateLinkResources"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestResourceGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster/privateLinkResources/plr"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2022-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.PrivateLinkResourceProperties{ + // GroupID: to.Ptr("coordinator"), + // RequiredMembers: []*string{ + // to.Ptr("coordinator")}, + // RequiredZoneNames: []*string{ + // to.Ptr("privatelink.testcluster.postgres.database.azure.com")}, + // }, + // } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/response_types.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/response_types.go new file mode 100644 index 000000000000..2953cbdda3bf --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/response_types.go @@ -0,0 +1,185 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +// ClustersClientCheckNameAvailabilityResponse contains the response from method ClustersClient.CheckNameAvailability. +type ClustersClientCheckNameAvailabilityResponse struct { + NameAvailability +} + +// ClustersClientCreateResponse contains the response from method ClustersClient.BeginCreate. +type ClustersClientCreateResponse struct { + Cluster +} + +// ClustersClientDeleteResponse contains the response from method ClustersClient.BeginDelete. +type ClustersClientDeleteResponse struct { + // placeholder for future response values +} + +// ClustersClientGetResponse contains the response from method ClustersClient.Get. +type ClustersClientGetResponse struct { + Cluster +} + +// ClustersClientListByResourceGroupResponse contains the response from method ClustersClient.NewListByResourceGroupPager. +type ClustersClientListByResourceGroupResponse struct { + ClusterListResult +} + +// ClustersClientListResponse contains the response from method ClustersClient.NewListPager. +type ClustersClientListResponse struct { + ClusterListResult +} + +// ClustersClientPromoteReadReplicaResponse contains the response from method ClustersClient.BeginPromoteReadReplica. +type ClustersClientPromoteReadReplicaResponse struct { + // placeholder for future response values +} + +// ClustersClientRestartResponse contains the response from method ClustersClient.BeginRestart. +type ClustersClientRestartResponse struct { + // placeholder for future response values +} + +// ClustersClientStartResponse contains the response from method ClustersClient.BeginStart. +type ClustersClientStartResponse struct { + // placeholder for future response values +} + +// ClustersClientStopResponse contains the response from method ClustersClient.BeginStop. +type ClustersClientStopResponse struct { + // placeholder for future response values +} + +// ClustersClientUpdateResponse contains the response from method ClustersClient.BeginUpdate. +type ClustersClientUpdateResponse struct { + Cluster +} + +// ConfigurationsClientGetCoordinatorResponse contains the response from method ConfigurationsClient.GetCoordinator. +type ConfigurationsClientGetCoordinatorResponse struct { + ServerConfiguration +} + +// ConfigurationsClientGetNodeResponse contains the response from method ConfigurationsClient.GetNode. +type ConfigurationsClientGetNodeResponse struct { + ServerConfiguration +} + +// ConfigurationsClientGetResponse contains the response from method ConfigurationsClient.Get. +type ConfigurationsClientGetResponse struct { + Configuration +} + +// ConfigurationsClientListByClusterResponse contains the response from method ConfigurationsClient.NewListByClusterPager. +type ConfigurationsClientListByClusterResponse struct { + ClusterConfigurationListResult +} + +// ConfigurationsClientListByServerResponse contains the response from method ConfigurationsClient.NewListByServerPager. +type ConfigurationsClientListByServerResponse struct { + ServerConfigurationListResult +} + +// ConfigurationsClientUpdateOnCoordinatorResponse contains the response from method ConfigurationsClient.BeginUpdateOnCoordinator. +type ConfigurationsClientUpdateOnCoordinatorResponse struct { + ServerConfiguration +} + +// ConfigurationsClientUpdateOnNodeResponse contains the response from method ConfigurationsClient.BeginUpdateOnNode. +type ConfigurationsClientUpdateOnNodeResponse struct { + ServerConfiguration +} + +// FirewallRulesClientCreateOrUpdateResponse contains the response from method FirewallRulesClient.BeginCreateOrUpdate. +type FirewallRulesClientCreateOrUpdateResponse struct { + FirewallRule +} + +// FirewallRulesClientDeleteResponse contains the response from method FirewallRulesClient.BeginDelete. +type FirewallRulesClientDeleteResponse struct { + // placeholder for future response values +} + +// FirewallRulesClientGetResponse contains the response from method FirewallRulesClient.Get. +type FirewallRulesClientGetResponse struct { + FirewallRule +} + +// FirewallRulesClientListByClusterResponse contains the response from method FirewallRulesClient.NewListByClusterPager. +type FirewallRulesClientListByClusterResponse struct { + FirewallRuleListResult +} + +// OperationsClientListResponse contains the response from method OperationsClient.NewListPager. +type OperationsClientListResponse struct { + OperationListResult +} + +// PrivateEndpointConnectionsClientCreateOrUpdateResponse contains the response from method PrivateEndpointConnectionsClient.BeginCreateOrUpdate. +type PrivateEndpointConnectionsClientCreateOrUpdateResponse struct { + PrivateEndpointConnection +} + +// PrivateEndpointConnectionsClientDeleteResponse contains the response from method PrivateEndpointConnectionsClient.BeginDelete. +type PrivateEndpointConnectionsClientDeleteResponse struct { + // placeholder for future response values +} + +// PrivateEndpointConnectionsClientGetResponse contains the response from method PrivateEndpointConnectionsClient.Get. +type PrivateEndpointConnectionsClientGetResponse struct { + PrivateEndpointConnection +} + +// PrivateEndpointConnectionsClientListByClusterResponse contains the response from method PrivateEndpointConnectionsClient.NewListByClusterPager. +type PrivateEndpointConnectionsClientListByClusterResponse struct { + PrivateEndpointConnectionListResult +} + +// PrivateLinkResourcesClientGetResponse contains the response from method PrivateLinkResourcesClient.Get. +type PrivateLinkResourcesClientGetResponse struct { + PrivateLinkResource +} + +// PrivateLinkResourcesClientListByClusterResponse contains the response from method PrivateLinkResourcesClient.NewListByClusterPager. +type PrivateLinkResourcesClientListByClusterResponse struct { + PrivateLinkResourceListResult +} + +// RolesClientCreateResponse contains the response from method RolesClient.BeginCreate. +type RolesClientCreateResponse struct { + Role +} + +// RolesClientDeleteResponse contains the response from method RolesClient.BeginDelete. +type RolesClientDeleteResponse struct { + // placeholder for future response values +} + +// RolesClientGetResponse contains the response from method RolesClient.Get. +type RolesClientGetResponse struct { + Role +} + +// RolesClientListByClusterResponse contains the response from method RolesClient.NewListByClusterPager. +type RolesClientListByClusterResponse struct { + RoleListResult +} + +// ServersClientGetResponse contains the response from method ServersClient.Get. +type ServersClientGetResponse struct { + ClusterServer +} + +// ServersClientListByClusterResponse contains the response from method ServersClient.NewListByClusterPager. +type ServersClientListByClusterResponse struct { + ClusterServerListResult +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/roles_client.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/roles_client.go new file mode 100644 index 000000000000..88d255ca63ac --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/roles_client.go @@ -0,0 +1,301 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "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 { + internal *arm.Client + subscriptionID string +} + +// NewRolesClient creates a new instance of RolesClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewRolesClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*RolesClient, error) { + cl, err := arm.NewClient(moduleName+".RolesClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &RolesClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// BeginCreate - Creates a new role or updates an existing role. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - roleName - The name of the cluster role. +// - parameters - The required parameters for creating or updating a role. +// - options - RolesClientBeginCreateOptions contains the optional parameters for the RolesClient.BeginCreate method. +func (client *RolesClient) BeginCreate(ctx context.Context, resourceGroupName string, clusterName string, roleName string, parameters Role, options *RolesClientBeginCreateOptions) (*runtime.Poller[RolesClientCreateResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.create(ctx, resourceGroupName, clusterName, roleName, parameters, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RolesClientCreateResponse]{ + FinalStateVia: runtime.FinalStateViaAzureAsyncOp, + }) + } else { + return runtime.NewPollerFromResumeToken[RolesClientCreateResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Create - Creates a new role or updates an existing role. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *RolesClient) create(ctx context.Context, resourceGroupName string, clusterName string, roleName string, parameters Role, options *RolesClientBeginCreateOptions) (*http.Response, error) { + req, err := client.createCreateRequest(ctx, resourceGroupName, clusterName, roleName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// createCreateRequest creates the Create request. +func (client *RolesClient) createCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, roleName string, parameters Role, options *RolesClientBeginCreateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, runtime.MarshalAsJSON(req, parameters) +} + +// BeginDelete - Deletes a cluster role. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - roleName - The name of the cluster role. +// - options - RolesClientBeginDeleteOptions contains the optional parameters for the RolesClient.BeginDelete method. +func (client *RolesClient) BeginDelete(ctx context.Context, resourceGroupName string, clusterName string, roleName string, options *RolesClientBeginDeleteOptions) (*runtime.Poller[RolesClientDeleteResponse], error) { + if options == nil || options.ResumeToken == "" { + resp, err := client.deleteOperation(ctx, resourceGroupName, clusterName, roleName, options) + if err != nil { + return nil, err + } + return runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[RolesClientDeleteResponse]{ + FinalStateVia: runtime.FinalStateViaLocation, + }) + } else { + return runtime.NewPollerFromResumeToken[RolesClientDeleteResponse](options.ResumeToken, client.internal.Pipeline(), nil) + } +} + +// Delete - Deletes a cluster role. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +func (client *RolesClient) deleteOperation(ctx context.Context, resourceGroupName string, clusterName string, roleName string, options *RolesClientBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, clusterName, roleName, options) + if err != nil { + return nil, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusAccepted, http.StatusNoContent) { + return nil, runtime.NewResponseError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *RolesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, roleName string, options *RolesClientBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// Get - Gets information about a cluster role. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - roleName - The name of the cluster role. +// - options - RolesClientGetOptions contains the optional parameters for the RolesClient.Get method. +func (client *RolesClient) Get(ctx context.Context, resourceGroupName string, clusterName string, roleName string, options *RolesClientGetOptions) (RolesClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, clusterName, roleName, options) + if err != nil { + return RolesClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return RolesClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return RolesClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *RolesClient) getCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, roleName string, options *RolesClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *RolesClient) getHandleResponse(resp *http.Response) (RolesClientGetResponse, error) { + result := RolesClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.Role); err != nil { + return RolesClientGetResponse{}, err + } + return result, nil +} + +// NewListByClusterPager - List all the roles in a given cluster. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - RolesClientListByClusterOptions contains the optional parameters for the RolesClient.NewListByClusterPager method. +func (client *RolesClient) NewListByClusterPager(resourceGroupName string, clusterName string, options *RolesClientListByClusterOptions) *runtime.Pager[RolesClientListByClusterResponse] { + return runtime.NewPager(runtime.PagingHandler[RolesClientListByClusterResponse]{ + More: func(page RolesClientListByClusterResponse) bool { + return false + }, + Fetcher: func(ctx context.Context, page *RolesClientListByClusterResponse) (RolesClientListByClusterResponse, error) { + req, err := client.listByClusterCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return RolesClientListByClusterResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return RolesClientListByClusterResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return RolesClientListByClusterResponse{}, runtime.NewResponseError(resp) + } + return client.listByClusterHandleResponse(resp) + }, + }) +} + +// listByClusterCreateRequest creates the ListByCluster request. +func (client *RolesClient) listByClusterCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *RolesClientListByClusterOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByClusterHandleResponse handles the ListByCluster response. +func (client *RolesClient) listByClusterHandleResponse(resp *http.Response) (RolesClientListByClusterResponse, error) { + result := RolesClientListByClusterResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.RoleListResult); err != nil { + return RolesClientListByClusterResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/roles_client_example_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/roles_client_example_test.go new file mode 100644 index 000000000000..4d825705f82e --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/roles_client_example_test.go @@ -0,0 +1,180 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/RoleGet.json +func ExampleRolesClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewRolesClient().Get(ctx, "TestGroup", "pgtestsvc4", "role1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Role = armcosmosforpostgresql.Role{ + // Name: to.Ptr("role1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/roles"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/roles/role1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.RoleProperties{ + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/RoleCreate.json +func ExampleRolesClient_BeginCreate() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewRolesClient().BeginCreate(ctx, "TestGroup", "pgtestsvc4", "role1", armcosmosforpostgresql.Role{ + Properties: &armcosmosforpostgresql.RoleProperties{ + Password: to.Ptr("password"), + }, + }, nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + res, err := poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.Role = armcosmosforpostgresql.Role{ + // Name: to.Ptr("role1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/roles"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/roles/role1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.RoleProperties{ + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // }, + // } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/RoleDelete.json +func ExampleRolesClient_BeginDelete() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + poller, err := clientFactory.NewRolesClient().BeginDelete(ctx, "TestGroup", "pgtestsvc4", "role1", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + _, err = poller.PollUntilDone(ctx, nil) + if err != nil { + log.Fatalf("failed to pull the result: %v", err) + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/RoleListByCluster.json +func ExampleRolesClient_NewListByClusterPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewRolesClient().NewListByClusterPager("TestGroup", "pgtestsvc4", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.RoleListResult = armcosmosforpostgresql.RoleListResult{ + // Value: []*armcosmosforpostgresql.Role{ + // { + // Name: to.Ptr("role1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/roles"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/roles/role1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.RoleProperties{ + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // }, + // }, + // { + // Name: to.Ptr("role2"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/roles"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/pgtestsvc4/roles/role2"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.RoleProperties{ + // ProvisioningState: to.Ptr(armcosmosforpostgresql.ProvisioningStateSucceeded), + // }, + // }}, + // } + } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/servers_client.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/servers_client.go new file mode 100644 index 000000000000..095e3747168c --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/servers_client.go @@ -0,0 +1,165 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "context" + "errors" + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "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 { + internal *arm.Client + subscriptionID string +} + +// NewServersClient creates a new instance of ServersClient with the specified values. +// - subscriptionID - The ID of the target subscription. The value must be an UUID. +// - credential - used to authorize requests. Usually a credential from azidentity. +// - options - pass nil to accept the default values. +func NewServersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*ServersClient, error) { + cl, err := arm.NewClient(moduleName+".ServersClient", moduleVersion, credential, options) + if err != nil { + return nil, err + } + client := &ServersClient{ + subscriptionID: subscriptionID, + internal: cl, + } + return client, nil +} + +// Get - Gets information about a server in cluster. +// If the operation fails it returns an *azcore.ResponseError type. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - serverName - The name of the server. +// - options - ServersClientGetOptions contains the optional parameters for the ServersClient.Get method. +func (client *ServersClient) Get(ctx context.Context, resourceGroupName string, clusterName string, serverName string, options *ServersClientGetOptions) (ServersClientGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, clusterName, serverName, options) + if err != nil { + return ServersClientGetResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ServersClientGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ServersClientGetResponse{}, runtime.NewResponseError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ServersClient) getCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, serverName string, options *ServersClientGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers/{serverName}" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + 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.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ServersClient) getHandleResponse(resp *http.Response) (ServersClientGetResponse, error) { + result := ServersClientGetResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ClusterServer); err != nil { + return ServersClientGetResponse{}, err + } + return result, nil +} + +// NewListByClusterPager - Lists servers of a cluster. +// +// Generated from API version 2022-11-08 +// - resourceGroupName - The name of the resource group. The name is case insensitive. +// - clusterName - The name of the cluster. +// - options - ServersClientListByClusterOptions contains the optional parameters for the ServersClient.NewListByClusterPager +// method. +func (client *ServersClient) NewListByClusterPager(resourceGroupName string, clusterName string, options *ServersClientListByClusterOptions) *runtime.Pager[ServersClientListByClusterResponse] { + return runtime.NewPager(runtime.PagingHandler[ServersClientListByClusterResponse]{ + More: func(page ServersClientListByClusterResponse) bool { + return false + }, + Fetcher: func(ctx context.Context, page *ServersClientListByClusterResponse) (ServersClientListByClusterResponse, error) { + req, err := client.listByClusterCreateRequest(ctx, resourceGroupName, clusterName, options) + if err != nil { + return ServersClientListByClusterResponse{}, err + } + resp, err := client.internal.Pipeline().Do(req) + if err != nil { + return ServersClientListByClusterResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ServersClientListByClusterResponse{}, runtime.NewResponseError(resp) + } + return client.listByClusterHandleResponse(resp) + }, + }) +} + +// listByClusterCreateRequest creates the ListByCluster request. +func (client *ServersClient) listByClusterCreateRequest(ctx context.Context, resourceGroupName string, clusterName string, options *ServersClientListByClusterOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers" + 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 clusterName == "" { + return nil, errors.New("parameter clusterName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{clusterName}", url.PathEscape(clusterName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2022-11-08") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header["Accept"] = []string{"application/json"} + return req, nil +} + +// listByClusterHandleResponse handles the ListByCluster response. +func (client *ServersClient) listByClusterHandleResponse(resp *http.Response) (ServersClientListByClusterResponse, error) { + result := ServersClientListByClusterResponse{} + if err := runtime.UnmarshalAsJSON(resp, &result.ClusterServerListResult); err != nil { + return ServersClientListByClusterResponse{}, err + } + return result, nil +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/servers_client_example_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/servers_client_example_test.go new file mode 100644 index 000000000000..9e20b5dcf596 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/servers_client_example_test.go @@ -0,0 +1,182 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql_test + +import ( + "context" + "log" + + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" +) + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ServerListByCluster.json +func ExampleServersClient_NewListByClusterPager() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + pager := clientFactory.NewServersClient().NewListByClusterPager("TestGroup", "testcluster1", nil) + for pager.More() { + page, err := pager.NextPage(ctx) + if err != nil { + log.Fatalf("failed to advance page: %v", err) + } + for _, v := range page.Value { + // You could use page here. We use blank identifier for just demo purposes. + _ = v + } + // If the HTTP response code is 200 as defined in example definition, your page structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // page.ClusterServerListResult = armcosmosforpostgresql.ClusterServerListResult{ + // Value: []*armcosmosforpostgresql.ClusterServer{ + // { + // Name: to.Ptr("testcluster1-c"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1/servers/testcluster1-c"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ClusterServerProperties{ + // AdministratorLogin: to.Ptr("citus"), + // EnableHa: to.Ptr(true), + // EnablePublicIPAccess: to.Ptr(true), + // IsReadOnly: to.Ptr(false), + // ServerEdition: to.Ptr("MemoryOptimized"), + // StorageQuotaInMb: to.Ptr[int32](10000), + // VCores: to.Ptr[int32](4), + // AvailabilityZone: to.Ptr("1"), + // CitusVersion: to.Ptr("9.5"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // HaState: to.Ptr("Healthy"), + // PostgresqlVersion: to.Ptr("12"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleCoordinator), + // State: to.Ptr("Ready"), + // }, + // }, + // { + // Name: to.Ptr("testcluster1-w0"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1/servers/testcluster1-w0"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ClusterServerProperties{ + // AdministratorLogin: to.Ptr("citus"), + // EnableHa: to.Ptr(false), + // EnablePublicIPAccess: to.Ptr(false), + // IsReadOnly: to.Ptr(false), + // ServerEdition: to.Ptr("MemoryOptimized"), + // StorageQuotaInMb: to.Ptr[int32](10000), + // VCores: to.Ptr[int32](4), + // AvailabilityZone: to.Ptr("1"), + // CitusVersion: to.Ptr("9.5"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w0.postgres.database.azure.com"), + // HaState: to.Ptr("NotEnabled"), + // PostgresqlVersion: to.Ptr("12"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleWorker), + // State: to.Ptr("Ready"), + // }, + // }, + // { + // Name: to.Ptr("testcluster1-w1"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1/servers/testcluster1-w1"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ClusterServerProperties{ + // AdministratorLogin: to.Ptr("citus"), + // EnableHa: to.Ptr(false), + // EnablePublicIPAccess: to.Ptr(false), + // IsReadOnly: to.Ptr(false), + // ServerEdition: to.Ptr("MemoryOptimized"), + // StorageQuotaInMb: to.Ptr[int32](10000), + // VCores: to.Ptr[int32](4), + // AvailabilityZone: to.Ptr("1"), + // CitusVersion: to.Ptr("9.5"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-w1.postgres.database.azure.com"), + // HaState: to.Ptr("NotEnabled"), + // PostgresqlVersion: to.Ptr("12"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleWorker), + // State: to.Ptr("Ready"), + // }, + // }}, + // } + } +} + +// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/Microsoft.DBforPostgreSQL/stable/2022-11-08/examples/ServerGet.json +func ExampleServersClient_Get() { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + log.Fatalf("failed to obtain a credential: %v", err) + } + ctx := context.Background() + clientFactory, err := armcosmosforpostgresql.NewClientFactory("", cred, nil) + if err != nil { + log.Fatalf("failed to create client: %v", err) + } + res, err := clientFactory.NewServersClient().Get(ctx, "TestGroup", "testcluster1", "testcluster1-c", nil) + if err != nil { + log.Fatalf("failed to finish the request: %v", err) + } + // You could use response here. We use blank identifier for just demo purposes. + _ = res + // If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes. + // res.ClusterServer = armcosmosforpostgresql.ClusterServer{ + // Name: to.Ptr("testcluster1-c"), + // Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2/servers"), + // ID: to.Ptr("/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/TestGroup/providers/Microsoft.DBforPostgreSQL/serverGroupsv2/testcluster1/servers/testcluster1-c"), + // SystemData: &armcosmosforpostgresql.SystemData{ + // CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-01T17:18:19.1234567Z"); return t}()), + // CreatedBy: to.Ptr("user1"), + // CreatedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2020-01-02T17:18:19.1234567Z"); return t}()), + // LastModifiedBy: to.Ptr("user2"), + // LastModifiedByType: to.Ptr(armcosmosforpostgresql.CreatedByTypeUser), + // }, + // Properties: &armcosmosforpostgresql.ClusterServerProperties{ + // AdministratorLogin: to.Ptr("citus"), + // EnableHa: to.Ptr(true), + // EnablePublicIPAccess: to.Ptr(true), + // IsReadOnly: to.Ptr(false), + // ServerEdition: to.Ptr("MemoryOptimized"), + // StorageQuotaInMb: to.Ptr[int32](10000), + // VCores: to.Ptr[int32](4), + // AvailabilityZone: to.Ptr("1"), + // CitusVersion: to.Ptr("9.5"), + // FullyQualifiedDomainName: to.Ptr("testcluster1-c.postgres.database.azure.com"), + // HaState: to.Ptr("Healthy"), + // PostgresqlVersion: to.Ptr("12"), + // Role: to.Ptr(armcosmosforpostgresql.ServerRoleCoordinator), + // State: to.Ptr("Ready"), + // }, + // } +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/time_rfc3339.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/time_rfc3339.go new file mode 100644 index 000000000000..578ba20c8ff0 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/time_rfc3339.go @@ -0,0 +1,87 @@ +//go:build go1.18 +// +build go1.18 + +// 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. +// DO NOT EDIT. + +package armcosmosforpostgresql + +import ( + "encoding/json" + "fmt" + "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]any, 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, fn string, 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 fmt.Errorf("struct field %s: %v", fn, err) + } + *t = (*time.Time)(&aux) + return nil +} From e556a4050347c4f843be3b57cf20c5041b7413ad Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Tue, 6 Jun 2023 10:04:45 +0800 Subject: [PATCH 2/6] replace version to v0.1.0 --- .../cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md | 2 +- .../cosmosforpostgresql/armcosmosforpostgresql/autorest.md | 2 +- .../cosmosforpostgresql/armcosmosforpostgresql/constants.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md index 4e7cd155f72b..c667e9a49946 100644 --- a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.0.0 (2023-06-23) +## 0.1.0 (2023-06-23) The package of `github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql` is using our [next generation design principles](https://azure.github.io/azure-sdk/general_introduction.html). diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/autorest.md b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/autorest.md index 8003e412260c..287f406a9a88 100644 --- a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/autorest.md +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/autorest.md @@ -8,6 +8,6 @@ require: - https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/readme.md - https://github.com/Azure/azure-rest-api-specs/blob/0d41e635294dce73dfa99b07f3da4b68a9c9e29c/specification/postgresqlhsc/resource-manager/readme.go.md license-header: MICROSOFT_MIT_NO_VERSION -module-version: 1.0.0 +module-version: 0.1.0 tag: package-2022-11-08 ``` \ No newline at end of file diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/constants.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/constants.go index cc0349e6099b..6063c1b1a9f1 100644 --- a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/constants.go +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/constants.go @@ -11,7 +11,7 @@ package armcosmosforpostgresql const ( moduleName = "armcosmosforpostgresql" - moduleVersion = "v1.0.0" + moduleVersion = "v0.1.0" ) // ConfigurationDataType - Data type of the configuration. From 5889eda4ff6453162aba66fd709aeb972d1d3be1 Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Fri, 9 Jun 2023 10:15:05 +0800 Subject: [PATCH 3/6] add sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql live test --- .../armcosmosforpostgresql/assets.json | 6 + .../armcosmosforpostgresql/go.mod | 10 +- .../armcosmosforpostgresql/go.sum | 17 + .../postgresqlhsc_live_test.go | 557 ++++++++++++++++++ 4 files changed, 589 insertions(+), 1 deletion(-) create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/postgresqlhsc_live_test.go diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json new file mode 100644 index 000000000000..c1bd14f7bb56 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "go", + "TagPrefix": "go/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql", + "Tag": "go/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql_80a4293735" +} diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.mod b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.mod index d19c72cf3eb4..7312ab1d4376 100644 --- a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.mod +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.mod @@ -5,17 +5,25 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.6.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 + github.com/stretchr/testify v1.7.0 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.2.0 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/google/uuid v1.3.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/crypto v0.7.0 // indirect golang.org/x/net v0.8.0 // indirect golang.org/x/sys v0.6.0 // indirect golang.org/x/text v0.8.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.sum b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.sum index 21718b486698..688a9b2402b0 100644 --- a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.sum +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/go.sum @@ -4,20 +4,31 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0 h1:vcYCAze6p19qBW7MhZybI github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.0/go.mod h1:OQeznEEkTZ9OrhHJoDD8ZDq51FHgXjqtP9z6bEwBq9U= github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY= github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s= github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY= github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= 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.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= @@ -27,5 +38,11 @@ golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/postgresqlhsc_live_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/postgresqlhsc_live_test.go new file mode 100644 index 000000000000..5976195930c4 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/postgresqlhsc_live_test.go @@ -0,0 +1,557 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package armcosmosforpostgresql_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/stretchr/testify/suite" +) + +type PostgresqlhscTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + clusterId string + clusterName string + firewallRuleName string + roleName string + adminPassword string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *PostgresqlhscTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.clusterName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "clustern", 14, true) + testsuite.firewallRuleName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "firewall", 14, false) + testsuite.roleName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "rolename", 14, true) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + testsuite.location = testutil.GetEnv("LOCATION", "westus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *PostgresqlhscTestSuite) TearDownSuite() { + testsuite.Cleanup() + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestPostgresqlhscTestSuite(t *testing.T) { + suite.Run(t, new(PostgresqlhscTestSuite)) +} + +func (testsuite *PostgresqlhscTestSuite) Prepare() { + var err error + // From step Clusters_CheckNameAvailability + fmt.Println("Call operation: Clusters_CheckNameAvailability") + clustersClient, err := armcosmosforpostgresql.NewClustersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = clustersClient.CheckNameAvailability(testsuite.ctx, armcosmosforpostgresql.NameAvailabilityRequest{ + Name: to.Ptr("name1"), + Type: to.Ptr("Microsoft.DBforPostgreSQL/serverGroupsv2"), + }, nil) + testsuite.Require().NoError(err) + + // From step Clusters_Create + fmt.Println("Call operation: Clusters_Create") + clustersClientCreateResponsePoller, err := clustersClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, armcosmosforpostgresql.Cluster{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmosforpostgresql.ClusterProperties{ + AdministratorLoginPassword: to.Ptr(testsuite.adminPassword), + CitusVersion: to.Ptr("11.1"), + CoordinatorEnablePublicIPAccess: to.Ptr(true), + CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + CoordinatorVCores: to.Ptr[int32](4), + EnableHa: to.Ptr(true), + EnableShardsOnCoordinator: to.Ptr(false), + NodeCount: to.Ptr[int32](3), + NodeEnablePublicIPAccess: to.Ptr(false), + NodeServerEdition: to.Ptr("MemoryOptimized"), + NodeStorageQuotaInMb: to.Ptr[int32](524288), + NodeVCores: to.Ptr[int32](8), + PostgresqlVersion: to.Ptr("15"), + PreferredPrimaryZone: to.Ptr("1"), + }, + }, nil) + testsuite.Require().NoError(err) + var clustersClientCreateResponse *armcosmosforpostgresql.ClustersClientCreateResponse + clustersClientCreateResponse, err = testutil.PollForTest(testsuite.ctx, clustersClientCreateResponsePoller) + testsuite.Require().NoError(err) + testsuite.clusterId = *clustersClientCreateResponse.ID +} + +// Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName} +func (testsuite *PostgresqlhscTestSuite) TestClusters() { + var err error + // From step Clusters_List + fmt.Println("Call operation: Clusters_List") + clustersClient, err := armcosmosforpostgresql.NewClustersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + clustersClientNewListPager := clustersClient.NewListPager(nil) + for clustersClientNewListPager.More() { + _, err := clustersClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Clusters_ListByResourceGroup + fmt.Println("Call operation: Clusters_ListByResourceGroup") + clustersClientNewListByResourceGroupPager := clustersClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for clustersClientNewListByResourceGroupPager.More() { + _, err := clustersClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Clusters_Get + fmt.Println("Call operation: Clusters_Get") + _, err = clustersClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, nil) + testsuite.Require().NoError(err) + + // From step Clusters_Update + fmt.Println("Call operation: Clusters_Update") + clustersClientUpdateResponsePoller, err := clustersClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, armcosmosforpostgresql.ClusterForUpdate{}, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, clustersClientUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step Clusters_Stop + fmt.Println("Call operation: Clusters_Stop") + clustersClientStopResponsePoller, err := clustersClient.BeginStop(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, clustersClientStopResponsePoller) + testsuite.Require().NoError(err) + + // From step Clusters_Start + fmt.Println("Call operation: Clusters_Start") + clustersClientStartResponsePoller, err := clustersClient.BeginStart(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, clustersClientStartResponsePoller) + testsuite.Require().NoError(err) + + // From step Clusters_Restart + fmt.Println("Call operation: Clusters_Restart") + clustersClientRestartResponsePoller, err := clustersClient.BeginRestart(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, clustersClientRestartResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/firewallRules/{firewallRuleName} +func (testsuite *PostgresqlhscTestSuite) TestFirewallRules() { + var err error + // From step FirewallRules_CreateOrUpdate + fmt.Println("Call operation: FirewallRules_CreateOrUpdate") + firewallRulesClient, err := armcosmosforpostgresql.NewFirewallRulesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + firewallRulesClientCreateOrUpdateResponsePoller, err := firewallRulesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.firewallRuleName, armcosmosforpostgresql.FirewallRule{ + Properties: &armcosmosforpostgresql.FirewallRuleProperties{ + EndIPAddress: to.Ptr("255.255.255.255"), + StartIPAddress: to.Ptr("0.0.0.0"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, firewallRulesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step FirewallRules_ListByCluster + fmt.Println("Call operation: FirewallRules_ListByCluster") + firewallRulesClientNewListByClusterPager := firewallRulesClient.NewListByClusterPager(testsuite.resourceGroupName, testsuite.clusterName, nil) + for firewallRulesClientNewListByClusterPager.More() { + _, err := firewallRulesClientNewListByClusterPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step FirewallRules_Get + fmt.Println("Call operation: FirewallRules_Get") + _, err = firewallRulesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.firewallRuleName, nil) + testsuite.Require().NoError(err) + + // From step FirewallRules_Delete + fmt.Println("Call operation: FirewallRules_Delete") + firewallRulesClientDeleteResponsePoller, err := firewallRulesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.firewallRuleName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, firewallRulesClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/roles/{roleName} +func (testsuite *PostgresqlhscTestSuite) TestRoles() { + var err error + // From step Roles_Create + fmt.Println("Call operation: Roles_Create") + rolesClient, err := armcosmosforpostgresql.NewRolesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + rolesClientCreateResponsePoller, err := rolesClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.roleName, armcosmosforpostgresql.Role{ + Properties: &armcosmosforpostgresql.RoleProperties{ + Password: to.Ptr(testsuite.adminPassword), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, rolesClientCreateResponsePoller) + testsuite.Require().NoError(err) + + // From step Roles_ListByCluster + fmt.Println("Call operation: Roles_ListByCluster") + rolesClientNewListByClusterPager := rolesClient.NewListByClusterPager(testsuite.resourceGroupName, testsuite.clusterName, nil) + for rolesClientNewListByClusterPager.More() { + _, err := rolesClientNewListByClusterPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Roles_Get + fmt.Println("Call operation: Roles_Get") + _, err = rolesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.roleName, nil) + testsuite.Require().NoError(err) + + // From step Roles_Delete + fmt.Println("Call operation: Roles_Delete") + rolesClientDeleteResponsePoller, err := rolesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, testsuite.roleName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, rolesClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/privateEndpointConnections/{privateEndpointConnectionName} +func (testsuite *PostgresqlhscTestSuite) TestPrivateEndpointConnections() { + var err error + var privateEndpointConnectionName string + var privateLinkResourceName string + // From step Create_PrivateEndpoint + template := map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": map[string]any{ + "clusterId": map[string]any{ + "type": "string", + "defaultValue": testsuite.clusterId, + }, + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "networkInterfaceName": map[string]any{ + "type": "string", + "defaultValue": "endpointpgsqlhsc-nic", + }, + "privateEndpointName": map[string]any{ + "type": "string", + "defaultValue": "endpointpgsqlhsc", + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": "pgsqlhscvnet", + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworksName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2020-11-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "enableDdosProtection": false, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + "delegations": []any{}, + "privateEndpointNetworkPolicies": "Disabled", + "privateLinkServiceNetworkPolicies": "Enabled", + }, + }, + }, + "virtualNetworkPeerings": []any{}, + }, + }, + map[string]any{ + "name": "[parameters('networkInterfaceName')]", + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "dnsSettings": map[string]any{ + "dnsServers": []any{}, + }, + "enableIPForwarding": false, + "ipConfigurations": []any{ + map[string]any{ + "name": "privateEndpointIpConfig", + "properties": map[string]any{ + "primary": true, + "privateIPAddress": "10.0.0.4", + "privateIPAddressVersion": "IPv4", + "privateIPAllocationMethod": "Dynamic", + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + }, + }, + }, + }, + }, + map[string]any{ + "name": "[parameters('privateEndpointName')]", + "type": "Microsoft.Network/privateEndpoints", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "customDnsConfigs": []any{}, + "manualPrivateLinkServiceConnections": []any{}, + "privateLinkServiceConnections": []any{ + map[string]any{ + "name": "[parameters('privateEndpointName')]", + "properties": map[string]any{ + "groupIds": []any{ + "coordinator", + }, + "privateLinkServiceConnectionState": map[string]any{ + "description": "Auto-Approved", + "actionsRequired": "None", + "status": "Approved", + }, + "privateLinkServiceId": "[parameters('clusterId')]", + }, + }, + }, + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + }, + }, + map[string]any{ + "name": "[concat(parameters('virtualNetworksName'), '/default')]", + "type": "Microsoft.Network/virtualNetworks/subnets", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + "delegations": []any{}, + "privateEndpointNetworkPolicies": "Disabled", + "privateLinkServiceNetworkPolicies": "Enabled", + }, + }, + }, + "variables": map[string]any{}, + } + deployment := armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + _, err = testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_PrivateEndpoint", &deployment) + testsuite.Require().NoError(err) + + // From step PrivateEndpointConnections_ListByCluster + fmt.Println("Call operation: PrivateEndpointConnections_ListByCluster") + privateEndpointConnectionsClient, err := armcosmosforpostgresql.NewPrivateEndpointConnectionsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + privateEndpointConnectionsClientNewListByClusterPager := privateEndpointConnectionsClient.NewListByClusterPager(testsuite.resourceGroupName, testsuite.clusterName, nil) + for privateEndpointConnectionsClientNewListByClusterPager.More() { + privateEndpointConnectionsClientListByClusterResponse, err := privateEndpointConnectionsClientNewListByClusterPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + privateEndpointConnectionName = *privateEndpointConnectionsClientListByClusterResponse.Value[0].Name + break + } + + // From step PrivateEndpointConnections_CreateOrUpdate + fmt.Println("Call operation: PrivateEndpointConnections_CreateOrUpdate") + privateEndpointConnectionsClientCreateOrUpdateResponsePoller, err := privateEndpointConnectionsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, privateEndpointConnectionName, armcosmosforpostgresql.PrivateEndpointConnection{ + Properties: &armcosmosforpostgresql.PrivateEndpointConnectionProperties{ + PrivateLinkServiceConnectionState: &armcosmosforpostgresql.PrivateLinkServiceConnectionState{ + Description: to.Ptr("Approved by johndoe@contoso.com"), + Status: to.Ptr(armcosmosforpostgresql.PrivateEndpointServiceConnectionStatusRejected), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, privateEndpointConnectionsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step PrivateEndpointConnections_Get + fmt.Println("Call operation: PrivateEndpointConnections_Get") + _, err = privateEndpointConnectionsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, privateEndpointConnectionName, nil) + testsuite.Require().NoError(err) + + // From step PrivateLinkResources_ListByCluster + fmt.Println("Call operation: PrivateLinkResources_ListByCluster") + privateLinkResourcesClient, err := armcosmosforpostgresql.NewPrivateLinkResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + privateLinkResourcesClientNewListByClusterPager := privateLinkResourcesClient.NewListByClusterPager(testsuite.resourceGroupName, testsuite.clusterName, nil) + for privateLinkResourcesClientNewListByClusterPager.More() { + privateLinkResourcesClientListByClusterResponse, err := privateLinkResourcesClientNewListByClusterPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + privateLinkResourceName = *privateLinkResourcesClientListByClusterResponse.Value[0].Name + break + } + + // From step PrivateLinkResources_Get + fmt.Println("Call operation: PrivateLinkResources_Get") + _, err = privateLinkResourcesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, privateLinkResourceName, nil) + testsuite.Require().NoError(err) + + // From step PrivateEndpointConnections_Delete + fmt.Println("Call operation: PrivateEndpointConnections_Delete") + privateEndpointConnectionsClientDeleteResponsePoller, err := privateEndpointConnectionsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, privateEndpointConnectionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, privateEndpointConnectionsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/coordinatorConfigurations/{configurationName} +func (testsuite *PostgresqlhscTestSuite) TestConfigurations() { + var err error + var configurationName = "array_nulls" + // From step Configurations_UpdateOnCoordinator + fmt.Println("Call operation: Configurations_UpdateOnCoordinator") + configurationsClient, err := armcosmosforpostgresql.NewConfigurationsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + configurationsClientUpdateOnCoordinatorResponsePoller, err := configurationsClient.BeginUpdateOnCoordinator(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, configurationName, armcosmosforpostgresql.ServerConfiguration{ + Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + Value: to.Ptr("on"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, configurationsClientUpdateOnCoordinatorResponsePoller) + testsuite.Require().NoError(err) + + // From step Configurations_ListByCluster + fmt.Println("Call operation: Configurations_ListByCluster") + configurationsClientNewListByClusterPager := configurationsClient.NewListByClusterPager(testsuite.resourceGroupName, testsuite.clusterName, nil) + for configurationsClientNewListByClusterPager.More() { + _, err := configurationsClientNewListByClusterPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Configurations_Get + fmt.Println("Call operation: Configurations_Get") + _, err = configurationsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, configurationName, nil) + testsuite.Require().NoError(err) + + // From step Configurations_GetCoordinator + fmt.Println("Call operation: Configurations_GetCoordinator") + _, err = configurationsClient.GetCoordinator(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, configurationName, nil) + testsuite.Require().NoError(err) + + // From step Configurations_UpdateOnNode + fmt.Println("Call operation: Configurations_UpdateOnNode") + configurationsClientUpdateOnNodeResponsePoller, err := configurationsClient.BeginUpdateOnNode(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, configurationName, armcosmosforpostgresql.ServerConfiguration{ + Properties: &armcosmosforpostgresql.ServerConfigurationProperties{ + Value: to.Ptr("off"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, configurationsClientUpdateOnNodeResponsePoller) + testsuite.Require().NoError(err) + + // From step Configurations_GetNode + fmt.Println("Call operation: Configurations_GetNode") + _, err = configurationsClient.GetNode(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, configurationName, nil) + testsuite.Require().NoError(err) +} + +// Microsoft.DBforPostgreSQL/operations +func (testsuite *PostgresqlhscTestSuite) TestOperations() { + var err error + // From step Operations_List + fmt.Println("Call operation: Operations_List") + operationsClient, err := armcosmosforpostgresql.NewOperationsClient(testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + operationsClientNewListPager := operationsClient.NewListPager(nil) + for operationsClientNewListPager.More() { + _, err := operationsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +// Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName}/servers +func (testsuite *PostgresqlhscTestSuite) TestServers() { + var err error + var serverName string + // From step Servers_ListByCluster + fmt.Println("Call operation: Servers_ListByCluster") + serversClient, err := armcosmosforpostgresql.NewServersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + serversClientNewListByClusterPager := serversClient.NewListByClusterPager(testsuite.resourceGroupName, testsuite.clusterName, nil) + for serversClientNewListByClusterPager.More() { + serversClientListByClusterResponse, err := serversClientNewListByClusterPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + serverName = *serversClientListByClusterResponse.Value[0].Name + break + } + + // From step Servers_Get + fmt.Println("Call operation: Servers_Get") + _, err = serversClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, serverName, nil) + testsuite.Require().NoError(err) + + // From step Configurations_ListByServer + fmt.Println("Call operation: Configurations_ListByServer") + configurationsClient, err := armcosmosforpostgresql.NewConfigurationsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + configurationsClientNewListByServerPager := configurationsClient.NewListByServerPager(testsuite.resourceGroupName, testsuite.clusterName, serverName, nil) + for configurationsClientNewListByServerPager.More() { + _, err := configurationsClientNewListByServerPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + +func (testsuite *PostgresqlhscTestSuite) Cleanup() { + var err error + // From step Clusters_Delete + fmt.Println("Call operation: Clusters_Delete") + clustersClient, err := armcosmosforpostgresql.NewClustersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + clustersClientDeleteResponsePoller, err := clustersClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, clustersClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} From a3c2fe9f425e47453da48069476975e2171e033c Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Fri, 9 Jun 2023 14:42:09 +0800 Subject: [PATCH 4/6] add readreplica live test --- .../readreplica_live_test.go | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/readreplica_live_test.go diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/readreplica_live_test.go b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/readreplica_live_test.go new file mode 100644 index 000000000000..8fb2f0cc3381 --- /dev/null +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/readreplica_live_test.go @@ -0,0 +1,123 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package armcosmosforpostgresql_test + +import ( + "context" + "fmt" + "testing" + "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/stretchr/testify/suite" +) + +type ReadReplicaTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + clusterName string + clusterReplicaName string + adminPassword string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *ReadReplicaTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.clusterName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "clustern", 14, true) + testsuite.clusterReplicaName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "clustern", 14, true) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + testsuite.location = testutil.GetEnv("LOCATION", "westus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name +} + +func (testsuite *ReadReplicaTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestReadReplicaTestSuite(t *testing.T) { + suite.Run(t, new(ReadReplicaTestSuite)) +} + +// Microsoft.DBforPostgreSQL/serverGroupsv2/{clusterName} +func (testsuite *ReadReplicaTestSuite) TestClusters() { + var clusterId string + var err error + // From step Clusters_Create + fmt.Println("Call operation: Clusters_Create") + clustersClient, err := armcosmosforpostgresql.NewClustersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + clustersClientCreateResponsePoller, err := clustersClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterName, armcosmosforpostgresql.Cluster{ + Location: to.Ptr(testsuite.location), + Tags: map[string]*string{}, + Properties: &armcosmosforpostgresql.ClusterProperties{ + AdministratorLoginPassword: to.Ptr(testsuite.adminPassword), + CitusVersion: to.Ptr("11.1"), + CoordinatorEnablePublicIPAccess: to.Ptr(true), + CoordinatorServerEdition: to.Ptr("GeneralPurpose"), + CoordinatorStorageQuotaInMb: to.Ptr[int32](524288), + CoordinatorVCores: to.Ptr[int32](4), + EnableHa: to.Ptr(true), + EnableShardsOnCoordinator: to.Ptr(false), + NodeCount: to.Ptr[int32](3), + NodeEnablePublicIPAccess: to.Ptr(false), + NodeServerEdition: to.Ptr("MemoryOptimized"), + NodeStorageQuotaInMb: to.Ptr[int32](524288), + NodeVCores: to.Ptr[int32](8), + PostgresqlVersion: to.Ptr("15"), + PreferredPrimaryZone: to.Ptr("1"), + }, + }, nil) + testsuite.Require().NoError(err) + var clustersClientCreateResponse *armcosmosforpostgresql.ClustersClientCreateResponse + clustersClientCreateResponse, err = testutil.PollForTest(testsuite.ctx, clustersClientCreateResponsePoller) + testsuite.Require().NoError(err) + clusterId = *clustersClientCreateResponse.ID + + // The source cluster is not ready for restore yet + if recording.GetRecordMode() == recording.RecordingMode { + time.Sleep(5 * time.Minute) + } + + // From step Clusters_CreateReplica + fmt.Println("Call operation: Clusters_Create") + clustersClientCreateResponsePoller, err = clustersClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterReplicaName, armcosmosforpostgresql.Cluster{ + Location: to.Ptr(testsuite.location), + Properties: &armcosmosforpostgresql.ClusterProperties{ + SourceLocation: to.Ptr(testsuite.location), + SourceResourceID: to.Ptr(clusterId), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, clustersClientCreateResponsePoller) + testsuite.Require().NoError(err) + + // From step Clusters_PromoteReadReplica + fmt.Println("Call operation: Clusters_PromoteReadReplica") + clustersClientPromoteReadReplicaResponsePoller, err := clustersClient.BeginPromoteReadReplica(testsuite.ctx, testsuite.resourceGroupName, testsuite.clusterReplicaName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, clustersClientPromoteReadReplicaResponsePoller) + testsuite.Require().NoError(err) +} From 277c599a0658521f290cd6fa5afa616088c93dcf Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Fri, 9 Jun 2023 14:52:39 +0800 Subject: [PATCH 5/6] update assets --- .../cosmosforpostgresql/armcosmosforpostgresql/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json index c1bd14f7bb56..097c28874a65 100644 --- a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql", - "Tag": "go/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql_80a4293735" + "Tag": "go/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql_ba57d80dc1" } From 032778ed15e6cb57305dc7df017a6e0a5aa7e67a Mon Sep 17 00:00:00 2001 From: Alancere <804873052@qq.com> Date: Fri, 9 Jun 2023 14:54:38 +0800 Subject: [PATCH 6/6] fix assests --- .../cosmosforpostgresql/armcosmosforpostgresql/assets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json index 097c28874a65..448cedb25587 100644 --- a/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json +++ b/sdk/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql", - "Tag": "go/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql_ba57d80dc1" + "Tag": "go/resourcemanager/cosmosforpostgresql/armcosmosforpostgresql_e31a4e5848" }