1// +build go1.13 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// Code generated by Microsoft (R) AutoRest Code Generator. 6// Changes may cause incorrect behavior and will be lost if the code is regenerated. 7 8package armpostgresql 9 10import ( 11 "context" 12 "errors" 13 "fmt" 14 "github.com/Azure/azure-sdk-for-go/sdk/armcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 16 "net/http" 17 "net/url" 18 "strings" 19 "time" 20) 21 22// ServerParametersClient contains the methods for the ServerParameters group. 23// Don't use this type directly, use NewServerParametersClient() instead. 24type ServerParametersClient struct { 25 con *armcore.Connection 26 subscriptionID string 27} 28 29// NewServerParametersClient creates a new instance of ServerParametersClient with the specified values. 30func NewServerParametersClient(con *armcore.Connection, subscriptionID string) *ServerParametersClient { 31 return &ServerParametersClient{con: con, subscriptionID: subscriptionID} 32} 33 34// BeginListUpdateConfigurations - Update a list of configurations in a given server. 35// If the operation fails it returns the *CloudError error type. 36func (client *ServerParametersClient) BeginListUpdateConfigurations(ctx context.Context, resourceGroupName string, serverName string, value ConfigurationListResult, options *ServerParametersBeginListUpdateConfigurationsOptions) (ServerParametersListUpdateConfigurationsPollerResponse, error) { 37 resp, err := client.listUpdateConfigurations(ctx, resourceGroupName, serverName, value, options) 38 if err != nil { 39 return ServerParametersListUpdateConfigurationsPollerResponse{}, err 40 } 41 result := ServerParametersListUpdateConfigurationsPollerResponse{ 42 RawResponse: resp.Response, 43 } 44 pt, err := armcore.NewLROPoller("ServerParametersClient.ListUpdateConfigurations", "azure-async-operation", resp, client.con.Pipeline(), client.listUpdateConfigurationsHandleError) 45 if err != nil { 46 return ServerParametersListUpdateConfigurationsPollerResponse{}, err 47 } 48 poller := &serverParametersListUpdateConfigurationsPoller{ 49 pt: pt, 50 } 51 result.Poller = poller 52 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (ServerParametersListUpdateConfigurationsResponse, error) { 53 return poller.pollUntilDone(ctx, frequency) 54 } 55 return result, nil 56} 57 58// ResumeListUpdateConfigurations creates a new ServerParametersListUpdateConfigurationsPoller from the specified resume token. 59// token - The value must come from a previous call to ServerParametersListUpdateConfigurationsPoller.ResumeToken(). 60func (client *ServerParametersClient) ResumeListUpdateConfigurations(ctx context.Context, token string) (ServerParametersListUpdateConfigurationsPollerResponse, error) { 61 pt, err := armcore.NewLROPollerFromResumeToken("ServerParametersClient.ListUpdateConfigurations", token, client.con.Pipeline(), client.listUpdateConfigurationsHandleError) 62 if err != nil { 63 return ServerParametersListUpdateConfigurationsPollerResponse{}, err 64 } 65 poller := &serverParametersListUpdateConfigurationsPoller{ 66 pt: pt, 67 } 68 resp, err := poller.Poll(ctx) 69 if err != nil { 70 return ServerParametersListUpdateConfigurationsPollerResponse{}, err 71 } 72 result := ServerParametersListUpdateConfigurationsPollerResponse{ 73 RawResponse: resp, 74 } 75 result.Poller = poller 76 result.PollUntilDone = func(ctx context.Context, frequency time.Duration) (ServerParametersListUpdateConfigurationsResponse, error) { 77 return poller.pollUntilDone(ctx, frequency) 78 } 79 return result, nil 80} 81 82// ListUpdateConfigurations - Update a list of configurations in a given server. 83// If the operation fails it returns the *CloudError error type. 84func (client *ServerParametersClient) listUpdateConfigurations(ctx context.Context, resourceGroupName string, serverName string, value ConfigurationListResult, options *ServerParametersBeginListUpdateConfigurationsOptions) (*azcore.Response, error) { 85 req, err := client.listUpdateConfigurationsCreateRequest(ctx, resourceGroupName, serverName, value, options) 86 if err != nil { 87 return nil, err 88 } 89 resp, err := client.con.Pipeline().Do(req) 90 if err != nil { 91 return nil, err 92 } 93 if !resp.HasStatusCode(http.StatusOK, http.StatusAccepted) { 94 return nil, client.listUpdateConfigurationsHandleError(resp) 95 } 96 return resp, nil 97} 98 99// listUpdateConfigurationsCreateRequest creates the ListUpdateConfigurations request. 100func (client *ServerParametersClient) listUpdateConfigurationsCreateRequest(ctx context.Context, resourceGroupName string, serverName string, value ConfigurationListResult, options *ServerParametersBeginListUpdateConfigurationsOptions) (*azcore.Request, error) { 101 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/servers/{serverName}/updateConfigurations" 102 if client.subscriptionID == "" { 103 return nil, errors.New("parameter client.subscriptionID cannot be empty") 104 } 105 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 106 if resourceGroupName == "" { 107 return nil, errors.New("parameter resourceGroupName cannot be empty") 108 } 109 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 110 if serverName == "" { 111 return nil, errors.New("parameter serverName cannot be empty") 112 } 113 urlPath = strings.ReplaceAll(urlPath, "{serverName}", url.PathEscape(serverName)) 114 req, err := azcore.NewRequest(ctx, http.MethodPost, azcore.JoinPaths(client.con.Endpoint(), urlPath)) 115 if err != nil { 116 return nil, err 117 } 118 req.Telemetry(telemetryInfo) 119 reqQP := req.URL.Query() 120 reqQP.Set("api-version", "2017-12-01") 121 req.URL.RawQuery = reqQP.Encode() 122 req.Header.Set("Accept", "application/json") 123 return req, req.MarshalAsJSON(value) 124} 125 126// listUpdateConfigurationsHandleError handles the ListUpdateConfigurations error response. 127func (client *ServerParametersClient) listUpdateConfigurationsHandleError(resp *azcore.Response) error { 128 body, err := resp.Payload() 129 if err != nil { 130 return azcore.NewResponseError(err, resp.Response) 131 } 132 errType := CloudError{raw: string(body)} 133 if err := resp.UnmarshalAsJSON(&errType); err != nil { 134 return azcore.NewResponseError(fmt.Errorf("%s\n%s", string(body), err), resp.Response) 135 } 136 return azcore.NewResponseError(&errType, resp.Response) 137} 138