diff --git a/sdk/mysql/armmysqlflexibleserver/CHANGELOG.md b/sdk/mysql/armmysqlflexibleserver/CHANGELOG.md new file mode 100644 index 000000000000..a3373b480144 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/CHANGELOG.md @@ -0,0 +1,3 @@ +# Release History + +## v0.1.0 (2021-09-07) diff --git a/sdk/mysql/armmysqlflexibleserver/LICENSE.txt b/sdk/mysql/armmysqlflexibleserver/LICENSE.txt new file mode 100644 index 000000000000..ccb63b166732 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2021 Microsoft + +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/mysql/armmysqlflexibleserver/README.md b/sdk/mysql/armmysqlflexibleserver/README.md new file mode 100644 index 000000000000..8280cd1e38ee --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/README.md @@ -0,0 +1,76 @@ +# Azure Database for MySQL Module for Go + +[![PkgGoDev](https://pkg.go.dev/badge/github.com/Azure/azure-sdk-for-go/sdk/mysql/armmysqlflexibleserver)](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/mysql/armmysqlflexibleserver) + +The `armmysqlflexibleserver` module provides operations for working with Azure Database for MySQL. + +[Source code](https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/mysql/armmysqlflexibleserver) + +# Getting started + +## Prerequisites + +- an [Azure subscription](https://azure.microsoft.com/free/) +- Go 1.13 or above + +## Install the package + +This project uses [Go modules](https://github.com/golang/go/wiki/Modules) for versioning and dependency management. + +Install the Azure Database for MySQL module: + +```sh +go get github.com/Azure/azure-sdk-for-go/sdk/mysql/armmysqlflexibleserver +``` + +## Authorization + +When creating a client, you will need to provide a credential for authenticating with Azure Database for MySQL. 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). + +## Connecting to Azure Database for MySQL + +Once you have a credential, create a connection to the desired ARM endpoint. The `github.com/Azure/azure-sdk-for-go/sdk/azcore/arm` package provides facilities for connecting with ARM endpoints including public and sovereign clouds as well as Azure Stack. + +```go +con := arm.NewDefaultConnection(cred, nil) +``` + +For more information on ARM connections, 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). + +## Clients + +Azure Database for MySQL modules consist of one or more clients. A client groups a set of related APIs, providing access to its functionality within the specified subscription. Create one or more clients to access the APIs you require using your `arm.Connection`. + +```go +client := armmysqlflexibleserver.NewDatabasesClient(con, "") +``` + +## 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 `Database for MySQL` 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/mysql/armmysqlflexibleserver/autorest.md b/sdk/mysql/armmysqlflexibleserver/autorest.md new file mode 100644 index 000000000000..8fbda51789e3 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/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/2cd7c6eacc5430d8956885e8d19b87ce3f3ebd6e/specification/mysql/resource-manager/readme.md +- https://github.com/Azure/azure-rest-api-specs/blob/2cd7c6eacc5430d8956885e8d19b87ce3f3ebd6e/specification/mysql/resource-manager/readme.go.md +license-header: MICROSOFT_MIT_NO_VERSION +module-version: 0.1.0 +package-flexibleservers: true +``` \ No newline at end of file diff --git a/sdk/mysql/armmysqlflexibleserver/build.go b/sdk/mysql/armmysqlflexibleserver/build.go new file mode 100644 index 000000000000..93e687e81e74 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/build.go @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file enables 'go generate' to regenerate this specific SDK +//go:generate pwsh.exe ../../../eng/scripts/build.ps1 -skipBuild -cleanGenerated -format -tidy -generate armmysqlflexibleserver + +package armmysqlflexibleserver diff --git a/sdk/mysql/armmysqlflexibleserver/ci.yml b/sdk/mysql/armmysqlflexibleserver/ci.yml new file mode 100644 index 000000000000..f2f89765207d --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/ci.yml @@ -0,0 +1,15 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. +trigger: + paths: + include: + - sdk/mysql/armmysqlflexibleserver/ + +pr: + paths: + include: + - sdk/mysql/armmysqlflexibleserver/ + +stages: +- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: 'mysql/armmysqlflexibleserver' diff --git a/sdk/mysql/armmysqlflexibleserver/go.mod b/sdk/mysql/armmysqlflexibleserver/go.mod new file mode 100644 index 000000000000..d35b2d9e3668 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/go.mod @@ -0,0 +1,8 @@ +module github.com/Azure/azure-sdk-for-go/sdk/mysql/armmysqlflexibleserver + +go 1.13 + +require ( + github.com/Azure/azure-sdk-for-go v57.1.0+incompatible + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0 +) diff --git a/sdk/mysql/armmysqlflexibleserver/go.sum b/sdk/mysql/armmysqlflexibleserver/go.sum new file mode 100644 index 000000000000..d70b5ec62bca --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/go.sum @@ -0,0 +1,31 @@ +github.com/Azure/azure-sdk-for-go v57.1.0+incompatible h1:TKQ3ieyB0vVKkF6t9dsWbMjq56O1xU3eh3Ec09v6ajM= +github.com/Azure/azure-sdk-for-go v57.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0 h1:lhSJz9RMbJcTgxifR1hUNJnn6CNYtbgEDtQV22/9RBA= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0 h1:v9p9TfTbf7AwNb5NYQt7hI41IfPoLFiFkLtb+bmGjT0= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8= +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/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 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/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.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/mysql/armmysqlflexibleserver/go_mod_tidy_hack.go b/sdk/mysql/armmysqlflexibleserver/go_mod_tidy_hack.go new file mode 100644 index 000000000000..9a66c7e9a4f4 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/go_mod_tidy_hack.go @@ -0,0 +1,13 @@ +//go:build modhack +// +build modhack + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// This file, and the github.com/Azure/azure-sdk-for-go import, won't actually become part of +// the resultant binary. + +package armmysqlflexibleserver + +// Necessary for safely adding multi-module repo. See: https://github.com/golang/go/wiki/Modules#is-it-possible-to-add-a-module-to-a-multi-module-repository +import _ "github.com/Azure/azure-sdk-for-go" diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_backups_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_backups_client.go new file mode 100644 index 000000000000..2efafeebd113 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_backups_client.go @@ -0,0 +1,166 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "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" +) + +// BackupsClient contains the methods for the Backups group. +// Don't use this type directly, use NewBackupsClient() instead. +type BackupsClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewBackupsClient creates a new instance of BackupsClient with the specified values. +func NewBackupsClient(con *arm.Connection, subscriptionID string) *BackupsClient { + return &BackupsClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// Get - List all the backups for a given server. +// If the operation fails it returns the *CloudError error type. +func (client *BackupsClient) Get(ctx context.Context, resourceGroupName string, serverName string, backupName string, options *BackupsGetOptions) (BackupsGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverName, backupName, options) + if err != nil { + return BackupsGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return BackupsGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return BackupsGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *BackupsClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverName string, backupName string, options *BackupsGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/backups/{backupName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if backupName == "" { + return nil, errors.New("parameter backupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{backupName}", url.PathEscape(backupName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *BackupsClient) getHandleResponse(resp *http.Response) (BackupsGetResponse, error) { + result := BackupsGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerBackup); err != nil { + return BackupsGetResponse{}, err + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *BackupsClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListByServer - List all the backups for a given server. +// If the operation fails it returns the *CloudError error type. +func (client *BackupsClient) ListByServer(resourceGroupName string, serverName string, options *BackupsListByServerOptions) *BackupsListByServerPager { + return &BackupsListByServerPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByServerCreateRequest(ctx, resourceGroupName, serverName, options) + }, + advancer: func(ctx context.Context, resp BackupsListByServerResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ServerBackupListResult.NextLink) + }, + } +} + +// listByServerCreateRequest creates the ListByServer request. +func (client *BackupsClient) listByServerCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *BackupsListByServerOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/backups" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerHandleResponse handles the ListByServer response. +func (client *BackupsClient) listByServerHandleResponse(resp *http.Response) (BackupsListByServerResponse, error) { + result := BackupsListByServerResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerBackupListResult); err != nil { + return BackupsListByServerResponse{}, err + } + return result, nil +} + +// listByServerHandleError handles the ListByServer error response. +func (client *BackupsClient) listByServerHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_checknameavailability_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_checknameavailability_client.go new file mode 100644 index 000000000000..bdf84610d96e --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_checknameavailability_client.go @@ -0,0 +1,96 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "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" +) + +// CheckNameAvailabilityClient contains the methods for the CheckNameAvailability group. +// Don't use this type directly, use NewCheckNameAvailabilityClient() instead. +type CheckNameAvailabilityClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewCheckNameAvailabilityClient creates a new instance of CheckNameAvailabilityClient with the specified values. +func NewCheckNameAvailabilityClient(con *arm.Connection, subscriptionID string) *CheckNameAvailabilityClient { + return &CheckNameAvailabilityClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// Execute - Check the availability of name for server +// If the operation fails it returns the *CloudError error type. +func (client *CheckNameAvailabilityClient) Execute(ctx context.Context, locationName string, nameAvailabilityRequest NameAvailabilityRequest, options *CheckNameAvailabilityExecuteOptions) (CheckNameAvailabilityExecuteResponse, error) { + req, err := client.executeCreateRequest(ctx, locationName, nameAvailabilityRequest, options) + if err != nil { + return CheckNameAvailabilityExecuteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return CheckNameAvailabilityExecuteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return CheckNameAvailabilityExecuteResponse{}, client.executeHandleError(resp) + } + return client.executeHandleResponse(resp) +} + +// executeCreateRequest creates the Execute request. +func (client *CheckNameAvailabilityClient) executeCreateRequest(ctx context.Context, locationName string, nameAvailabilityRequest NameAvailabilityRequest, options *CheckNameAvailabilityExecuteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DBforMySQL/locations/{locationName}/checkNameAvailability" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if locationName == "" { + return nil, errors.New("parameter locationName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{locationName}", url.PathEscape(locationName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, nameAvailabilityRequest) +} + +// executeHandleResponse handles the Execute response. +func (client *CheckNameAvailabilityClient) executeHandleResponse(resp *http.Response) (CheckNameAvailabilityExecuteResponse, error) { + result := CheckNameAvailabilityExecuteResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.NameAvailability); err != nil { + return CheckNameAvailabilityExecuteResponse{}, err + } + return result, nil +} + +// executeHandleError handles the Execute error response. +func (client *CheckNameAvailabilityClient) executeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_checkvirtualnetworksubnetusage_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_checkvirtualnetworksubnetusage_client.go new file mode 100644 index 000000000000..f3f21673df27 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_checkvirtualnetworksubnetusage_client.go @@ -0,0 +1,96 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "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" +) + +// CheckVirtualNetworkSubnetUsageClient contains the methods for the CheckVirtualNetworkSubnetUsage group. +// Don't use this type directly, use NewCheckVirtualNetworkSubnetUsageClient() instead. +type CheckVirtualNetworkSubnetUsageClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewCheckVirtualNetworkSubnetUsageClient creates a new instance of CheckVirtualNetworkSubnetUsageClient with the specified values. +func NewCheckVirtualNetworkSubnetUsageClient(con *arm.Connection, subscriptionID string) *CheckVirtualNetworkSubnetUsageClient { + return &CheckVirtualNetworkSubnetUsageClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// Execute - Get virtual network subnet usage for a given vNet resource id. +// If the operation fails it returns the *CloudError error type. +func (client *CheckVirtualNetworkSubnetUsageClient) Execute(ctx context.Context, locationName string, parameters VirtualNetworkSubnetUsageParameter, options *CheckVirtualNetworkSubnetUsageExecuteOptions) (CheckVirtualNetworkSubnetUsageExecuteResponse, error) { + req, err := client.executeCreateRequest(ctx, locationName, parameters, options) + if err != nil { + return CheckVirtualNetworkSubnetUsageExecuteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return CheckVirtualNetworkSubnetUsageExecuteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return CheckVirtualNetworkSubnetUsageExecuteResponse{}, client.executeHandleError(resp) + } + return client.executeHandleResponse(resp) +} + +// executeCreateRequest creates the Execute request. +func (client *CheckVirtualNetworkSubnetUsageClient) executeCreateRequest(ctx context.Context, locationName string, parameters VirtualNetworkSubnetUsageParameter, options *CheckVirtualNetworkSubnetUsageExecuteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DBforMySQL/locations/{locationName}/checkVirtualNetworkSubnetUsage" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if locationName == "" { + return nil, errors.New("parameter locationName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{locationName}", url.PathEscape(locationName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// executeHandleResponse handles the Execute response. +func (client *CheckVirtualNetworkSubnetUsageClient) executeHandleResponse(resp *http.Response) (CheckVirtualNetworkSubnetUsageExecuteResponse, error) { + result := CheckVirtualNetworkSubnetUsageExecuteResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.VirtualNetworkSubnetUsageResult); err != nil { + return CheckVirtualNetworkSubnetUsageExecuteResponse{}, err + } + return result, nil +} + +// executeHandleError handles the Execute error response. +func (client *CheckVirtualNetworkSubnetUsageClient) executeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_configurations_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_configurations_client.go new file mode 100644 index 000000000000..66f853a7b510 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_configurations_client.go @@ -0,0 +1,323 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" +) + +// ConfigurationsClient contains the methods for the Configurations group. +// Don't use this type directly, use NewConfigurationsClient() instead. +type ConfigurationsClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewConfigurationsClient creates a new instance of ConfigurationsClient with the specified values. +func NewConfigurationsClient(con *arm.Connection, subscriptionID string) *ConfigurationsClient { + return &ConfigurationsClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// BeginBatchUpdate - Update a list of configurations in a given server. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) BeginBatchUpdate(ctx context.Context, resourceGroupName string, serverName string, parameters ConfigurationListForBatchUpdate, options *ConfigurationsBeginBatchUpdateOptions) (ConfigurationsBatchUpdatePollerResponse, error) { + resp, err := client.batchUpdate(ctx, resourceGroupName, serverName, parameters, options) + if err != nil { + return ConfigurationsBatchUpdatePollerResponse{}, err + } + result := ConfigurationsBatchUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ConfigurationsClient.BatchUpdate", "azure-async-operation", resp, client.pl, client.batchUpdateHandleError) + if err != nil { + return ConfigurationsBatchUpdatePollerResponse{}, err + } + result.Poller = &ConfigurationsBatchUpdatePoller{ + pt: pt, + } + return result, nil +} + +// BatchUpdate - Update a list of configurations in a given server. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) batchUpdate(ctx context.Context, resourceGroupName string, serverName string, parameters ConfigurationListForBatchUpdate, options *ConfigurationsBeginBatchUpdateOptions) (*http.Response, error) { + req, err := client.batchUpdateCreateRequest(ctx, resourceGroupName, serverName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.batchUpdateHandleError(resp) + } + return resp, nil +} + +// batchUpdateCreateRequest creates the BatchUpdate request. +func (client *ConfigurationsClient) batchUpdateCreateRequest(ctx context.Context, resourceGroupName string, serverName string, parameters ConfigurationListForBatchUpdate, options *ConfigurationsBeginBatchUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/updateConfigurations" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// batchUpdateHandleError handles the BatchUpdate error response. +func (client *ConfigurationsClient) batchUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Gets information about a configuration of server. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) Get(ctx context.Context, resourceGroupName string, serverName string, configurationName string, options *ConfigurationsGetOptions) (ConfigurationsGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverName, configurationName, options) + if err != nil { + return ConfigurationsGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ConfigurationsGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ConfigurationsGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ConfigurationsClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverName string, configurationName string, options *ConfigurationsGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/configurations/{configurationName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if configurationName == "" { + return nil, errors.New("parameter configurationName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ConfigurationsClient) getHandleResponse(resp *http.Response) (ConfigurationsGetResponse, error) { + result := ConfigurationsGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Configuration); err != nil { + return ConfigurationsGetResponse{}, err + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *ConfigurationsClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListByServer - List all the configurations in a given server. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) ListByServer(resourceGroupName string, serverName string, options *ConfigurationsListByServerOptions) *ConfigurationsListByServerPager { + return &ConfigurationsListByServerPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByServerCreateRequest(ctx, resourceGroupName, serverName, options) + }, + advancer: func(ctx context.Context, resp ConfigurationsListByServerResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ConfigurationListResult.NextLink) + }, + } +} + +// listByServerCreateRequest creates the ListByServer request. +func (client *ConfigurationsClient) listByServerCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *ConfigurationsListByServerOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/configurations" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerHandleResponse handles the ListByServer response. +func (client *ConfigurationsClient) listByServerHandleResponse(resp *http.Response) (ConfigurationsListByServerResponse, error) { + result := ConfigurationsListByServerResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ConfigurationListResult); err != nil { + return ConfigurationsListByServerResponse{}, err + } + return result, nil +} + +// listByServerHandleError handles the ListByServer error response. +func (client *ConfigurationsClient) listByServerHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginUpdate - Updates a configuration of a server. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) BeginUpdate(ctx context.Context, resourceGroupName string, serverName string, configurationName string, parameters Configuration, options *ConfigurationsBeginUpdateOptions) (ConfigurationsUpdatePollerResponse, error) { + resp, err := client.update(ctx, resourceGroupName, serverName, configurationName, parameters, options) + if err != nil { + return ConfigurationsUpdatePollerResponse{}, err + } + result := ConfigurationsUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ConfigurationsClient.Update", "", resp, client.pl, client.updateHandleError) + if err != nil { + return ConfigurationsUpdatePollerResponse{}, err + } + result.Poller = &ConfigurationsUpdatePoller{ + pt: pt, + } + return result, nil +} + +// Update - Updates a configuration of a server. +// If the operation fails it returns the *CloudError error type. +func (client *ConfigurationsClient) update(ctx context.Context, resourceGroupName string, serverName string, configurationName string, parameters Configuration, options *ConfigurationsBeginUpdateOptions) (*http.Response, error) { + req, err := client.updateCreateRequest(ctx, resourceGroupName, serverName, configurationName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.updateHandleError(resp) + } + return resp, nil +} + +// updateCreateRequest creates the Update request. +func (client *ConfigurationsClient) updateCreateRequest(ctx context.Context, resourceGroupName string, serverName string, configurationName string, parameters Configuration, options *ConfigurationsBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/configurations/{configurationName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if configurationName == "" { + return nil, errors.New("parameter configurationName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{configurationName}", url.PathEscape(configurationName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// updateHandleError handles the Update error response. +func (client *ConfigurationsClient) updateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_constants.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_constants.go new file mode 100644 index 000000000000..387d578f18b7 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_constants.go @@ -0,0 +1,317 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +const ( + module = "armmysqlflexibleserver" + version = "v0.1.0" +) + +// ConfigurationSource - Source of the configuration. +type ConfigurationSource string + +const ( + ConfigurationSourceSystemDefault ConfigurationSource = "system-default" + ConfigurationSourceUserOverride ConfigurationSource = "user-override" +) + +// PossibleConfigurationSourceValues returns the possible values for the ConfigurationSource const type. +func PossibleConfigurationSourceValues() []ConfigurationSource { + return []ConfigurationSource{ + ConfigurationSourceSystemDefault, + ConfigurationSourceUserOverride, + } +} + +// ToPtr returns a *ConfigurationSource pointing to the current value. +func (c ConfigurationSource) ToPtr() *ConfigurationSource { + return &c +} + +// CreateMode - The mode to create a new MySQL server. +type CreateMode string + +const ( + CreateModeDefault CreateMode = "Default" + CreateModeGeoRestore CreateMode = "GeoRestore" + CreateModePointInTimeRestore CreateMode = "PointInTimeRestore" + CreateModeReplica CreateMode = "Replica" +) + +// PossibleCreateModeValues returns the possible values for the CreateMode const type. +func PossibleCreateModeValues() []CreateMode { + return []CreateMode{ + CreateModeDefault, + CreateModeGeoRestore, + CreateModePointInTimeRestore, + CreateModeReplica, + } +} + +// ToPtr returns a *CreateMode pointing to the current value. +func (c CreateMode) ToPtr() *CreateMode { + return &c +} + +// CreatedByType - The type of identity that created the resource. +type CreatedByType string + +const ( + CreatedByTypeApplication CreatedByType = "Application" + CreatedByTypeKey CreatedByType = "Key" + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + CreatedByTypeUser CreatedByType = "User" +) + +// PossibleCreatedByTypeValues returns the possible values for the CreatedByType const type. +func PossibleCreatedByTypeValues() []CreatedByType { + return []CreatedByType{ + CreatedByTypeApplication, + CreatedByTypeKey, + CreatedByTypeManagedIdentity, + CreatedByTypeUser, + } +} + +// ToPtr returns a *CreatedByType pointing to the current value. +func (c CreatedByType) ToPtr() *CreatedByType { + return &c +} + +// EnableStatusEnum - Enum to indicate whether value is 'Enabled' or 'Disabled' +type EnableStatusEnum string + +const ( + EnableStatusEnumDisabled EnableStatusEnum = "Disabled" + EnableStatusEnumEnabled EnableStatusEnum = "Enabled" +) + +// PossibleEnableStatusEnumValues returns the possible values for the EnableStatusEnum const type. +func PossibleEnableStatusEnumValues() []EnableStatusEnum { + return []EnableStatusEnum{ + EnableStatusEnumDisabled, + EnableStatusEnumEnabled, + } +} + +// ToPtr returns a *EnableStatusEnum pointing to the current value. +func (c EnableStatusEnum) ToPtr() *EnableStatusEnum { + return &c +} + +// HighAvailabilityMode - High availability mode for a server. +type HighAvailabilityMode string + +const ( + HighAvailabilityModeDisabled HighAvailabilityMode = "Disabled" + HighAvailabilityModeSameZone HighAvailabilityMode = "SameZone" + HighAvailabilityModeZoneRedundant HighAvailabilityMode = "ZoneRedundant" +) + +// PossibleHighAvailabilityModeValues returns the possible values for the HighAvailabilityMode const type. +func PossibleHighAvailabilityModeValues() []HighAvailabilityMode { + return []HighAvailabilityMode{ + HighAvailabilityModeDisabled, + HighAvailabilityModeSameZone, + HighAvailabilityModeZoneRedundant, + } +} + +// ToPtr returns a *HighAvailabilityMode pointing to the current value. +func (c HighAvailabilityMode) ToPtr() *HighAvailabilityMode { + return &c +} + +// HighAvailabilityState - The state of server high availability. +type HighAvailabilityState string + +const ( + HighAvailabilityStateCreatingStandby HighAvailabilityState = "CreatingStandby" + HighAvailabilityStateFailingOver HighAvailabilityState = "FailingOver" + HighAvailabilityStateHealthy HighAvailabilityState = "Healthy" + HighAvailabilityStateNotEnabled HighAvailabilityState = "NotEnabled" + HighAvailabilityStateRemovingStandby HighAvailabilityState = "RemovingStandby" +) + +// PossibleHighAvailabilityStateValues returns the possible values for the HighAvailabilityState const type. +func PossibleHighAvailabilityStateValues() []HighAvailabilityState { + return []HighAvailabilityState{ + HighAvailabilityStateCreatingStandby, + HighAvailabilityStateFailingOver, + HighAvailabilityStateHealthy, + HighAvailabilityStateNotEnabled, + HighAvailabilityStateRemovingStandby, + } +} + +// ToPtr returns a *HighAvailabilityState pointing to the current value. +func (c HighAvailabilityState) ToPtr() *HighAvailabilityState { + return &c +} + +// IsConfigPendingRestart - If is the configuration pending restart or not. +type IsConfigPendingRestart string + +const ( + IsConfigPendingRestartFalse IsConfigPendingRestart = "False" + IsConfigPendingRestartTrue IsConfigPendingRestart = "True" +) + +// PossibleIsConfigPendingRestartValues returns the possible values for the IsConfigPendingRestart const type. +func PossibleIsConfigPendingRestartValues() []IsConfigPendingRestart { + return []IsConfigPendingRestart{ + IsConfigPendingRestartFalse, + IsConfigPendingRestartTrue, + } +} + +// ToPtr returns a *IsConfigPendingRestart pointing to the current value. +func (c IsConfigPendingRestart) ToPtr() *IsConfigPendingRestart { + return &c +} + +// IsDynamicConfig - If is the configuration dynamic. +type IsDynamicConfig string + +const ( + IsDynamicConfigFalse IsDynamicConfig = "False" + IsDynamicConfigTrue IsDynamicConfig = "True" +) + +// PossibleIsDynamicConfigValues returns the possible values for the IsDynamicConfig const type. +func PossibleIsDynamicConfigValues() []IsDynamicConfig { + return []IsDynamicConfig{ + IsDynamicConfigFalse, + IsDynamicConfigTrue, + } +} + +// ToPtr returns a *IsDynamicConfig pointing to the current value. +func (c IsDynamicConfig) ToPtr() *IsDynamicConfig { + return &c +} + +// IsReadOnly - If is the configuration read only. +type IsReadOnly string + +const ( + IsReadOnlyFalse IsReadOnly = "False" + IsReadOnlyTrue IsReadOnly = "True" +) + +// PossibleIsReadOnlyValues returns the possible values for the IsReadOnly const type. +func PossibleIsReadOnlyValues() []IsReadOnly { + return []IsReadOnly{ + IsReadOnlyFalse, + IsReadOnlyTrue, + } +} + +// ToPtr returns a *IsReadOnly pointing to the current value. +func (c IsReadOnly) ToPtr() *IsReadOnly { + return &c +} + +// ReplicationRole - The replication role. +type ReplicationRole string + +const ( + ReplicationRoleNone ReplicationRole = "None" + ReplicationRoleReplica ReplicationRole = "Replica" + ReplicationRoleSource ReplicationRole = "Source" +) + +// PossibleReplicationRoleValues returns the possible values for the ReplicationRole const type. +func PossibleReplicationRoleValues() []ReplicationRole { + return []ReplicationRole{ + ReplicationRoleNone, + ReplicationRoleReplica, + ReplicationRoleSource, + } +} + +// ToPtr returns a *ReplicationRole pointing to the current value. +func (c ReplicationRole) ToPtr() *ReplicationRole { + return &c +} + +// SKUTier - The tier of the particular SKU, e.g. GeneralPurpose. +type SKUTier string + +const ( + SKUTierBurstable SKUTier = "Burstable" + SKUTierGeneralPurpose SKUTier = "GeneralPurpose" + SKUTierMemoryOptimized SKUTier = "MemoryOptimized" +) + +// PossibleSKUTierValues returns the possible values for the SKUTier const type. +func PossibleSKUTierValues() []SKUTier { + return []SKUTier{ + SKUTierBurstable, + SKUTierGeneralPurpose, + SKUTierMemoryOptimized, + } +} + +// ToPtr returns a *SKUTier pointing to the current value. +func (c SKUTier) ToPtr() *SKUTier { + return &c +} + +// ServerState - The state of a server. +type ServerState string + +const ( + ServerStateDisabled ServerState = "Disabled" + ServerStateDropping ServerState = "Dropping" + ServerStateReady ServerState = "Ready" + ServerStateStarting ServerState = "Starting" + ServerStateStopped ServerState = "Stopped" + ServerStateStopping ServerState = "Stopping" + ServerStateUpdating ServerState = "Updating" +) + +// PossibleServerStateValues returns the possible values for the ServerState const type. +func PossibleServerStateValues() []ServerState { + return []ServerState{ + ServerStateDisabled, + ServerStateDropping, + ServerStateReady, + ServerStateStarting, + ServerStateStopped, + ServerStateStopping, + ServerStateUpdating, + } +} + +// ToPtr returns a *ServerState pointing to the current value. +func (c ServerState) ToPtr() *ServerState { + return &c +} + +// ServerVersion - The version of a server. +type ServerVersion string + +const ( + ServerVersionEight021 ServerVersion = "8.0.21" + ServerVersionFive7 ServerVersion = "5.7" +) + +// PossibleServerVersionValues returns the possible values for the ServerVersion const type. +func PossibleServerVersionValues() []ServerVersion { + return []ServerVersion{ + ServerVersionEight021, + ServerVersionFive7, + } +} + +// ToPtr returns a *ServerVersion pointing to the current value. +func (c ServerVersion) ToPtr() *ServerVersion { + return &c +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_databases_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_databases_client.go new file mode 100644 index 000000000000..48f901d0bd9a --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_databases_client.go @@ -0,0 +1,327 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" +) + +// DatabasesClient contains the methods for the Databases group. +// Don't use this type directly, use NewDatabasesClient() instead. +type DatabasesClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewDatabasesClient creates a new instance of DatabasesClient with the specified values. +func NewDatabasesClient(con *arm.Connection, subscriptionID string) *DatabasesClient { + return &DatabasesClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// BeginCreateOrUpdate - Creates a new database or updates an existing database. +// If the operation fails it returns the *CloudError error type. +func (client *DatabasesClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters Database, options *DatabasesBeginCreateOrUpdateOptions) (DatabasesCreateOrUpdatePollerResponse, error) { + resp, err := client.createOrUpdate(ctx, resourceGroupName, serverName, databaseName, parameters, options) + if err != nil { + return DatabasesCreateOrUpdatePollerResponse{}, err + } + result := DatabasesCreateOrUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("DatabasesClient.CreateOrUpdate", "", resp, client.pl, client.createOrUpdateHandleError) + if err != nil { + return DatabasesCreateOrUpdatePollerResponse{}, err + } + result.Poller = &DatabasesCreateOrUpdatePoller{ + pt: pt, + } + return result, nil +} + +// CreateOrUpdate - Creates a new database or updates an existing database. +// If the operation fails it returns the *CloudError error type. +func (client *DatabasesClient) createOrUpdate(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters Database, options *DatabasesBeginCreateOrUpdateOptions) (*http.Response, error) { + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, serverName, databaseName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + return nil, client.createOrUpdateHandleError(resp) + } + return resp, nil +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *DatabasesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters Database, options *DatabasesBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/databases/{databaseName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if databaseName == "" { + return nil, errors.New("parameter databaseName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{databaseName}", url.PathEscape(databaseName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleError handles the CreateOrUpdate error response. +func (client *DatabasesClient) createOrUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginDelete - Deletes a database. +// If the operation fails it returns the *CloudError error type. +func (client *DatabasesClient) BeginDelete(ctx context.Context, resourceGroupName string, serverName string, databaseName string, options *DatabasesBeginDeleteOptions) (DatabasesDeletePollerResponse, error) { + resp, err := client.deleteOperation(ctx, resourceGroupName, serverName, databaseName, options) + if err != nil { + return DatabasesDeletePollerResponse{}, err + } + result := DatabasesDeletePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("DatabasesClient.Delete", "", resp, client.pl, client.deleteHandleError) + if err != nil { + return DatabasesDeletePollerResponse{}, err + } + result.Poller = &DatabasesDeletePoller{ + pt: pt, + } + return result, nil +} + +// Delete - Deletes a database. +// If the operation fails it returns the *CloudError error type. +func (client *DatabasesClient) deleteOperation(ctx context.Context, resourceGroupName string, serverName string, databaseName string, options *DatabasesBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, serverName, databaseName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + return nil, client.deleteHandleError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *DatabasesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serverName string, databaseName string, options *DatabasesBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/databases/{databaseName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if databaseName == "" { + return nil, errors.New("parameter databaseName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{databaseName}", url.PathEscape(databaseName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *DatabasesClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Gets information about a database. +// If the operation fails it returns the *CloudError error type. +func (client *DatabasesClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string, options *DatabasesGetOptions) (DatabasesGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverName, databaseName, options) + if err != nil { + return DatabasesGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return DatabasesGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return DatabasesGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *DatabasesClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverName string, databaseName string, options *DatabasesGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/databases/{databaseName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if databaseName == "" { + return nil, errors.New("parameter databaseName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{databaseName}", url.PathEscape(databaseName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *DatabasesClient) getHandleResponse(resp *http.Response) (DatabasesGetResponse, error) { + result := DatabasesGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Database); err != nil { + return DatabasesGetResponse{}, err + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *DatabasesClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListByServer - List all the databases in a given server. +// If the operation fails it returns the *CloudError error type. +func (client *DatabasesClient) ListByServer(resourceGroupName string, serverName string, options *DatabasesListByServerOptions) *DatabasesListByServerPager { + return &DatabasesListByServerPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByServerCreateRequest(ctx, resourceGroupName, serverName, options) + }, + advancer: func(ctx context.Context, resp DatabasesListByServerResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.DatabaseListResult.NextLink) + }, + } +} + +// listByServerCreateRequest creates the ListByServer request. +func (client *DatabasesClient) listByServerCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *DatabasesListByServerOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/databases" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerHandleResponse handles the ListByServer response. +func (client *DatabasesClient) listByServerHandleResponse(resp *http.Response) (DatabasesListByServerResponse, error) { + result := DatabasesListByServerResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.DatabaseListResult); err != nil { + return DatabasesListByServerResponse{}, err + } + return result, nil +} + +// listByServerHandleError handles the ListByServer error response. +func (client *DatabasesClient) listByServerHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_firewallrules_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_firewallrules_client.go new file mode 100644 index 000000000000..840894cf6f9b --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_firewallrules_client.go @@ -0,0 +1,327 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" +) + +// FirewallRulesClient contains the methods for the FirewallRules group. +// Don't use this type directly, use NewFirewallRulesClient() instead. +type FirewallRulesClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewFirewallRulesClient creates a new instance of FirewallRulesClient with the specified values. +func NewFirewallRulesClient(con *arm.Connection, subscriptionID string) *FirewallRulesClient { + return &FirewallRulesClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// BeginCreateOrUpdate - Creates a new firewall rule or updates an existing firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesBeginCreateOrUpdateOptions) (FirewallRulesCreateOrUpdatePollerResponse, error) { + resp, err := client.createOrUpdate(ctx, resourceGroupName, serverName, firewallRuleName, parameters, options) + if err != nil { + return FirewallRulesCreateOrUpdatePollerResponse{}, err + } + result := FirewallRulesCreateOrUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("FirewallRulesClient.CreateOrUpdate", "", resp, client.pl, client.createOrUpdateHandleError) + if err != nil { + return FirewallRulesCreateOrUpdatePollerResponse{}, err + } + result.Poller = &FirewallRulesCreateOrUpdatePoller{ + pt: pt, + } + return result, nil +} + +// CreateOrUpdate - Creates a new firewall rule or updates an existing firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) createOrUpdate(ctx context.Context, resourceGroupName string, serverName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesBeginCreateOrUpdateOptions) (*http.Response, error) { + req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, serverName, firewallRuleName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + return nil, client.createOrUpdateHandleError(resp) + } + return resp, nil +} + +// createOrUpdateCreateRequest creates the CreateOrUpdate request. +func (client *FirewallRulesClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, serverName string, firewallRuleName string, parameters FirewallRule, options *FirewallRulesBeginCreateOrUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/firewallRules/{firewallRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if firewallRuleName == "" { + return nil, errors.New("parameter firewallRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{firewallRuleName}", url.PathEscape(firewallRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createOrUpdateHandleError handles the CreateOrUpdate error response. +func (client *FirewallRulesClient) createOrUpdateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginDelete - Deletes a firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) BeginDelete(ctx context.Context, resourceGroupName string, serverName string, firewallRuleName string, options *FirewallRulesBeginDeleteOptions) (FirewallRulesDeletePollerResponse, error) { + resp, err := client.deleteOperation(ctx, resourceGroupName, serverName, firewallRuleName, options) + if err != nil { + return FirewallRulesDeletePollerResponse{}, err + } + result := FirewallRulesDeletePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("FirewallRulesClient.Delete", "", resp, client.pl, client.deleteHandleError) + if err != nil { + return FirewallRulesDeletePollerResponse{}, err + } + result.Poller = &FirewallRulesDeletePoller{ + pt: pt, + } + return result, nil +} + +// Delete - Deletes a firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) deleteOperation(ctx context.Context, resourceGroupName string, serverName string, firewallRuleName string, options *FirewallRulesBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, serverName, firewallRuleName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + return nil, client.deleteHandleError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *FirewallRulesClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serverName string, firewallRuleName string, options *FirewallRulesBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/firewallRules/{firewallRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if firewallRuleName == "" { + return nil, errors.New("parameter firewallRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{firewallRuleName}", url.PathEscape(firewallRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *FirewallRulesClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Gets information about a server firewall rule. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) Get(ctx context.Context, resourceGroupName string, serverName string, firewallRuleName string, options *FirewallRulesGetOptions) (FirewallRulesGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverName, firewallRuleName, options) + if err != nil { + return FirewallRulesGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return FirewallRulesGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return FirewallRulesGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *FirewallRulesClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverName string, firewallRuleName string, options *FirewallRulesGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/firewallRules/{firewallRuleName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + if firewallRuleName == "" { + return nil, errors.New("parameter firewallRuleName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{firewallRuleName}", url.PathEscape(firewallRuleName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *FirewallRulesClient) getHandleResponse(resp *http.Response) (FirewallRulesGetResponse, error) { + result := FirewallRulesGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.FirewallRule); err != nil { + return FirewallRulesGetResponse{}, err + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *FirewallRulesClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListByServer - List all the firewall rules in a given server. +// If the operation fails it returns the *CloudError error type. +func (client *FirewallRulesClient) ListByServer(resourceGroupName string, serverName string, options *FirewallRulesListByServerOptions) *FirewallRulesListByServerPager { + return &FirewallRulesListByServerPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByServerCreateRequest(ctx, resourceGroupName, serverName, options) + }, + advancer: func(ctx context.Context, resp FirewallRulesListByServerResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.FirewallRuleListResult.NextLink) + }, + } +} + +// listByServerCreateRequest creates the ListByServer request. +func (client *FirewallRulesClient) listByServerCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *FirewallRulesListByServerOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/firewallRules" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerHandleResponse handles the ListByServer response. +func (client *FirewallRulesClient) listByServerHandleResponse(resp *http.Response) (FirewallRulesListByServerResponse, error) { + result := FirewallRulesListByServerResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.FirewallRuleListResult); err != nil { + return FirewallRulesListByServerResponse{}, err + } + return result, nil +} + +// listByServerHandleError handles the ListByServer error response. +func (client *FirewallRulesClient) listByServerHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_getprivatednszonesuffix_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_getprivatednszonesuffix_client.go new file mode 100644 index 000000000000..8560fd59b42e --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_getprivatednszonesuffix_client.go @@ -0,0 +1,84 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "fmt" + "net/http" + + "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" +) + +// GetPrivateDNSZoneSuffixClient contains the methods for the GetPrivateDNSZoneSuffix group. +// Don't use this type directly, use NewGetPrivateDNSZoneSuffixClient() instead. +type GetPrivateDNSZoneSuffixClient struct { + ep string + pl runtime.Pipeline +} + +// NewGetPrivateDNSZoneSuffixClient creates a new instance of GetPrivateDNSZoneSuffixClient with the specified values. +func NewGetPrivateDNSZoneSuffixClient(con *arm.Connection) *GetPrivateDNSZoneSuffixClient { + return &GetPrivateDNSZoneSuffixClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version)} +} + +// Execute - Get private DNS zone suffix in the cloud. +// If the operation fails it returns the *CloudError error type. +func (client *GetPrivateDNSZoneSuffixClient) Execute(ctx context.Context, options *GetPrivateDNSZoneSuffixExecuteOptions) (GetPrivateDNSZoneSuffixExecuteResponse, error) { + req, err := client.executeCreateRequest(ctx, options) + if err != nil { + return GetPrivateDNSZoneSuffixExecuteResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return GetPrivateDNSZoneSuffixExecuteResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return GetPrivateDNSZoneSuffixExecuteResponse{}, client.executeHandleError(resp) + } + return client.executeHandleResponse(resp) +} + +// executeCreateRequest creates the Execute request. +func (client *GetPrivateDNSZoneSuffixClient) executeCreateRequest(ctx context.Context, options *GetPrivateDNSZoneSuffixExecuteOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.DBforMySQL/getPrivateDnsZoneSuffix" + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// executeHandleResponse handles the Execute response. +func (client *GetPrivateDNSZoneSuffixClient) executeHandleResponse(resp *http.Response) (GetPrivateDNSZoneSuffixExecuteResponse, error) { + result := GetPrivateDNSZoneSuffixExecuteResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.GetPrivateDNSZoneSuffixResponse); err != nil { + return GetPrivateDNSZoneSuffixExecuteResponse{}, err + } + return result, nil +} + +// executeHandleError handles the Execute error response. +func (client *GetPrivateDNSZoneSuffixClient) executeHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_locationbasedcapabilities_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_locationbasedcapabilities_client.go new file mode 100644 index 000000000000..1450b7dede06 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_locationbasedcapabilities_client.go @@ -0,0 +1,93 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "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" +) + +// LocationBasedCapabilitiesClient contains the methods for the LocationBasedCapabilities group. +// Don't use this type directly, use NewLocationBasedCapabilitiesClient() instead. +type LocationBasedCapabilitiesClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewLocationBasedCapabilitiesClient creates a new instance of LocationBasedCapabilitiesClient with the specified values. +func NewLocationBasedCapabilitiesClient(con *arm.Connection, subscriptionID string) *LocationBasedCapabilitiesClient { + return &LocationBasedCapabilitiesClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// List - Get capabilities at specified location in a given subscription. +// If the operation fails it returns the *CloudError error type. +func (client *LocationBasedCapabilitiesClient) List(locationName string, options *LocationBasedCapabilitiesListOptions) *LocationBasedCapabilitiesListPager { + return &LocationBasedCapabilitiesListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, locationName, options) + }, + advancer: func(ctx context.Context, resp LocationBasedCapabilitiesListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.CapabilitiesListResult.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *LocationBasedCapabilitiesClient) listCreateRequest(ctx context.Context, locationName string, options *LocationBasedCapabilitiesListOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DBforMySQL/locations/{locationName}/capabilities" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if locationName == "" { + return nil, errors.New("parameter locationName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{locationName}", url.PathEscape(locationName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *LocationBasedCapabilitiesClient) listHandleResponse(resp *http.Response) (LocationBasedCapabilitiesListResponse, error) { + result := LocationBasedCapabilitiesListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.CapabilitiesListResult); err != nil { + return LocationBasedCapabilitiesListResponse{}, err + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *LocationBasedCapabilitiesClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_models.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_models.go new file mode 100644 index 000000000000..f86c6694cf35 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_models.go @@ -0,0 +1,1203 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "encoding/json" + "reflect" + "time" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" +) + +// Backup - Storage Profile properties of a server +type Backup struct { + // Backup retention days for the server. + BackupRetentionDays *int32 `json:"backupRetentionDays,omitempty"` + + // Whether or not geo redundant backup is enabled. + GeoRedundantBackup *EnableStatusEnum `json:"geoRedundantBackup,omitempty"` + + // READ-ONLY; Earliest restore point creation time (ISO8601 format) + EarliestRestoreDate *time.Time `json:"earliestRestoreDate,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Backup. +func (b Backup) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "backupRetentionDays", b.BackupRetentionDays) + populate(objectMap, "earliestRestoreDate", (*timeRFC3339)(b.EarliestRestoreDate)) + populate(objectMap, "geoRedundantBackup", b.GeoRedundantBackup) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type Backup. +func (b *Backup) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "backupRetentionDays": + err = unpopulate(val, &b.BackupRetentionDays) + delete(rawMsg, key) + case "earliestRestoreDate": + var aux timeRFC3339 + err = unpopulate(val, &aux) + b.EarliestRestoreDate = (*time.Time)(&aux) + delete(rawMsg, key) + case "geoRedundantBackup": + err = unpopulate(val, &b.GeoRedundantBackup) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// BackupsGetOptions contains the optional parameters for the Backups.Get method. +type BackupsGetOptions struct { + // placeholder for future optional parameters +} + +// BackupsListByServerOptions contains the optional parameters for the Backups.ListByServer method. +type BackupsListByServerOptions struct { + // placeholder for future optional parameters +} + +// CapabilitiesListResult - location capability +type CapabilitiesListResult struct { + // READ-ONLY; Link to retrieve next page of results. + NextLink *string `json:"nextLink,omitempty" azure:"ro"` + + // READ-ONLY; A list of supported capabilities. + Value []*CapabilityProperties `json:"value,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type CapabilitiesListResult. +func (c CapabilitiesListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", c.NextLink) + populate(objectMap, "value", c.Value) + return json.Marshal(objectMap) +} + +// CapabilityProperties - Location capabilities. +type CapabilityProperties struct { + // READ-ONLY; A list of supported flexible server editions. + SupportedFlexibleServerEditions []*ServerEditionCapability `json:"supportedFlexibleServerEditions,omitempty" azure:"ro"` + + // READ-ONLY; supported geo backup regions + SupportedGeoBackupRegions []*string `json:"supportedGeoBackupRegions,omitempty" azure:"ro"` + + // READ-ONLY; Supported high availability mode + SupportedHAMode []*string `json:"supportedHAMode,omitempty" azure:"ro"` + + // READ-ONLY; zone name + Zone *string `json:"zone,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type CapabilityProperties. +func (c CapabilityProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "supportedFlexibleServerEditions", c.SupportedFlexibleServerEditions) + populate(objectMap, "supportedGeoBackupRegions", c.SupportedGeoBackupRegions) + populate(objectMap, "supportedHAMode", c.SupportedHAMode) + populate(objectMap, "zone", c.Zone) + return json.Marshal(objectMap) +} + +// CheckNameAvailabilityExecuteOptions contains the optional parameters for the CheckNameAvailability.Execute method. +type CheckNameAvailabilityExecuteOptions struct { + // placeholder for future optional parameters +} + +// CheckVirtualNetworkSubnetUsageExecuteOptions contains the optional parameters for the CheckVirtualNetworkSubnetUsage.Execute method. +type CheckVirtualNetworkSubnetUsageExecuteOptions struct { + // placeholder for future optional parameters +} + +// CloudError - An error response from the Batch service. +// Implements the error and azcore.HTTPResponse interfaces. +type CloudError struct { + raw string + // The resource management error response. + InnerError *ErrorResponse `json:"error,omitempty"` +} + +// Error implements the error interface for type CloudError. +// The contents of the error text are not contractual and subject to change. +func (e CloudError) Error() string { + return e.raw +} + +// Configuration - Represents a Configuration. +type Configuration struct { + ProxyResource + // The properties of a configuration. + Properties *ConfigurationProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Configuration. +func (c Configuration) MarshalJSON() ([]byte, error) { + objectMap := c.ProxyResource.marshalInternal() + populate(objectMap, "properties", c.Properties) + populate(objectMap, "systemData", c.SystemData) + return json.Marshal(objectMap) +} + +// ConfigurationForBatchUpdate - Represents a Configuration. +type ConfigurationForBatchUpdate struct { + // Name of the configuration. + Name *string `json:"name,omitempty"` + + // The properties can be updated for a configuration. + Properties *ConfigurationForBatchUpdateProperties `json:"properties,omitempty"` +} + +// ConfigurationForBatchUpdateProperties - The properties can be updated for a configuration. +type ConfigurationForBatchUpdateProperties struct { + // Source of the configuration. + Source *string `json:"source,omitempty"` + + // Value of the configuration. + Value *string `json:"value,omitempty"` +} + +// ConfigurationListForBatchUpdate - A list of server configurations to update. +type ConfigurationListForBatchUpdate struct { + // The list of server configurations. + Value []*ConfigurationForBatchUpdate `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ConfigurationListForBatchUpdate. +func (c ConfigurationListForBatchUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "value", c.Value) + return json.Marshal(objectMap) +} + +// ConfigurationListResult - A list of server configurations. +type ConfigurationListResult struct { + // The link used to get the next page of operations. + NextLink *string `json:"nextLink,omitempty"` + + // The list of server configurations. + Value []*Configuration `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ConfigurationListResult. +func (c ConfigurationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", c.NextLink) + populate(objectMap, "value", c.Value) + return json.Marshal(objectMap) +} + +// ConfigurationProperties - The properties of a configuration. +type ConfigurationProperties struct { + // Source of the configuration. + Source *ConfigurationSource `json:"source,omitempty"` + + // Value of the configuration. + Value *string `json:"value,omitempty"` + + // READ-ONLY; Allowed values of the configuration. + AllowedValues *string `json:"allowedValues,omitempty" azure:"ro"` + + // READ-ONLY; Data type of the configuration. + DataType *string `json:"dataType,omitempty" azure:"ro"` + + // READ-ONLY; Default value of the configuration. + DefaultValue *string `json:"defaultValue,omitempty" azure:"ro"` + + // READ-ONLY; Description of the configuration. + Description *string `json:"description,omitempty" azure:"ro"` + + // READ-ONLY; If is the configuration pending restart or not. + IsConfigPendingRestart *IsConfigPendingRestart `json:"isConfigPendingRestart,omitempty" azure:"ro"` + + // READ-ONLY; If is the configuration dynamic. + IsDynamicConfig *IsDynamicConfig `json:"isDynamicConfig,omitempty" azure:"ro"` + + // READ-ONLY; If is the configuration read only. + IsReadOnly *IsReadOnly `json:"isReadOnly,omitempty" azure:"ro"` +} + +// ConfigurationsBeginBatchUpdateOptions contains the optional parameters for the Configurations.BeginBatchUpdate method. +type ConfigurationsBeginBatchUpdateOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsBeginUpdateOptions contains the optional parameters for the Configurations.BeginUpdate method. +type ConfigurationsBeginUpdateOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsGetOptions contains the optional parameters for the Configurations.Get method. +type ConfigurationsGetOptions struct { + // placeholder for future optional parameters +} + +// ConfigurationsListByServerOptions contains the optional parameters for the Configurations.ListByServer method. +type ConfigurationsListByServerOptions struct { + // placeholder for future optional parameters +} + +// Database - Represents a Database. +type Database struct { + ProxyResource + // The properties of a database. + Properties *DatabaseProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Database. +func (d Database) MarshalJSON() ([]byte, error) { + objectMap := d.ProxyResource.marshalInternal() + populate(objectMap, "properties", d.Properties) + populate(objectMap, "systemData", d.SystemData) + return json.Marshal(objectMap) +} + +// DatabaseListResult - A List of databases. +type DatabaseListResult struct { + // The link used to get the next page of operations. + NextLink *string `json:"nextLink,omitempty"` + + // The list of databases housed in a server + Value []*Database `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type DatabaseListResult. +func (d DatabaseListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", d.NextLink) + populate(objectMap, "value", d.Value) + return json.Marshal(objectMap) +} + +// DatabaseProperties - The properties of a database. +type DatabaseProperties struct { + // The charset of the database. + Charset *string `json:"charset,omitempty"` + + // The collation of the database. + Collation *string `json:"collation,omitempty"` +} + +// DatabasesBeginCreateOrUpdateOptions contains the optional parameters for the Databases.BeginCreateOrUpdate method. +type DatabasesBeginCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// DatabasesBeginDeleteOptions contains the optional parameters for the Databases.BeginDelete method. +type DatabasesBeginDeleteOptions struct { + // placeholder for future optional parameters +} + +// DatabasesGetOptions contains the optional parameters for the Databases.Get method. +type DatabasesGetOptions struct { + // placeholder for future optional parameters +} + +// DatabasesListByServerOptions contains the optional parameters for the Databases.ListByServer method. +type DatabasesListByServerOptions struct { + // placeholder for future optional parameters +} + +// DelegatedSubnetUsage - Delegated subnet usage data. +type DelegatedSubnetUsage struct { + // READ-ONLY; name of the subnet + SubnetName *string `json:"subnetName,omitempty" azure:"ro"` + + // READ-ONLY; Number of used delegated subnets + Usage *int64 `json:"usage,omitempty" azure:"ro"` +} + +// ErrorAdditionalInfo - The resource management error additional info. +type ErrorAdditionalInfo struct { + // READ-ONLY; The additional info. + Info map[string]interface{} `json:"info,omitempty" azure:"ro"` + + // READ-ONLY; The additional info type. + Type *string `json:"type,omitempty" azure:"ro"` +} + +// ErrorResponse - Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also follows the OData +// error response format.) +type ErrorResponse struct { + // READ-ONLY; The error additional info. + AdditionalInfo []*ErrorAdditionalInfo `json:"additionalInfo,omitempty" azure:"ro"` + + // READ-ONLY; The error code. + Code *string `json:"code,omitempty" azure:"ro"` + + // READ-ONLY; The error details. + Details []*ErrorResponse `json:"details,omitempty" azure:"ro"` + + // READ-ONLY; The error message. + Message *string `json:"message,omitempty" azure:"ro"` + + // READ-ONLY; The error target. + Target *string `json:"target,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ErrorResponse. +func (e ErrorResponse) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "additionalInfo", e.AdditionalInfo) + populate(objectMap, "code", e.Code) + populate(objectMap, "details", e.Details) + populate(objectMap, "message", e.Message) + populate(objectMap, "target", e.Target) + return json.Marshal(objectMap) +} + +// FirewallRule - Represents a server firewall rule. +type FirewallRule struct { + ProxyResource + // REQUIRED; The properties of a firewall rule. + Properties *FirewallRuleProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type FirewallRule. +func (f FirewallRule) MarshalJSON() ([]byte, error) { + objectMap := f.ProxyResource.marshalInternal() + populate(objectMap, "properties", f.Properties) + populate(objectMap, "systemData", f.SystemData) + return json.Marshal(objectMap) +} + +// FirewallRuleListResult - A list of firewall rules. +type FirewallRuleListResult struct { + // The link used to get the next page of operations. + NextLink *string `json:"nextLink,omitempty"` + + // The list of firewall rules in a server. + Value []*FirewallRule `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type FirewallRuleListResult. +func (f FirewallRuleListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", f.NextLink) + populate(objectMap, "value", f.Value) + return json.Marshal(objectMap) +} + +// FirewallRuleProperties - The properties of a server firewall rule. +type FirewallRuleProperties struct { + // REQUIRED; The end IP address of the server firewall rule. Must be IPv4 format. + EndIPAddress *string `json:"endIpAddress,omitempty"` + + // REQUIRED; The start IP address of the server firewall rule. Must be IPv4 format. + StartIPAddress *string `json:"startIpAddress,omitempty"` +} + +// FirewallRulesBeginCreateOrUpdateOptions contains the optional parameters for the FirewallRules.BeginCreateOrUpdate method. +type FirewallRulesBeginCreateOrUpdateOptions struct { + // placeholder for future optional parameters +} + +// FirewallRulesBeginDeleteOptions contains the optional parameters for the FirewallRules.BeginDelete method. +type FirewallRulesBeginDeleteOptions struct { + // placeholder for future optional parameters +} + +// FirewallRulesGetOptions contains the optional parameters for the FirewallRules.Get method. +type FirewallRulesGetOptions struct { + // placeholder for future optional parameters +} + +// FirewallRulesListByServerOptions contains the optional parameters for the FirewallRules.ListByServer method. +type FirewallRulesListByServerOptions struct { + // placeholder for future optional parameters +} + +// GetPrivateDNSZoneSuffixExecuteOptions contains the optional parameters for the GetPrivateDNSZoneSuffix.Execute method. +type GetPrivateDNSZoneSuffixExecuteOptions struct { + // placeholder for future optional parameters +} + +// GetPrivateDNSZoneSuffixResponse - The response of get private dns zone suffix. +type GetPrivateDNSZoneSuffixResponse struct { + // Represents the private DNS zone suffix. + PrivateDNSZoneSuffix *string `json:"privateDnsZoneSuffix,omitempty"` +} + +// HighAvailability - Network related properties of a server +type HighAvailability struct { + // High availability mode for a server. + Mode *HighAvailabilityMode `json:"mode,omitempty"` + + // Availability zone of the standby server. + StandbyAvailabilityZone *string `json:"standbyAvailabilityZone,omitempty"` + + // READ-ONLY; The state of server high availability. + State *HighAvailabilityState `json:"state,omitempty" azure:"ro"` +} + +// LocationBasedCapabilitiesListOptions contains the optional parameters for the LocationBasedCapabilities.List method. +type LocationBasedCapabilitiesListOptions struct { + // placeholder for future optional parameters +} + +// MaintenanceWindow - Maintenance window of a server. +type MaintenanceWindow struct { + // indicates whether custom window is enabled or disabled + CustomWindow *string `json:"customWindow,omitempty"` + + // day of week for maintenance window + DayOfWeek *int32 `json:"dayOfWeek,omitempty"` + + // start hour for maintenance window + StartHour *int32 `json:"startHour,omitempty"` + + // start minute for maintenance window + StartMinute *int32 `json:"startMinute,omitempty"` +} + +// NameAvailability - Represents a resource name availability. +type NameAvailability struct { + // Error Message. + Message *string `json:"message,omitempty"` + + // Indicates whether the resource name is available. + NameAvailable *bool `json:"nameAvailable,omitempty"` + + // Reason for name being unavailable. + Reason *string `json:"reason,omitempty"` +} + +// NameAvailabilityRequest - Request from client to check resource name availability. +type NameAvailabilityRequest struct { + // REQUIRED; Resource name to verify. + Name *string `json:"name,omitempty"` + + // Resource type used for verification. + Type *string `json:"type,omitempty"` +} + +// Network related properties of a server +type Network struct { + // Delegated subnet resource id used to setup vnet for a server. + DelegatedSubnetResourceID *string `json:"delegatedSubnetResourceId,omitempty"` + + // Private DNS zone resource id. + PrivateDNSZoneResourceID *string `json:"privateDnsZoneResourceId,omitempty"` + + // READ-ONLY; Whether or not public network access is allowed for this server. Value is 'Disabled' when server has VNet integration. + PublicNetworkAccess *EnableStatusEnum `json:"publicNetworkAccess,omitempty" azure:"ro"` +} + +// Operation - REST API operation definition. +type Operation struct { + // The localized display information for this particular operation or action. + Display *OperationDisplay `json:"display,omitempty"` + + // The name of the operation being performed on this particular object. + Name *string `json:"name,omitempty"` + + // The intended executor of the operation. + Origin *string `json:"origin,omitempty"` + + // Additional descriptions for the operation. + Properties map[string]map[string]interface{} `json:"properties,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type Operation. +func (o Operation) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "display", o.Display) + populate(objectMap, "name", o.Name) + populate(objectMap, "origin", o.Origin) + populate(objectMap, "properties", o.Properties) + return json.Marshal(objectMap) +} + +// OperationDisplay - Display metadata associated with the operation. +type OperationDisplay struct { + // Operation description. + Description *string `json:"description,omitempty"` + + // Localized friendly name for the operation. + Operation *string `json:"operation,omitempty"` + + // Operation resource provider name. + Provider *string `json:"provider,omitempty"` + + // Resource on which the operation is performed. + Resource *string `json:"resource,omitempty"` +} + +// OperationListResult - A list of resource provider operations. +type OperationListResult struct { + // URL client should use to fetch the next page (per server side paging). + NextLink *string `json:"nextLink,omitempty"` + + // Collection of available operation details + Value []*Operation `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type OperationListResult. +func (o OperationListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", o.NextLink) + populate(objectMap, "value", o.Value) + return json.Marshal(objectMap) +} + +// OperationsListOptions contains the optional parameters for the Operations.List method. +type OperationsListOptions struct { + // placeholder for future optional parameters +} + +// ProxyResource - The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location +type ProxyResource struct { + Resource +} + +func (p ProxyResource) marshalInternal() map[string]interface{} { + objectMap := p.Resource.marshalInternal() + return objectMap +} + +// ReplicasListByServerOptions contains the optional parameters for the Replicas.ListByServer method. +type ReplicasListByServerOptions struct { + // placeholder for future optional parameters +} + +// Resource - Common fields that are returned in the response for all Azure Resource Manager resources +type Resource struct { + // READ-ONLY; Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} + ID *string `json:"id,omitempty" azure:"ro"` + + // READ-ONLY; The name of the resource + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts" + Type *string `json:"type,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Resource. +func (r Resource) MarshalJSON() ([]byte, error) { + objectMap := r.marshalInternal() + return json.Marshal(objectMap) +} + +func (r Resource) marshalInternal() map[string]interface{} { + objectMap := make(map[string]interface{}) + populate(objectMap, "id", r.ID) + populate(objectMap, "name", r.Name) + populate(objectMap, "type", r.Type) + return objectMap +} + +// SKU - Billing information related properties of a server. +type SKU struct { + // REQUIRED; The name of the sku, e.g. StandardD32sv3. + Name *string `json:"name,omitempty"` + + // REQUIRED; The tier of the particular SKU, e.g. GeneralPurpose. + Tier *SKUTier `json:"tier,omitempty"` +} + +// SKUCapability - Sku capability +type SKUCapability struct { + // READ-ONLY; vCore name + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; supported IOPS + SupportedIops *int64 `json:"supportedIops,omitempty" azure:"ro"` + + // READ-ONLY; supported memory per vCore in MB + SupportedMemoryPerVCoreMB *int64 `json:"supportedMemoryPerVCoreMB,omitempty" azure:"ro"` + + // READ-ONLY; supported vCores + VCores *int64 `json:"vCores,omitempty" azure:"ro"` +} + +// Server - Represents a server. +type Server struct { + TrackedResource + // Properties of the server. + Properties *ServerProperties `json:"properties,omitempty"` + + // The SKU (pricing tier) of the server. + SKU *SKU `json:"sku,omitempty"` + + // READ-ONLY; The system metadata relating to this resource. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type Server. +func (s Server) MarshalJSON() ([]byte, error) { + objectMap := s.TrackedResource.marshalInternal() + populate(objectMap, "properties", s.Properties) + populate(objectMap, "sku", s.SKU) + populate(objectMap, "systemData", s.SystemData) + return json.Marshal(objectMap) +} + +// ServerBackup - Server backup properties +type ServerBackup struct { + ProxyResource + // The properties of a server backup. + Properties *ServerBackupProperties `json:"properties,omitempty"` + + // READ-ONLY; The system metadata relating to this resource. + SystemData *SystemData `json:"systemData,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerBackup. +func (s ServerBackup) MarshalJSON() ([]byte, error) { + objectMap := s.ProxyResource.marshalInternal() + populate(objectMap, "properties", s.Properties) + populate(objectMap, "systemData", s.SystemData) + return json.Marshal(objectMap) +} + +// ServerBackupListResult - A list of server backups. +type ServerBackupListResult struct { + // The link used to get the next page of operations. + NextLink *string `json:"nextLink,omitempty"` + + // The list of backups of a server. + Value []*ServerBackup `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerBackupListResult. +func (s ServerBackupListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// ServerBackupProperties - The properties of a server backup. +type ServerBackupProperties struct { + // Backup type. + BackupType *string `json:"backupType,omitempty"` + + // Backup completed time (ISO8601 format). + CompletedTime *time.Time `json:"completedTime,omitempty"` + + // Backup source + Source *string `json:"source,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerBackupProperties. +func (s ServerBackupProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "backupType", s.BackupType) + populate(objectMap, "completedTime", (*timeRFC3339)(s.CompletedTime)) + populate(objectMap, "source", s.Source) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ServerBackupProperties. +func (s *ServerBackupProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "backupType": + err = unpopulate(val, &s.BackupType) + delete(rawMsg, key) + case "completedTime": + var aux timeRFC3339 + err = unpopulate(val, &aux) + s.CompletedTime = (*time.Time)(&aux) + delete(rawMsg, key) + case "source": + err = unpopulate(val, &s.Source) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ServerEditionCapability - Server edition capabilities. +type ServerEditionCapability struct { + // READ-ONLY; Server edition name + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; A list of supported server versions. + SupportedServerVersions []*ServerVersionCapability `json:"supportedServerVersions,omitempty" azure:"ro"` + + // READ-ONLY; A list of supported storage editions + SupportedStorageEditions []*StorageEditionCapability `json:"supportedStorageEditions,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerEditionCapability. +func (s ServerEditionCapability) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "name", s.Name) + populate(objectMap, "supportedServerVersions", s.SupportedServerVersions) + populate(objectMap, "supportedStorageEditions", s.SupportedStorageEditions) + return json.Marshal(objectMap) +} + +// ServerForUpdate - Parameters allowed to update for a server. +type ServerForUpdate struct { + // The properties that can be updated for a server. + Properties *ServerPropertiesForUpdate `json:"properties,omitempty"` + + // The SKU (pricing tier) of the server. + SKU *SKU `json:"sku,omitempty"` + + // Application-specific metadata in the form of key-value pairs. + Tags map[string]*string `json:"tags,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerForUpdate. +func (s ServerForUpdate) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "properties", s.Properties) + populate(objectMap, "sku", s.SKU) + populate(objectMap, "tags", s.Tags) + return json.Marshal(objectMap) +} + +// ServerListResult - A list of servers. +type ServerListResult struct { + // The link used to get the next page of operations. + NextLink *string `json:"nextLink,omitempty"` + + // The list of servers + Value []*Server `json:"value,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerListResult. +func (s ServerListResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "nextLink", s.NextLink) + populate(objectMap, "value", s.Value) + return json.Marshal(objectMap) +} + +// ServerProperties - The properties of a server. +type ServerProperties struct { + // The administrator's login name of a server. Can only be specified when the server is being created (and is required for creation). + AdministratorLogin *string `json:"administratorLogin,omitempty"` + + // The password of the administrator login (required for server creation). + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + + // availability Zone information of the server. + AvailabilityZone *string `json:"availabilityZone,omitempty"` + + // Backup related properties of a server. + Backup *Backup `json:"backup,omitempty"` + + // The mode to create a new MySQL server. + CreateMode *CreateMode `json:"createMode,omitempty"` + + // High availability related properties of a server. + HighAvailability *HighAvailability `json:"highAvailability,omitempty"` + + // Maintenance window of a server. + MaintenanceWindow *MaintenanceWindow `json:"maintenanceWindow,omitempty"` + + // Network related properties of a server. + Network *Network `json:"network,omitempty"` + + // The replication role. + ReplicationRole *ReplicationRole `json:"replicationRole,omitempty"` + + // Restore point creation time (ISO8601 format), specifying the time to restore from. + RestorePointInTime *time.Time `json:"restorePointInTime,omitempty"` + + // The source MySQL server id. + SourceServerResourceID *string `json:"sourceServerResourceId,omitempty"` + + // Storage related properties of a server. + Storage *Storage `json:"storage,omitempty"` + + // Server version. + Version *ServerVersion `json:"version,omitempty"` + + // READ-ONLY; The fully qualified domain name of a server. + FullyQualifiedDomainName *string `json:"fullyQualifiedDomainName,omitempty" azure:"ro"` + + // READ-ONLY; The maximum number of replicas that a primary server can have. + ReplicaCapacity *int32 `json:"replicaCapacity,omitempty" azure:"ro"` + + // READ-ONLY; The state of a server. + State *ServerState `json:"state,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerProperties. +func (s ServerProperties) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "administratorLogin", s.AdministratorLogin) + populate(objectMap, "administratorLoginPassword", s.AdministratorLoginPassword) + populate(objectMap, "availabilityZone", s.AvailabilityZone) + populate(objectMap, "backup", s.Backup) + populate(objectMap, "createMode", s.CreateMode) + populate(objectMap, "fullyQualifiedDomainName", s.FullyQualifiedDomainName) + populate(objectMap, "highAvailability", s.HighAvailability) + populate(objectMap, "maintenanceWindow", s.MaintenanceWindow) + populate(objectMap, "network", s.Network) + populate(objectMap, "replicaCapacity", s.ReplicaCapacity) + populate(objectMap, "replicationRole", s.ReplicationRole) + populate(objectMap, "restorePointInTime", (*timeRFC3339)(s.RestorePointInTime)) + populate(objectMap, "sourceServerResourceId", s.SourceServerResourceID) + populate(objectMap, "state", s.State) + populate(objectMap, "storage", s.Storage) + populate(objectMap, "version", s.Version) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type ServerProperties. +func (s *ServerProperties) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "administratorLogin": + err = unpopulate(val, &s.AdministratorLogin) + delete(rawMsg, key) + case "administratorLoginPassword": + err = unpopulate(val, &s.AdministratorLoginPassword) + delete(rawMsg, key) + case "availabilityZone": + err = unpopulate(val, &s.AvailabilityZone) + delete(rawMsg, key) + case "backup": + err = unpopulate(val, &s.Backup) + delete(rawMsg, key) + case "createMode": + err = unpopulate(val, &s.CreateMode) + delete(rawMsg, key) + case "fullyQualifiedDomainName": + err = unpopulate(val, &s.FullyQualifiedDomainName) + delete(rawMsg, key) + case "highAvailability": + err = unpopulate(val, &s.HighAvailability) + delete(rawMsg, key) + case "maintenanceWindow": + err = unpopulate(val, &s.MaintenanceWindow) + delete(rawMsg, key) + case "network": + err = unpopulate(val, &s.Network) + delete(rawMsg, key) + case "replicaCapacity": + err = unpopulate(val, &s.ReplicaCapacity) + delete(rawMsg, key) + case "replicationRole": + err = unpopulate(val, &s.ReplicationRole) + delete(rawMsg, key) + case "restorePointInTime": + var aux timeRFC3339 + err = unpopulate(val, &aux) + s.RestorePointInTime = (*time.Time)(&aux) + delete(rawMsg, key) + case "sourceServerResourceId": + err = unpopulate(val, &s.SourceServerResourceID) + delete(rawMsg, key) + case "state": + err = unpopulate(val, &s.State) + delete(rawMsg, key) + case "storage": + err = unpopulate(val, &s.Storage) + delete(rawMsg, key) + case "version": + err = unpopulate(val, &s.Version) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// ServerPropertiesForUpdate - The properties that can be updated for a server. +type ServerPropertiesForUpdate struct { + // The password of the administrator login. + AdministratorLoginPassword *string `json:"administratorLoginPassword,omitempty"` + + // Backup related properties of a server. + Backup *Backup `json:"backup,omitempty"` + + // High availability related properties of a server. + HighAvailability *HighAvailability `json:"highAvailability,omitempty"` + + // Maintenance window of a server. + MaintenanceWindow *MaintenanceWindow `json:"maintenanceWindow,omitempty"` + + // The replication role of the server. + ReplicationRole *ReplicationRole `json:"replicationRole,omitempty"` + + // Storage related properties of a server. + Storage *Storage `json:"storage,omitempty"` +} + +// ServerRestartParameter - Server restart parameters. +type ServerRestartParameter struct { + // The maximum allowed failover time in seconds. + MaxFailoverSeconds *int32 `json:"maxFailoverSeconds,omitempty"` + + // Whether or not failover to standby server when restarting a server with high availability enabled. + RestartWithFailover *EnableStatusEnum `json:"restartWithFailover,omitempty"` +} + +// ServerVersionCapability - Server version capabilities. +type ServerVersionCapability struct { + // READ-ONLY; server version + Name *string `json:"name,omitempty" azure:"ro"` + + // READ-ONLY; A list of supported Skus + SupportedSKUs []*SKUCapability `json:"supportedSkus,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type ServerVersionCapability. +func (s ServerVersionCapability) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "name", s.Name) + populate(objectMap, "supportedSkus", s.SupportedSKUs) + return json.Marshal(objectMap) +} + +// ServersBeginCreateOptions contains the optional parameters for the Servers.BeginCreate method. +type ServersBeginCreateOptions struct { + // placeholder for future optional parameters +} + +// ServersBeginDeleteOptions contains the optional parameters for the Servers.BeginDelete method. +type ServersBeginDeleteOptions struct { + // placeholder for future optional parameters +} + +// ServersBeginFailoverOptions contains the optional parameters for the Servers.BeginFailover method. +type ServersBeginFailoverOptions struct { + // placeholder for future optional parameters +} + +// ServersBeginRestartOptions contains the optional parameters for the Servers.BeginRestart method. +type ServersBeginRestartOptions struct { + // placeholder for future optional parameters +} + +// ServersBeginStartOptions contains the optional parameters for the Servers.BeginStart method. +type ServersBeginStartOptions struct { + // placeholder for future optional parameters +} + +// ServersBeginStopOptions contains the optional parameters for the Servers.BeginStop method. +type ServersBeginStopOptions struct { + // placeholder for future optional parameters +} + +// ServersBeginUpdateOptions contains the optional parameters for the Servers.BeginUpdate method. +type ServersBeginUpdateOptions struct { + // placeholder for future optional parameters +} + +// ServersGetOptions contains the optional parameters for the Servers.Get method. +type ServersGetOptions struct { + // placeholder for future optional parameters +} + +// ServersListByResourceGroupOptions contains the optional parameters for the Servers.ListByResourceGroup method. +type ServersListByResourceGroupOptions struct { + // placeholder for future optional parameters +} + +// ServersListOptions contains the optional parameters for the Servers.List method. +type ServersListOptions struct { + // placeholder for future optional parameters +} + +// Storage Profile properties of a server +type Storage struct { + // Enable Storage Auto Grow or not. + AutoGrow *EnableStatusEnum `json:"autoGrow,omitempty"` + + // Storage IOPS for a server. + Iops *int32 `json:"iops,omitempty"` + + // Max storage size allowed for a server. + StorageSizeGB *int32 `json:"storageSizeGB,omitempty"` + + // READ-ONLY; The sku name of the server storage. + StorageSKU *string `json:"storageSku,omitempty" azure:"ro"` +} + +// StorageEditionCapability - storage edition capability +type StorageEditionCapability struct { + // READ-ONLY; Maximum backup retention days + MaxBackupRetentionDays *int64 `json:"maxBackupRetentionDays,omitempty" azure:"ro"` + + // READ-ONLY; The maximum supported storage size. + MaxStorageSize *int64 `json:"maxStorageSize,omitempty" azure:"ro"` + + // READ-ONLY; Minimal backup retention days + MinBackupRetentionDays *int64 `json:"minBackupRetentionDays,omitempty" azure:"ro"` + + // READ-ONLY; The minimal supported storage size. + MinStorageSize *int64 `json:"minStorageSize,omitempty" azure:"ro"` + + // READ-ONLY; storage edition name + Name *string `json:"name,omitempty" azure:"ro"` +} + +// SystemData - Metadata pertaining to creation and last modification of the resource. +type SystemData struct { + // The timestamp of resource creation (UTC). + CreatedAt *time.Time `json:"createdAt,omitempty"` + + // The identity that created the resource. + CreatedBy *string `json:"createdBy,omitempty"` + + // The type of identity that created the resource. + CreatedByType *CreatedByType `json:"createdByType,omitempty"` + + // The timestamp of resource last modification (UTC) + LastModifiedAt *time.Time `json:"lastModifiedAt,omitempty"` + + // The identity that last modified the resource. + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + + // The type of identity that last modified the resource. + LastModifiedByType *CreatedByType `json:"lastModifiedByType,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type SystemData. +func (s SystemData) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "createdAt", (*timeRFC3339)(s.CreatedAt)) + populate(objectMap, "createdBy", s.CreatedBy) + populate(objectMap, "createdByType", s.CreatedByType) + populate(objectMap, "lastModifiedAt", (*timeRFC3339)(s.LastModifiedAt)) + populate(objectMap, "lastModifiedBy", s.LastModifiedBy) + populate(objectMap, "lastModifiedByType", s.LastModifiedByType) + return json.Marshal(objectMap) +} + +// UnmarshalJSON implements the json.Unmarshaller interface for type SystemData. +func (s *SystemData) UnmarshalJSON(data []byte) error { + var rawMsg map[string]json.RawMessage + if err := json.Unmarshal(data, &rawMsg); err != nil { + return err + } + for key, val := range rawMsg { + var err error + switch key { + case "createdAt": + var aux timeRFC3339 + err = unpopulate(val, &aux) + s.CreatedAt = (*time.Time)(&aux) + delete(rawMsg, key) + case "createdBy": + err = unpopulate(val, &s.CreatedBy) + delete(rawMsg, key) + case "createdByType": + err = unpopulate(val, &s.CreatedByType) + delete(rawMsg, key) + case "lastModifiedAt": + var aux timeRFC3339 + err = unpopulate(val, &aux) + s.LastModifiedAt = (*time.Time)(&aux) + delete(rawMsg, key) + case "lastModifiedBy": + err = unpopulate(val, &s.LastModifiedBy) + delete(rawMsg, key) + case "lastModifiedByType": + err = unpopulate(val, &s.LastModifiedByType) + delete(rawMsg, key) + } + if err != nil { + return err + } + } + return nil +} + +// TrackedResource - The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location' +type TrackedResource struct { + Resource + // REQUIRED; The geo-location where the resource lives + Location *string `json:"location,omitempty"` + + // Resource tags. + Tags map[string]*string `json:"tags,omitempty"` +} + +// MarshalJSON implements the json.Marshaller interface for type TrackedResource. +func (t TrackedResource) MarshalJSON() ([]byte, error) { + objectMap := t.marshalInternal() + return json.Marshal(objectMap) +} + +func (t TrackedResource) marshalInternal() map[string]interface{} { + objectMap := t.Resource.marshalInternal() + populate(objectMap, "location", t.Location) + populate(objectMap, "tags", t.Tags) + return objectMap +} + +// VirtualNetworkSubnetUsageParameter - Virtual network subnet usage parameter +type VirtualNetworkSubnetUsageParameter struct { + // Virtual network resource id. + VirtualNetworkResourceID *string `json:"virtualNetworkResourceId,omitempty"` +} + +// VirtualNetworkSubnetUsageResult - Virtual network subnet usage data. +type VirtualNetworkSubnetUsageResult struct { + // READ-ONLY; A list of delegated subnet usage + DelegatedSubnetsUsage []*DelegatedSubnetUsage `json:"delegatedSubnetsUsage,omitempty" azure:"ro"` +} + +// MarshalJSON implements the json.Marshaller interface for type VirtualNetworkSubnetUsageResult. +func (v VirtualNetworkSubnetUsageResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + populate(objectMap, "delegatedSubnetsUsage", v.DelegatedSubnetsUsage) + return json.Marshal(objectMap) +} + +func populate(m map[string]interface{}, k string, v interface{}) { + if v == nil { + return + } else if azcore.IsNullValue(v) { + m[k] = nil + } else if !reflect.ValueOf(v).IsNil() { + m[k] = v + } +} + +func unpopulate(data json.RawMessage, v interface{}) error { + if data == nil { + return nil + } + return json.Unmarshal(data, v) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_operations_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_operations_client.go new file mode 100644 index 000000000000..97c7398f435e --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_operations_client.go @@ -0,0 +1,81 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "fmt" + "net/http" + + "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" +) + +// OperationsClient contains the methods for the Operations group. +// Don't use this type directly, use NewOperationsClient() instead. +type OperationsClient struct { + ep string + pl runtime.Pipeline +} + +// NewOperationsClient creates a new instance of OperationsClient with the specified values. +func NewOperationsClient(con *arm.Connection) *OperationsClient { + return &OperationsClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version)} +} + +// List - Lists all of the available REST API operations. +// If the operation fails it returns the *CloudError error type. +func (client *OperationsClient) List(options *OperationsListOptions) *OperationsListPager { + return &OperationsListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp OperationsListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.OperationListResult.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *OperationsClient) listCreateRequest(ctx context.Context, options *OperationsListOptions) (*policy.Request, error) { + urlPath := "/providers/Microsoft.DBforMySQL/operations" + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *OperationsClient) listHandleResponse(resp *http.Response) (OperationsListResponse, error) { + result := OperationsListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.OperationListResult); err != nil { + return OperationsListResponse{}, err + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *OperationsClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_pagers.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_pagers.go new file mode 100644 index 000000000000..698e0d1f2a09 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_pagers.go @@ -0,0 +1,504 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "net/http" + "reflect" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" +) + +// BackupsListByServerPager provides operations for iterating over paged responses. +type BackupsListByServerPager struct { + client *BackupsClient + current BackupsListByServerResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, BackupsListByServerResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *BackupsListByServerPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *BackupsListByServerPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ServerBackupListResult.NextLink == nil || len(*p.current.ServerBackupListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByServerHandleError(resp) + return false + } + result, err := p.client.listByServerHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current BackupsListByServerResponse page. +func (p *BackupsListByServerPager) PageResponse() BackupsListByServerResponse { + return p.current +} + +// ConfigurationsListByServerPager provides operations for iterating over paged responses. +type ConfigurationsListByServerPager struct { + client *ConfigurationsClient + current ConfigurationsListByServerResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ConfigurationsListByServerResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ConfigurationsListByServerPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ConfigurationsListByServerPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ConfigurationListResult.NextLink == nil || len(*p.current.ConfigurationListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByServerHandleError(resp) + return false + } + result, err := p.client.listByServerHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ConfigurationsListByServerResponse page. +func (p *ConfigurationsListByServerPager) PageResponse() ConfigurationsListByServerResponse { + return p.current +} + +// DatabasesListByServerPager provides operations for iterating over paged responses. +type DatabasesListByServerPager struct { + client *DatabasesClient + current DatabasesListByServerResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, DatabasesListByServerResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *DatabasesListByServerPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *DatabasesListByServerPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.DatabaseListResult.NextLink == nil || len(*p.current.DatabaseListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByServerHandleError(resp) + return false + } + result, err := p.client.listByServerHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current DatabasesListByServerResponse page. +func (p *DatabasesListByServerPager) PageResponse() DatabasesListByServerResponse { + return p.current +} + +// FirewallRulesListByServerPager provides operations for iterating over paged responses. +type FirewallRulesListByServerPager struct { + client *FirewallRulesClient + current FirewallRulesListByServerResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, FirewallRulesListByServerResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *FirewallRulesListByServerPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *FirewallRulesListByServerPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.FirewallRuleListResult.NextLink == nil || len(*p.current.FirewallRuleListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByServerHandleError(resp) + return false + } + result, err := p.client.listByServerHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current FirewallRulesListByServerResponse page. +func (p *FirewallRulesListByServerPager) PageResponse() FirewallRulesListByServerResponse { + return p.current +} + +// LocationBasedCapabilitiesListPager provides operations for iterating over paged responses. +type LocationBasedCapabilitiesListPager struct { + client *LocationBasedCapabilitiesClient + current LocationBasedCapabilitiesListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, LocationBasedCapabilitiesListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *LocationBasedCapabilitiesListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *LocationBasedCapabilitiesListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.CapabilitiesListResult.NextLink == nil || len(*p.current.CapabilitiesListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current LocationBasedCapabilitiesListResponse page. +func (p *LocationBasedCapabilitiesListPager) PageResponse() LocationBasedCapabilitiesListResponse { + return p.current +} + +// OperationsListPager provides operations for iterating over paged responses. +type OperationsListPager struct { + client *OperationsClient + current OperationsListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, OperationsListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *OperationsListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *OperationsListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.OperationListResult.NextLink == nil || len(*p.current.OperationListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current OperationsListResponse page. +func (p *OperationsListPager) PageResponse() OperationsListResponse { + return p.current +} + +// ReplicasListByServerPager provides operations for iterating over paged responses. +type ReplicasListByServerPager struct { + client *ReplicasClient + current ReplicasListByServerResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ReplicasListByServerResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ReplicasListByServerPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ReplicasListByServerPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ServerListResult.NextLink == nil || len(*p.current.ServerListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByServerHandleError(resp) + return false + } + result, err := p.client.listByServerHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ReplicasListByServerResponse page. +func (p *ReplicasListByServerPager) PageResponse() ReplicasListByServerResponse { + return p.current +} + +// ServersListByResourceGroupPager provides operations for iterating over paged responses. +type ServersListByResourceGroupPager struct { + client *ServersClient + current ServersListByResourceGroupResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ServersListByResourceGroupResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ServersListByResourceGroupPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ServersListByResourceGroupPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ServerListResult.NextLink == nil || len(*p.current.ServerListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listByResourceGroupHandleError(resp) + return false + } + result, err := p.client.listByResourceGroupHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ServersListByResourceGroupResponse page. +func (p *ServersListByResourceGroupPager) PageResponse() ServersListByResourceGroupResponse { + return p.current +} + +// ServersListPager provides operations for iterating over paged responses. +type ServersListPager struct { + client *ServersClient + current ServersListResponse + err error + requester func(context.Context) (*policy.Request, error) + advancer func(context.Context, ServersListResponse) (*policy.Request, error) +} + +// Err returns the last error encountered while paging. +func (p *ServersListPager) Err() error { + return p.err +} + +// NextPage returns true if the pager advanced to the next page. +// Returns false if there are no more pages or an error occurred. +func (p *ServersListPager) NextPage(ctx context.Context) bool { + var req *policy.Request + var err error + if !reflect.ValueOf(p.current).IsZero() { + if p.current.ServerListResult.NextLink == nil || len(*p.current.ServerListResult.NextLink) == 0 { + return false + } + req, err = p.advancer(ctx, p.current) + } else { + req, err = p.requester(ctx) + } + if err != nil { + p.err = err + return false + } + resp, err := p.client.pl.Do(req) + if err != nil { + p.err = err + return false + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + p.err = p.client.listHandleError(resp) + return false + } + result, err := p.client.listHandleResponse(resp) + if err != nil { + p.err = err + return false + } + p.current = result + return true +} + +// PageResponse returns the current ServersListResponse page. +func (p *ServersListPager) PageResponse() ServersListResponse { + return p.current +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_pollers.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_pollers.go new file mode 100644 index 000000000000..47e231ff0171 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_pollers.go @@ -0,0 +1,575 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "net/http" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" +) + +// ConfigurationsBatchUpdatePoller provides polling facilities until the operation reaches a terminal state. +type ConfigurationsBatchUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ConfigurationsBatchUpdatePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ConfigurationsBatchUpdatePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ConfigurationsBatchUpdateResponse will be returned. +func (p *ConfigurationsBatchUpdatePoller) FinalResponse(ctx context.Context) (ConfigurationsBatchUpdateResponse, error) { + respType := ConfigurationsBatchUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.ConfigurationListResult) + if err != nil { + return ConfigurationsBatchUpdateResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ConfigurationsBatchUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ConfigurationsUpdatePoller provides polling facilities until the operation reaches a terminal state. +type ConfigurationsUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ConfigurationsUpdatePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ConfigurationsUpdatePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ConfigurationsUpdateResponse will be returned. +func (p *ConfigurationsUpdatePoller) FinalResponse(ctx context.Context) (ConfigurationsUpdateResponse, error) { + respType := ConfigurationsUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.Configuration) + if err != nil { + return ConfigurationsUpdateResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ConfigurationsUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// DatabasesCreateOrUpdatePoller provides polling facilities until the operation reaches a terminal state. +type DatabasesCreateOrUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *DatabasesCreateOrUpdatePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *DatabasesCreateOrUpdatePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final DatabasesCreateOrUpdateResponse will be returned. +func (p *DatabasesCreateOrUpdatePoller) FinalResponse(ctx context.Context) (DatabasesCreateOrUpdateResponse, error) { + respType := DatabasesCreateOrUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.Database) + if err != nil { + return DatabasesCreateOrUpdateResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *DatabasesCreateOrUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// DatabasesDeletePoller provides polling facilities until the operation reaches a terminal state. +type DatabasesDeletePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *DatabasesDeletePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *DatabasesDeletePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final DatabasesDeleteResponse will be returned. +func (p *DatabasesDeletePoller) FinalResponse(ctx context.Context) (DatabasesDeleteResponse, error) { + respType := DatabasesDeleteResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return DatabasesDeleteResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *DatabasesDeletePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// FirewallRulesCreateOrUpdatePoller provides polling facilities until the operation reaches a terminal state. +type FirewallRulesCreateOrUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *FirewallRulesCreateOrUpdatePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *FirewallRulesCreateOrUpdatePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final FirewallRulesCreateOrUpdateResponse will be returned. +func (p *FirewallRulesCreateOrUpdatePoller) FinalResponse(ctx context.Context) (FirewallRulesCreateOrUpdateResponse, error) { + respType := FirewallRulesCreateOrUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.FirewallRule) + if err != nil { + return FirewallRulesCreateOrUpdateResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *FirewallRulesCreateOrUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// FirewallRulesDeletePoller provides polling facilities until the operation reaches a terminal state. +type FirewallRulesDeletePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *FirewallRulesDeletePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *FirewallRulesDeletePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final FirewallRulesDeleteResponse will be returned. +func (p *FirewallRulesDeletePoller) FinalResponse(ctx context.Context) (FirewallRulesDeleteResponse, error) { + respType := FirewallRulesDeleteResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return FirewallRulesDeleteResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *FirewallRulesDeletePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServersCreatePoller provides polling facilities until the operation reaches a terminal state. +type ServersCreatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServersCreatePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ServersCreatePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ServersCreateResponse will be returned. +func (p *ServersCreatePoller) FinalResponse(ctx context.Context) (ServersCreateResponse, error) { + respType := ServersCreateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.Server) + if err != nil { + return ServersCreateResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ServersCreatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServersDeletePoller provides polling facilities until the operation reaches a terminal state. +type ServersDeletePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServersDeletePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ServersDeletePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ServersDeleteResponse will be returned. +func (p *ServersDeletePoller) FinalResponse(ctx context.Context) (ServersDeleteResponse, error) { + respType := ServersDeleteResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServersDeleteResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ServersDeletePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServersFailoverPoller provides polling facilities until the operation reaches a terminal state. +type ServersFailoverPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServersFailoverPoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ServersFailoverPoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ServersFailoverResponse will be returned. +func (p *ServersFailoverPoller) FinalResponse(ctx context.Context) (ServersFailoverResponse, error) { + respType := ServersFailoverResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServersFailoverResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ServersFailoverPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServersRestartPoller provides polling facilities until the operation reaches a terminal state. +type ServersRestartPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServersRestartPoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ServersRestartPoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ServersRestartResponse will be returned. +func (p *ServersRestartPoller) FinalResponse(ctx context.Context) (ServersRestartResponse, error) { + respType := ServersRestartResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServersRestartResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ServersRestartPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServersStartPoller provides polling facilities until the operation reaches a terminal state. +type ServersStartPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServersStartPoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ServersStartPoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ServersStartResponse will be returned. +func (p *ServersStartPoller) FinalResponse(ctx context.Context) (ServersStartResponse, error) { + respType := ServersStartResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServersStartResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ServersStartPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServersStopPoller provides polling facilities until the operation reaches a terminal state. +type ServersStopPoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServersStopPoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ServersStopPoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ServersStopResponse will be returned. +func (p *ServersStopPoller) FinalResponse(ctx context.Context) (ServersStopResponse, error) { + respType := ServersStopResponse{} + resp, err := p.pt.FinalResponse(ctx, nil) + if err != nil { + return ServersStopResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ServersStopPoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} + +// ServersUpdatePoller provides polling facilities until the operation reaches a terminal state. +type ServersUpdatePoller struct { + pt *azcore.Poller +} + +// Done returns true if the LRO has reached a terminal state. +func (p *ServersUpdatePoller) Done() bool { + return p.pt.Done() +} + +// Poll fetches the latest state of the LRO. It returns an HTTP response or error. +// If the LRO has completed successfully, the poller's state is updated and the HTTP +// response is returned. +// If the LRO has completed with failure or was cancelled, the poller's state is +// updated and the error is returned. +// If the LRO has not reached a terminal state, the poller's state is updated and +// the latest HTTP response is returned. +// If Poll fails, the poller's state is unmodified and the error is returned. +// Calling Poll on an LRO that has reached a terminal state will return the final +// HTTP response or error. +func (p *ServersUpdatePoller) Poll(ctx context.Context) (*http.Response, error) { + return p.pt.Poll(ctx) +} + +// FinalResponse performs a final GET to the service and returns the final response +// for the polling operation. If there is an error performing the final GET then an error is returned. +// If the final GET succeeded then the final ServersUpdateResponse will be returned. +func (p *ServersUpdatePoller) FinalResponse(ctx context.Context) (ServersUpdateResponse, error) { + respType := ServersUpdateResponse{} + resp, err := p.pt.FinalResponse(ctx, &respType.Server) + if err != nil { + return ServersUpdateResponse{}, err + } + respType.RawResponse = resp + return respType, nil +} + +// ResumeToken returns a value representing the poller that can be used to resume +// the LRO at a later time. ResumeTokens are unique per service operation. +func (p *ServersUpdatePoller) ResumeToken() (string, error) { + return p.pt.ResumeToken() +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_replicas_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_replicas_client.go new file mode 100644 index 000000000000..12c7b832bedf --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_replicas_client.go @@ -0,0 +1,97 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "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" +) + +// ReplicasClient contains the methods for the Replicas group. +// Don't use this type directly, use NewReplicasClient() instead. +type ReplicasClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewReplicasClient creates a new instance of ReplicasClient with the specified values. +func NewReplicasClient(con *arm.Connection, subscriptionID string) *ReplicasClient { + return &ReplicasClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// ListByServer - List all the replicas for a given server. +// If the operation fails it returns the *CloudError error type. +func (client *ReplicasClient) ListByServer(resourceGroupName string, serverName string, options *ReplicasListByServerOptions) *ReplicasListByServerPager { + return &ReplicasListByServerPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByServerCreateRequest(ctx, resourceGroupName, serverName, options) + }, + advancer: func(ctx context.Context, resp ReplicasListByServerResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ServerListResult.NextLink) + }, + } +} + +// listByServerCreateRequest creates the ListByServer request. +func (client *ReplicasClient) listByServerCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *ReplicasListByServerOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/replicas" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByServerHandleResponse handles the ListByServer response. +func (client *ReplicasClient) listByServerHandleResponse(resp *http.Response) (ReplicasListByServerResponse, error) { + result := ReplicasListByServerResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerListResult); err != nil { + return ReplicasListByServerResponse{}, err + } + return result, nil +} + +// listByServerHandleError handles the ListByServer error response. +func (client *ReplicasClient) listByServerHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_response_types.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_response_types.go new file mode 100644 index 000000000000..cdd238fe7dc0 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_response_types.go @@ -0,0 +1,829 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "net/http" + "time" + + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" +) + +// BackupsGetResponse contains the response from method Backups.Get. +type BackupsGetResponse struct { + BackupsGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// BackupsGetResult contains the result from method Backups.Get. +type BackupsGetResult struct { + ServerBackup +} + +// BackupsListByServerResponse contains the response from method Backups.ListByServer. +type BackupsListByServerResponse struct { + BackupsListByServerResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// BackupsListByServerResult contains the result from method Backups.ListByServer. +type BackupsListByServerResult struct { + ServerBackupListResult +} + +// CheckNameAvailabilityExecuteResponse contains the response from method CheckNameAvailability.Execute. +type CheckNameAvailabilityExecuteResponse struct { + CheckNameAvailabilityExecuteResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// CheckNameAvailabilityExecuteResult contains the result from method CheckNameAvailability.Execute. +type CheckNameAvailabilityExecuteResult struct { + NameAvailability +} + +// CheckVirtualNetworkSubnetUsageExecuteResponse contains the response from method CheckVirtualNetworkSubnetUsage.Execute. +type CheckVirtualNetworkSubnetUsageExecuteResponse struct { + CheckVirtualNetworkSubnetUsageExecuteResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// CheckVirtualNetworkSubnetUsageExecuteResult contains the result from method CheckVirtualNetworkSubnetUsage.Execute. +type CheckVirtualNetworkSubnetUsageExecuteResult struct { + VirtualNetworkSubnetUsageResult +} + +// ConfigurationsBatchUpdatePollerResponse contains the response from method Configurations.BatchUpdate. +type ConfigurationsBatchUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *ConfigurationsBatchUpdatePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ConfigurationsBatchUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ConfigurationsBatchUpdateResponse, error) { + respType := ConfigurationsBatchUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.ConfigurationListResult) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ConfigurationsBatchUpdatePollerResponse from the provided client and resume token. +func (l *ConfigurationsBatchUpdatePollerResponse) Resume(ctx context.Context, client *ConfigurationsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ConfigurationsClient.BatchUpdate", token, client.pl, client.batchUpdateHandleError) + if err != nil { + return err + } + poller := &ConfigurationsBatchUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ConfigurationsBatchUpdateResponse contains the response from method Configurations.BatchUpdate. +type ConfigurationsBatchUpdateResponse struct { + ConfigurationsBatchUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ConfigurationsBatchUpdateResult contains the result from method Configurations.BatchUpdate. +type ConfigurationsBatchUpdateResult struct { + ConfigurationListResult +} + +// ConfigurationsGetResponse contains the response from method Configurations.Get. +type ConfigurationsGetResponse struct { + ConfigurationsGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ConfigurationsGetResult contains the result from method Configurations.Get. +type ConfigurationsGetResult struct { + Configuration +} + +// ConfigurationsListByServerResponse contains the response from method Configurations.ListByServer. +type ConfigurationsListByServerResponse struct { + ConfigurationsListByServerResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ConfigurationsListByServerResult contains the result from method Configurations.ListByServer. +type ConfigurationsListByServerResult struct { + ConfigurationListResult +} + +// ConfigurationsUpdatePollerResponse contains the response from method Configurations.Update. +type ConfigurationsUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *ConfigurationsUpdatePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ConfigurationsUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ConfigurationsUpdateResponse, error) { + respType := ConfigurationsUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.Configuration) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ConfigurationsUpdatePollerResponse from the provided client and resume token. +func (l *ConfigurationsUpdatePollerResponse) Resume(ctx context.Context, client *ConfigurationsClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ConfigurationsClient.Update", token, client.pl, client.updateHandleError) + if err != nil { + return err + } + poller := &ConfigurationsUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ConfigurationsUpdateResponse contains the response from method Configurations.Update. +type ConfigurationsUpdateResponse struct { + ConfigurationsUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ConfigurationsUpdateResult contains the result from method Configurations.Update. +type ConfigurationsUpdateResult struct { + Configuration +} + +// DatabasesCreateOrUpdatePollerResponse contains the response from method Databases.CreateOrUpdate. +type DatabasesCreateOrUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *DatabasesCreateOrUpdatePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l DatabasesCreateOrUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (DatabasesCreateOrUpdateResponse, error) { + respType := DatabasesCreateOrUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.Database) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a DatabasesCreateOrUpdatePollerResponse from the provided client and resume token. +func (l *DatabasesCreateOrUpdatePollerResponse) Resume(ctx context.Context, client *DatabasesClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("DatabasesClient.CreateOrUpdate", token, client.pl, client.createOrUpdateHandleError) + if err != nil { + return err + } + poller := &DatabasesCreateOrUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// DatabasesCreateOrUpdateResponse contains the response from method Databases.CreateOrUpdate. +type DatabasesCreateOrUpdateResponse struct { + DatabasesCreateOrUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// DatabasesCreateOrUpdateResult contains the result from method Databases.CreateOrUpdate. +type DatabasesCreateOrUpdateResult struct { + Database +} + +// DatabasesDeletePollerResponse contains the response from method Databases.Delete. +type DatabasesDeletePollerResponse struct { + // Poller contains an initialized poller. + Poller *DatabasesDeletePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l DatabasesDeletePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (DatabasesDeleteResponse, error) { + respType := DatabasesDeleteResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a DatabasesDeletePollerResponse from the provided client and resume token. +func (l *DatabasesDeletePollerResponse) Resume(ctx context.Context, client *DatabasesClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("DatabasesClient.Delete", token, client.pl, client.deleteHandleError) + if err != nil { + return err + } + poller := &DatabasesDeletePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// DatabasesDeleteResponse contains the response from method Databases.Delete. +type DatabasesDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// DatabasesGetResponse contains the response from method Databases.Get. +type DatabasesGetResponse struct { + DatabasesGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// DatabasesGetResult contains the result from method Databases.Get. +type DatabasesGetResult struct { + Database +} + +// DatabasesListByServerResponse contains the response from method Databases.ListByServer. +type DatabasesListByServerResponse struct { + DatabasesListByServerResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// DatabasesListByServerResult contains the result from method Databases.ListByServer. +type DatabasesListByServerResult struct { + DatabaseListResult +} + +// FirewallRulesCreateOrUpdatePollerResponse contains the response from method FirewallRules.CreateOrUpdate. +type FirewallRulesCreateOrUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *FirewallRulesCreateOrUpdatePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l FirewallRulesCreateOrUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (FirewallRulesCreateOrUpdateResponse, error) { + respType := FirewallRulesCreateOrUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.FirewallRule) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a FirewallRulesCreateOrUpdatePollerResponse from the provided client and resume token. +func (l *FirewallRulesCreateOrUpdatePollerResponse) Resume(ctx context.Context, client *FirewallRulesClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("FirewallRulesClient.CreateOrUpdate", token, client.pl, client.createOrUpdateHandleError) + if err != nil { + return err + } + poller := &FirewallRulesCreateOrUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// FirewallRulesCreateOrUpdateResponse contains the response from method FirewallRules.CreateOrUpdate. +type FirewallRulesCreateOrUpdateResponse struct { + FirewallRulesCreateOrUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// FirewallRulesCreateOrUpdateResult contains the result from method FirewallRules.CreateOrUpdate. +type FirewallRulesCreateOrUpdateResult struct { + FirewallRule +} + +// FirewallRulesDeletePollerResponse contains the response from method FirewallRules.Delete. +type FirewallRulesDeletePollerResponse struct { + // Poller contains an initialized poller. + Poller *FirewallRulesDeletePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l FirewallRulesDeletePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (FirewallRulesDeleteResponse, error) { + respType := FirewallRulesDeleteResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a FirewallRulesDeletePollerResponse from the provided client and resume token. +func (l *FirewallRulesDeletePollerResponse) Resume(ctx context.Context, client *FirewallRulesClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("FirewallRulesClient.Delete", token, client.pl, client.deleteHandleError) + if err != nil { + return err + } + poller := &FirewallRulesDeletePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// FirewallRulesDeleteResponse contains the response from method FirewallRules.Delete. +type FirewallRulesDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// FirewallRulesGetResponse contains the response from method FirewallRules.Get. +type FirewallRulesGetResponse struct { + FirewallRulesGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// FirewallRulesGetResult contains the result from method FirewallRules.Get. +type FirewallRulesGetResult struct { + FirewallRule +} + +// FirewallRulesListByServerResponse contains the response from method FirewallRules.ListByServer. +type FirewallRulesListByServerResponse struct { + FirewallRulesListByServerResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// FirewallRulesListByServerResult contains the result from method FirewallRules.ListByServer. +type FirewallRulesListByServerResult struct { + FirewallRuleListResult +} + +// GetPrivateDNSZoneSuffixExecuteResponse contains the response from method GetPrivateDNSZoneSuffix.Execute. +type GetPrivateDNSZoneSuffixExecuteResponse struct { + GetPrivateDNSZoneSuffixExecuteResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// GetPrivateDNSZoneSuffixExecuteResult contains the result from method GetPrivateDNSZoneSuffix.Execute. +type GetPrivateDNSZoneSuffixExecuteResult struct { + GetPrivateDNSZoneSuffixResponse +} + +// LocationBasedCapabilitiesListResponse contains the response from method LocationBasedCapabilities.List. +type LocationBasedCapabilitiesListResponse struct { + LocationBasedCapabilitiesListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// LocationBasedCapabilitiesListResult contains the result from method LocationBasedCapabilities.List. +type LocationBasedCapabilitiesListResult struct { + CapabilitiesListResult +} + +// OperationsListResponse contains the response from method Operations.List. +type OperationsListResponse struct { + OperationsListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// OperationsListResult contains the result from method Operations.List. +type OperationsListResult struct { + OperationListResult +} + +// ReplicasListByServerResponse contains the response from method Replicas.ListByServer. +type ReplicasListByServerResponse struct { + ReplicasListByServerResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ReplicasListByServerResult contains the result from method Replicas.ListByServer. +type ReplicasListByServerResult struct { + ServerListResult +} + +// ServersCreatePollerResponse contains the response from method Servers.Create. +type ServersCreatePollerResponse struct { + // Poller contains an initialized poller. + Poller *ServersCreatePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ServersCreatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServersCreateResponse, error) { + respType := ServersCreateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.Server) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServersCreatePollerResponse from the provided client and resume token. +func (l *ServersCreatePollerResponse) Resume(ctx context.Context, client *ServersClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServersClient.Create", token, client.pl, client.createHandleError) + if err != nil { + return err + } + poller := &ServersCreatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServersCreateResponse contains the response from method Servers.Create. +type ServersCreateResponse struct { + ServersCreateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersCreateResult contains the result from method Servers.Create. +type ServersCreateResult struct { + Server +} + +// ServersDeletePollerResponse contains the response from method Servers.Delete. +type ServersDeletePollerResponse struct { + // Poller contains an initialized poller. + Poller *ServersDeletePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ServersDeletePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServersDeleteResponse, error) { + respType := ServersDeleteResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServersDeletePollerResponse from the provided client and resume token. +func (l *ServersDeletePollerResponse) Resume(ctx context.Context, client *ServersClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServersClient.Delete", token, client.pl, client.deleteHandleError) + if err != nil { + return err + } + poller := &ServersDeletePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServersDeleteResponse contains the response from method Servers.Delete. +type ServersDeleteResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersFailoverPollerResponse contains the response from method Servers.Failover. +type ServersFailoverPollerResponse struct { + // Poller contains an initialized poller. + Poller *ServersFailoverPoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ServersFailoverPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServersFailoverResponse, error) { + respType := ServersFailoverResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServersFailoverPollerResponse from the provided client and resume token. +func (l *ServersFailoverPollerResponse) Resume(ctx context.Context, client *ServersClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServersClient.Failover", token, client.pl, client.failoverHandleError) + if err != nil { + return err + } + poller := &ServersFailoverPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServersFailoverResponse contains the response from method Servers.Failover. +type ServersFailoverResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersGetResponse contains the response from method Servers.Get. +type ServersGetResponse struct { + ServersGetResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersGetResult contains the result from method Servers.Get. +type ServersGetResult struct { + Server +} + +// ServersListByResourceGroupResponse contains the response from method Servers.ListByResourceGroup. +type ServersListByResourceGroupResponse struct { + ServersListByResourceGroupResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersListByResourceGroupResult contains the result from method Servers.ListByResourceGroup. +type ServersListByResourceGroupResult struct { + ServerListResult +} + +// ServersListResponse contains the response from method Servers.List. +type ServersListResponse struct { + ServersListResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersListResult contains the result from method Servers.List. +type ServersListResult struct { + ServerListResult +} + +// ServersRestartPollerResponse contains the response from method Servers.Restart. +type ServersRestartPollerResponse struct { + // Poller contains an initialized poller. + Poller *ServersRestartPoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ServersRestartPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServersRestartResponse, error) { + respType := ServersRestartResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServersRestartPollerResponse from the provided client and resume token. +func (l *ServersRestartPollerResponse) Resume(ctx context.Context, client *ServersClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServersClient.Restart", token, client.pl, client.restartHandleError) + if err != nil { + return err + } + poller := &ServersRestartPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServersRestartResponse contains the response from method Servers.Restart. +type ServersRestartResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersStartPollerResponse contains the response from method Servers.Start. +type ServersStartPollerResponse struct { + // Poller contains an initialized poller. + Poller *ServersStartPoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ServersStartPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServersStartResponse, error) { + respType := ServersStartResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServersStartPollerResponse from the provided client and resume token. +func (l *ServersStartPollerResponse) Resume(ctx context.Context, client *ServersClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServersClient.Start", token, client.pl, client.startHandleError) + if err != nil { + return err + } + poller := &ServersStartPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServersStartResponse contains the response from method Servers.Start. +type ServersStartResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersStopPollerResponse contains the response from method Servers.Stop. +type ServersStopPollerResponse struct { + // Poller contains an initialized poller. + Poller *ServersStopPoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ServersStopPollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServersStopResponse, error) { + respType := ServersStopResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, nil) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServersStopPollerResponse from the provided client and resume token. +func (l *ServersStopPollerResponse) Resume(ctx context.Context, client *ServersClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServersClient.Stop", token, client.pl, client.stopHandleError) + if err != nil { + return err + } + poller := &ServersStopPoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServersStopResponse contains the response from method Servers.Stop. +type ServersStopResponse struct { + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersUpdatePollerResponse contains the response from method Servers.Update. +type ServersUpdatePollerResponse struct { + // Poller contains an initialized poller. + Poller *ServersUpdatePoller + + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// PollUntilDone will poll the service endpoint until a terminal state is reached or an error is received. +func (l ServersUpdatePollerResponse) PollUntilDone(ctx context.Context, freq time.Duration) (ServersUpdateResponse, error) { + respType := ServersUpdateResponse{} + resp, err := l.Poller.pt.PollUntilDone(ctx, freq, &respType.Server) + if err != nil { + return respType, err + } + respType.RawResponse = resp + return respType, nil +} + +// Resume rehydrates a ServersUpdatePollerResponse from the provided client and resume token. +func (l *ServersUpdatePollerResponse) Resume(ctx context.Context, client *ServersClient, token string) error { + pt, err := armruntime.NewPollerFromResumeToken("ServersClient.Update", token, client.pl, client.updateHandleError) + if err != nil { + return err + } + poller := &ServersUpdatePoller{ + pt: pt, + } + resp, err := poller.Poll(ctx) + if err != nil { + return err + } + l.Poller = poller + l.RawResponse = resp + return nil +} + +// ServersUpdateResponse contains the response from method Servers.Update. +type ServersUpdateResponse struct { + ServersUpdateResult + // RawResponse contains the underlying HTTP response. + RawResponse *http.Response +} + +// ServersUpdateResult contains the result from method Servers.Update. +type ServersUpdateResult struct { + Server +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_servers_client.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_servers_client.go new file mode 100644 index 000000000000..9f05d0442327 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_servers_client.go @@ -0,0 +1,745 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strings" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + armruntime "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/runtime" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" +) + +// ServersClient contains the methods for the Servers group. +// Don't use this type directly, use NewServersClient() instead. +type ServersClient struct { + ep string + pl runtime.Pipeline + subscriptionID string +} + +// NewServersClient creates a new instance of ServersClient with the specified values. +func NewServersClient(con *arm.Connection, subscriptionID string) *ServersClient { + return &ServersClient{ep: con.Endpoint(), pl: con.NewPipeline(module, version), subscriptionID: subscriptionID} +} + +// BeginCreate - Creates a new server or updates an existing server. The update action will overwrite the existing server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) BeginCreate(ctx context.Context, resourceGroupName string, serverName string, parameters Server, options *ServersBeginCreateOptions) (ServersCreatePollerResponse, error) { + resp, err := client.create(ctx, resourceGroupName, serverName, parameters, options) + if err != nil { + return ServersCreatePollerResponse{}, err + } + result := ServersCreatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServersClient.Create", "", resp, client.pl, client.createHandleError) + if err != nil { + return ServersCreatePollerResponse{}, err + } + result.Poller = &ServersCreatePoller{ + pt: pt, + } + return result, nil +} + +// Create - Creates a new server or updates an existing server. The update action will overwrite the existing server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) create(ctx context.Context, resourceGroupName string, serverName string, parameters Server, options *ServersBeginCreateOptions) (*http.Response, error) { + req, err := client.createCreateRequest(ctx, resourceGroupName, serverName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusCreated, http.StatusAccepted) { + return nil, client.createHandleError(resp) + } + return resp, nil +} + +// createCreateRequest creates the Create request. +func (client *ServersClient) createCreateRequest(ctx context.Context, resourceGroupName string, serverName string, parameters Server, options *ServersBeginCreateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// createHandleError handles the Create error response. +func (client *ServersClient) createHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginDelete - Deletes a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) BeginDelete(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginDeleteOptions) (ServersDeletePollerResponse, error) { + resp, err := client.deleteOperation(ctx, resourceGroupName, serverName, options) + if err != nil { + return ServersDeletePollerResponse{}, err + } + result := ServersDeletePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServersClient.Delete", "", resp, client.pl, client.deleteHandleError) + if err != nil { + return ServersDeletePollerResponse{}, err + } + result.Poller = &ServersDeletePoller{ + pt: pt, + } + return result, nil +} + +// Delete - Deletes a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) deleteOperation(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginDeleteOptions) (*http.Response, error) { + req, err := client.deleteCreateRequest(ctx, resourceGroupName, serverName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { + return nil, client.deleteHandleError(resp) + } + return resp, nil +} + +// deleteCreateRequest creates the Delete request. +func (client *ServersClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginDeleteOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// deleteHandleError handles the Delete error response. +func (client *ServersClient) deleteHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginFailover - Manual failover a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) BeginFailover(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginFailoverOptions) (ServersFailoverPollerResponse, error) { + resp, err := client.failover(ctx, resourceGroupName, serverName, options) + if err != nil { + return ServersFailoverPollerResponse{}, err + } + result := ServersFailoverPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServersClient.Failover", "", resp, client.pl, client.failoverHandleError) + if err != nil { + return ServersFailoverPollerResponse{}, err + } + result.Poller = &ServersFailoverPoller{ + pt: pt, + } + return result, nil +} + +// Failover - Manual failover a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) failover(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginFailoverOptions) (*http.Response, error) { + req, err := client.failoverCreateRequest(ctx, resourceGroupName, serverName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.failoverHandleError(resp) + } + return resp, nil +} + +// failoverCreateRequest creates the Failover request. +func (client *ServersClient) failoverCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginFailoverOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/failover" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// failoverHandleError handles the Failover error response. +func (client *ServersClient) failoverHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// Get - Gets information about a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) Get(ctx context.Context, resourceGroupName string, serverName string, options *ServersGetOptions) (ServersGetResponse, error) { + req, err := client.getCreateRequest(ctx, resourceGroupName, serverName, options) + if err != nil { + return ServersGetResponse{}, err + } + resp, err := client.pl.Do(req) + if err != nil { + return ServersGetResponse{}, err + } + if !runtime.HasStatusCode(resp, http.StatusOK) { + return ServersGetResponse{}, client.getHandleError(resp) + } + return client.getHandleResponse(resp) +} + +// getCreateRequest creates the Get request. +func (client *ServersClient) getCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *ServersGetOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// getHandleResponse handles the Get response. +func (client *ServersClient) getHandleResponse(resp *http.Response) (ServersGetResponse, error) { + result := ServersGetResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.Server); err != nil { + return ServersGetResponse{}, err + } + return result, nil +} + +// getHandleError handles the Get error response. +func (client *ServersClient) getHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// List - List all the servers in a given subscription. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) List(options *ServersListOptions) *ServersListPager { + return &ServersListPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listCreateRequest(ctx, options) + }, + advancer: func(ctx context.Context, resp ServersListResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ServerListResult.NextLink) + }, + } +} + +// listCreateRequest creates the List request. +func (client *ServersClient) listCreateRequest(ctx context.Context, options *ServersListOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.DBforMySQL/flexibleServers" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listHandleResponse handles the List response. +func (client *ServersClient) listHandleResponse(resp *http.Response) (ServersListResponse, error) { + result := ServersListResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerListResult); err != nil { + return ServersListResponse{}, err + } + return result, nil +} + +// listHandleError handles the List error response. +func (client *ServersClient) listHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// ListByResourceGroup - List all the servers in a given resource group. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) ListByResourceGroup(resourceGroupName string, options *ServersListByResourceGroupOptions) *ServersListByResourceGroupPager { + return &ServersListByResourceGroupPager{ + client: client, + requester: func(ctx context.Context) (*policy.Request, error) { + return client.listByResourceGroupCreateRequest(ctx, resourceGroupName, options) + }, + advancer: func(ctx context.Context, resp ServersListByResourceGroupResponse) (*policy.Request, error) { + return runtime.NewRequest(ctx, http.MethodGet, *resp.ServerListResult.NextLink) + }, + } +} + +// listByResourceGroupCreateRequest creates the ListByResourceGroup request. +func (client *ServersClient) listByResourceGroupCreateRequest(ctx context.Context, resourceGroupName string, options *ServersListByResourceGroupOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// listByResourceGroupHandleResponse handles the ListByResourceGroup response. +func (client *ServersClient) listByResourceGroupHandleResponse(resp *http.Response) (ServersListByResourceGroupResponse, error) { + result := ServersListByResourceGroupResponse{RawResponse: resp} + if err := runtime.UnmarshalAsJSON(resp, &result.ServerListResult); err != nil { + return ServersListByResourceGroupResponse{}, err + } + return result, nil +} + +// listByResourceGroupHandleError handles the ListByResourceGroup error response. +func (client *ServersClient) listByResourceGroupHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginRestart - Restarts a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) BeginRestart(ctx context.Context, resourceGroupName string, serverName string, parameters ServerRestartParameter, options *ServersBeginRestartOptions) (ServersRestartPollerResponse, error) { + resp, err := client.restart(ctx, resourceGroupName, serverName, parameters, options) + if err != nil { + return ServersRestartPollerResponse{}, err + } + result := ServersRestartPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServersClient.Restart", "", resp, client.pl, client.restartHandleError) + if err != nil { + return ServersRestartPollerResponse{}, err + } + result.Poller = &ServersRestartPoller{ + pt: pt, + } + return result, nil +} + +// Restart - Restarts a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) restart(ctx context.Context, resourceGroupName string, serverName string, parameters ServerRestartParameter, options *ServersBeginRestartOptions) (*http.Response, error) { + req, err := client.restartCreateRequest(ctx, resourceGroupName, serverName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.restartHandleError(resp) + } + return resp, nil +} + +// restartCreateRequest creates the Restart request. +func (client *ServersClient) restartCreateRequest(ctx context.Context, resourceGroupName string, serverName string, parameters ServerRestartParameter, options *ServersBeginRestartOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/restart" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// restartHandleError handles the Restart error response. +func (client *ServersClient) restartHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginStart - Starts a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) BeginStart(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginStartOptions) (ServersStartPollerResponse, error) { + resp, err := client.start(ctx, resourceGroupName, serverName, options) + if err != nil { + return ServersStartPollerResponse{}, err + } + result := ServersStartPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServersClient.Start", "", resp, client.pl, client.startHandleError) + if err != nil { + return ServersStartPollerResponse{}, err + } + result.Poller = &ServersStartPoller{ + pt: pt, + } + return result, nil +} + +// Start - Starts a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) start(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginStartOptions) (*http.Response, error) { + req, err := client.startCreateRequest(ctx, resourceGroupName, serverName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.startHandleError(resp) + } + return resp, nil +} + +// startCreateRequest creates the Start request. +func (client *ServersClient) startCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginStartOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/start" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// startHandleError handles the Start error response. +func (client *ServersClient) startHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginStop - Stops a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) BeginStop(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginStopOptions) (ServersStopPollerResponse, error) { + resp, err := client.stop(ctx, resourceGroupName, serverName, options) + if err != nil { + return ServersStopPollerResponse{}, err + } + result := ServersStopPollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServersClient.Stop", "", resp, client.pl, client.stopHandleError) + if err != nil { + return ServersStopPollerResponse{}, err + } + result.Poller = &ServersStopPoller{ + pt: pt, + } + return result, nil +} + +// Stop - Stops a server. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) stop(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginStopOptions) (*http.Response, error) { + req, err := client.stopCreateRequest(ctx, resourceGroupName, serverName, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.stopHandleError(resp) + } + return resp, nil +} + +// stopCreateRequest creates the Stop request. +func (client *ServersClient) stopCreateRequest(ctx context.Context, resourceGroupName string, serverName string, options *ServersBeginStopOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}/stop" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, nil +} + +// stopHandleError handles the Stop error response. +func (client *ServersClient) stopHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} + +// BeginUpdate - Updates an existing server. The request body can contain one to many of the properties present in the normal server definition. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) BeginUpdate(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForUpdate, options *ServersBeginUpdateOptions) (ServersUpdatePollerResponse, error) { + resp, err := client.update(ctx, resourceGroupName, serverName, parameters, options) + if err != nil { + return ServersUpdatePollerResponse{}, err + } + result := ServersUpdatePollerResponse{ + RawResponse: resp, + } + pt, err := armruntime.NewPoller("ServersClient.Update", "", resp, client.pl, client.updateHandleError) + if err != nil { + return ServersUpdatePollerResponse{}, err + } + result.Poller = &ServersUpdatePoller{ + pt: pt, + } + return result, nil +} + +// Update - Updates an existing server. The request body can contain one to many of the properties present in the normal server definition. +// If the operation fails it returns the *CloudError error type. +func (client *ServersClient) update(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForUpdate, options *ServersBeginUpdateOptions) (*http.Response, error) { + req, err := client.updateCreateRequest(ctx, resourceGroupName, serverName, parameters, options) + if err != nil { + return nil, err + } + resp, err := client.pl.Do(req) + if err != nil { + return nil, err + } + if !runtime.HasStatusCode(resp, http.StatusOK, http.StatusAccepted) { + return nil, client.updateHandleError(resp) + } + return resp, nil +} + +// updateCreateRequest creates the Update request. +func (client *ServersClient) updateCreateRequest(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForUpdate, options *ServersBeginUpdateOptions) (*policy.Request, error) { + urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/flexibleServers/{serverName}" + if client.subscriptionID == "" { + return nil, errors.New("parameter client.subscriptionID cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) + if resourceGroupName == "" { + return nil, errors.New("parameter resourceGroupName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) + if serverName == "" { + return nil, errors.New("parameter serverName cannot be empty") + } + urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) + req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.ep, urlPath)) + if err != nil { + return nil, err + } + reqQP := req.Raw().URL.Query() + reqQP.Set("api-version", "2021-05-01") + req.Raw().URL.RawQuery = reqQP.Encode() + req.Raw().Header.Set("Accept", "application/json") + return req, runtime.MarshalAsJSON(req, parameters) +} + +// updateHandleError handles the Update error response. +func (client *ServersClient) updateHandleError(resp *http.Response) error { + body, err := runtime.Payload(resp) + if err != nil { + return runtime.NewResponseError(err, resp) + } + errType := CloudError{raw: string(body)} + if err := runtime.UnmarshalAsJSON(resp, &errType); err != nil { + return runtime.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp) + } + return runtime.NewResponseError(&errType, resp) +} diff --git a/sdk/mysql/armmysqlflexibleserver/zz_generated_time_rfc3339.go b/sdk/mysql/armmysqlflexibleserver/zz_generated_time_rfc3339.go new file mode 100644 index 000000000000..5f8139f05829 --- /dev/null +++ b/sdk/mysql/armmysqlflexibleserver/zz_generated_time_rfc3339.go @@ -0,0 +1,58 @@ +//go:build go1.16 +// +build go1.16 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +package armmysqlflexibleserver + +import ( + "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 +}