1package sql 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// ServerConnectionPoliciesClient is the the Azure SQL Database management API provides a RESTful set of web services 29// that interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, 30// update, and delete databases. 31type ServerConnectionPoliciesClient struct { 32 BaseClient 33} 34 35// NewServerConnectionPoliciesClient creates an instance of the ServerConnectionPoliciesClient client. 36func NewServerConnectionPoliciesClient(subscriptionID string) ServerConnectionPoliciesClient { 37 return NewServerConnectionPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewServerConnectionPoliciesClientWithBaseURI creates an instance of the ServerConnectionPoliciesClient client using 41// a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 42// clouds, Azure stack). 43func NewServerConnectionPoliciesClientWithBaseURI(baseURI string, subscriptionID string) ServerConnectionPoliciesClient { 44 return ServerConnectionPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// CreateOrUpdate creates or updates the server's connection policy. 48// Parameters: 49// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 50// from the Azure Resource Manager API or the portal. 51// serverName - the name of the server. 52// parameters - the required parameters for updating a secure connection policy. 53func (client ServerConnectionPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, parameters ServerConnectionPolicy) (result ServerConnectionPolicy, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/ServerConnectionPoliciesClient.CreateOrUpdate") 56 defer func() { 57 sc := -1 58 if result.Response.Response != nil { 59 sc = result.Response.Response.StatusCode 60 } 61 tracing.EndSpan(ctx, sc, err) 62 }() 63 } 64 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, parameters) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "sql.ServerConnectionPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") 67 return 68 } 69 70 resp, err := client.CreateOrUpdateSender(req) 71 if err != nil { 72 result.Response = autorest.Response{Response: resp} 73 err = autorest.NewErrorWithError(err, "sql.ServerConnectionPoliciesClient", "CreateOrUpdate", resp, "Failure sending request") 74 return 75 } 76 77 result, err = client.CreateOrUpdateResponder(resp) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "sql.ServerConnectionPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request") 80 return 81 } 82 83 return 84} 85 86// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 87func (client ServerConnectionPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerConnectionPolicy) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "connectionPolicyName": autorest.Encode("path", "default"), 90 "resourceGroupName": autorest.Encode("path", resourceGroupName), 91 "serverName": autorest.Encode("path", serverName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 } 94 95 const APIVersion = "2014-04-01" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 parameters.Kind = nil 101 parameters.Location = nil 102 preparer := autorest.CreatePreparer( 103 autorest.AsContentType("application/json; charset=utf-8"), 104 autorest.AsPut(), 105 autorest.WithBaseURL(client.BaseURI), 106 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}", pathParameters), 107 autorest.WithJSON(parameters), 108 autorest.WithQueryParameters(queryParameters)) 109 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 110} 111 112// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 113// http.Response Body if it receives an error. 114func (client ServerConnectionPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 115 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 116} 117 118// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 119// closes the http.Response Body. 120func (client ServerConnectionPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ServerConnectionPolicy, err error) { 121 err = autorest.Respond( 122 resp, 123 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// Get gets the server's secure connection policy. 131// Parameters: 132// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 133// from the Azure Resource Manager API or the portal. 134// serverName - the name of the server. 135func (client ServerConnectionPoliciesClient) Get(ctx context.Context, resourceGroupName string, serverName string) (result ServerConnectionPolicy, err error) { 136 if tracing.IsEnabled() { 137 ctx = tracing.StartSpan(ctx, fqdn+"/ServerConnectionPoliciesClient.Get") 138 defer func() { 139 sc := -1 140 if result.Response.Response != nil { 141 sc = result.Response.Response.StatusCode 142 } 143 tracing.EndSpan(ctx, sc, err) 144 }() 145 } 146 req, err := client.GetPreparer(ctx, resourceGroupName, serverName) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "sql.ServerConnectionPoliciesClient", "Get", nil, "Failure preparing request") 149 return 150 } 151 152 resp, err := client.GetSender(req) 153 if err != nil { 154 result.Response = autorest.Response{Response: resp} 155 err = autorest.NewErrorWithError(err, "sql.ServerConnectionPoliciesClient", "Get", resp, "Failure sending request") 156 return 157 } 158 159 result, err = client.GetResponder(resp) 160 if err != nil { 161 err = autorest.NewErrorWithError(err, "sql.ServerConnectionPoliciesClient", "Get", resp, "Failure responding to request") 162 return 163 } 164 165 return 166} 167 168// GetPreparer prepares the Get request. 169func (client ServerConnectionPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 170 pathParameters := map[string]interface{}{ 171 "connectionPolicyName": autorest.Encode("path", "default"), 172 "resourceGroupName": autorest.Encode("path", resourceGroupName), 173 "serverName": autorest.Encode("path", serverName), 174 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 175 } 176 177 const APIVersion = "2014-04-01" 178 queryParameters := map[string]interface{}{ 179 "api-version": APIVersion, 180 } 181 182 preparer := autorest.CreatePreparer( 183 autorest.AsGet(), 184 autorest.WithBaseURL(client.BaseURI), 185 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/connectionPolicies/{connectionPolicyName}", pathParameters), 186 autorest.WithQueryParameters(queryParameters)) 187 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 188} 189 190// GetSender sends the Get request. The method will close the 191// http.Response Body if it receives an error. 192func (client ServerConnectionPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { 193 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 194} 195 196// GetResponder handles the response to the Get request. The method always 197// closes the http.Response Body. 198func (client ServerConnectionPoliciesClient) GetResponder(resp *http.Response) (result ServerConnectionPolicy, err error) { 199 err = autorest.Respond( 200 resp, 201 azure.WithErrorUnlessStatusCode(http.StatusOK), 202 autorest.ByUnmarshallingJSON(&result), 203 autorest.ByClosing()) 204 result.Response = autorest.Response{Response: resp} 205 return 206} 207