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// EncryptionProtectorsClient is the the Azure SQL Database management API provides a RESTful set of web services that 29// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, 30// and delete databases. 31type EncryptionProtectorsClient struct { 32 BaseClient 33} 34 35// NewEncryptionProtectorsClient creates an instance of the EncryptionProtectorsClient client. 36func NewEncryptionProtectorsClient(subscriptionID string) EncryptionProtectorsClient { 37 return NewEncryptionProtectorsClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewEncryptionProtectorsClientWithBaseURI creates an instance of the EncryptionProtectorsClient client using a custom 41// endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure 42// stack). 43func NewEncryptionProtectorsClientWithBaseURI(baseURI string, subscriptionID string) EncryptionProtectorsClient { 44 return EncryptionProtectorsClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// CreateOrUpdate updates an existing encryption protector. 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 requested encryption protector resource state. 53func (client EncryptionProtectorsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, parameters EncryptionProtector) (result EncryptionProtectorsCreateOrUpdateFuture, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionProtectorsClient.CreateOrUpdate") 56 defer func() { 57 sc := -1 58 if result.Response() != nil { 59 sc = result.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.EncryptionProtectorsClient", "CreateOrUpdate", nil, "Failure preparing request") 67 return 68 } 69 70 result, err = client.CreateOrUpdateSender(req) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 73 return 74 } 75 76 return 77} 78 79// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 80func (client EncryptionProtectorsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters EncryptionProtector) (*http.Request, error) { 81 pathParameters := map[string]interface{}{ 82 "encryptionProtectorName": autorest.Encode("path", "current"), 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "serverName": autorest.Encode("path", serverName), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2015-05-01-preview" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 93 parameters.Kind = nil 94 parameters.Location = nil 95 preparer := autorest.CreatePreparer( 96 autorest.AsContentType("application/json; charset=utf-8"), 97 autorest.AsPut(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}", pathParameters), 100 autorest.WithJSON(parameters), 101 autorest.WithQueryParameters(queryParameters)) 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 106// http.Response Body if it receives an error. 107func (client EncryptionProtectorsClient) CreateOrUpdateSender(req *http.Request) (future EncryptionProtectorsCreateOrUpdateFuture, err error) { 108 var resp *http.Response 109 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110 if err != nil { 111 return 112 } 113 future.Future, err = azure.NewFutureFromResponse(resp) 114 return 115} 116 117// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 118// closes the http.Response Body. 119func (client EncryptionProtectorsClient) CreateOrUpdateResponder(resp *http.Response) (result EncryptionProtector, err error) { 120 err = autorest.Respond( 121 resp, 122 client.ByInspecting(), 123 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// Get gets a server encryption protector. 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 EncryptionProtectorsClient) Get(ctx context.Context, resourceGroupName string, serverName string) (result EncryptionProtector, err error) { 136 if tracing.IsEnabled() { 137 ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionProtectorsClient.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.EncryptionProtectorsClient", "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.EncryptionProtectorsClient", "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.EncryptionProtectorsClient", "Get", resp, "Failure responding to request") 162 } 163 164 return 165} 166 167// GetPreparer prepares the Get request. 168func (client EncryptionProtectorsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 169 pathParameters := map[string]interface{}{ 170 "encryptionProtectorName": autorest.Encode("path", "current"), 171 "resourceGroupName": autorest.Encode("path", resourceGroupName), 172 "serverName": autorest.Encode("path", serverName), 173 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 174 } 175 176 const APIVersion = "2015-05-01-preview" 177 queryParameters := map[string]interface{}{ 178 "api-version": APIVersion, 179 } 180 181 preparer := autorest.CreatePreparer( 182 autorest.AsGet(), 183 autorest.WithBaseURL(client.BaseURI), 184 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}", pathParameters), 185 autorest.WithQueryParameters(queryParameters)) 186 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 187} 188 189// GetSender sends the Get request. The method will close the 190// http.Response Body if it receives an error. 191func (client EncryptionProtectorsClient) GetSender(req *http.Request) (*http.Response, error) { 192 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 193} 194 195// GetResponder handles the response to the Get request. The method always 196// closes the http.Response Body. 197func (client EncryptionProtectorsClient) GetResponder(resp *http.Response) (result EncryptionProtector, err error) { 198 err = autorest.Respond( 199 resp, 200 client.ByInspecting(), 201 azure.WithErrorUnlessStatusCode(http.StatusOK), 202 autorest.ByUnmarshallingJSON(&result), 203 autorest.ByClosing()) 204 result.Response = autorest.Response{Response: resp} 205 return 206} 207 208// ListByServer gets a list of server encryption protectors 209// Parameters: 210// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 211// from the Azure Resource Manager API or the portal. 212// serverName - the name of the server. 213func (client EncryptionProtectorsClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result EncryptionProtectorListResultPage, err error) { 214 if tracing.IsEnabled() { 215 ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionProtectorsClient.ListByServer") 216 defer func() { 217 sc := -1 218 if result.eplr.Response.Response != nil { 219 sc = result.eplr.Response.Response.StatusCode 220 } 221 tracing.EndSpan(ctx, sc, err) 222 }() 223 } 224 result.fn = client.listByServerNextResults 225 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 226 if err != nil { 227 err = autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "ListByServer", nil, "Failure preparing request") 228 return 229 } 230 231 resp, err := client.ListByServerSender(req) 232 if err != nil { 233 result.eplr.Response = autorest.Response{Response: resp} 234 err = autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "ListByServer", resp, "Failure sending request") 235 return 236 } 237 238 result.eplr, err = client.ListByServerResponder(resp) 239 if err != nil { 240 err = autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "ListByServer", resp, "Failure responding to request") 241 } 242 243 return 244} 245 246// ListByServerPreparer prepares the ListByServer request. 247func (client EncryptionProtectorsClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 248 pathParameters := map[string]interface{}{ 249 "resourceGroupName": autorest.Encode("path", resourceGroupName), 250 "serverName": autorest.Encode("path", serverName), 251 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 252 } 253 254 const APIVersion = "2015-05-01-preview" 255 queryParameters := map[string]interface{}{ 256 "api-version": APIVersion, 257 } 258 259 preparer := autorest.CreatePreparer( 260 autorest.AsGet(), 261 autorest.WithBaseURL(client.BaseURI), 262 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector", pathParameters), 263 autorest.WithQueryParameters(queryParameters)) 264 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 265} 266 267// ListByServerSender sends the ListByServer request. The method will close the 268// http.Response Body if it receives an error. 269func (client EncryptionProtectorsClient) ListByServerSender(req *http.Request) (*http.Response, error) { 270 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 271} 272 273// ListByServerResponder handles the response to the ListByServer request. The method always 274// closes the http.Response Body. 275func (client EncryptionProtectorsClient) ListByServerResponder(resp *http.Response) (result EncryptionProtectorListResult, err error) { 276 err = autorest.Respond( 277 resp, 278 client.ByInspecting(), 279 azure.WithErrorUnlessStatusCode(http.StatusOK), 280 autorest.ByUnmarshallingJSON(&result), 281 autorest.ByClosing()) 282 result.Response = autorest.Response{Response: resp} 283 return 284} 285 286// listByServerNextResults retrieves the next set of results, if any. 287func (client EncryptionProtectorsClient) listByServerNextResults(ctx context.Context, lastResults EncryptionProtectorListResult) (result EncryptionProtectorListResult, err error) { 288 req, err := lastResults.encryptionProtectorListResultPreparer(ctx) 289 if err != nil { 290 return result, autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "listByServerNextResults", nil, "Failure preparing next results request") 291 } 292 if req == nil { 293 return 294 } 295 resp, err := client.ListByServerSender(req) 296 if err != nil { 297 result.Response = autorest.Response{Response: resp} 298 return result, autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "listByServerNextResults", resp, "Failure sending next results request") 299 } 300 result, err = client.ListByServerResponder(resp) 301 if err != nil { 302 err = autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "listByServerNextResults", resp, "Failure responding to next results request") 303 } 304 return 305} 306 307// ListByServerComplete enumerates all values, automatically crossing page boundaries as required. 308func (client EncryptionProtectorsClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string) (result EncryptionProtectorListResultIterator, err error) { 309 if tracing.IsEnabled() { 310 ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionProtectorsClient.ListByServer") 311 defer func() { 312 sc := -1 313 if result.Response().Response.Response != nil { 314 sc = result.page.Response().Response.Response.StatusCode 315 } 316 tracing.EndSpan(ctx, sc, err) 317 }() 318 } 319 result.page, err = client.ListByServer(ctx, resourceGroupName, serverName) 320 return 321} 322 323// Revalidate revalidates an existing encryption protector. 324// Parameters: 325// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 326// from the Azure Resource Manager API or the portal. 327// serverName - the name of the server. 328func (client EncryptionProtectorsClient) Revalidate(ctx context.Context, resourceGroupName string, serverName string) (result EncryptionProtectorsRevalidateFuture, err error) { 329 if tracing.IsEnabled() { 330 ctx = tracing.StartSpan(ctx, fqdn+"/EncryptionProtectorsClient.Revalidate") 331 defer func() { 332 sc := -1 333 if result.Response() != nil { 334 sc = result.Response().StatusCode 335 } 336 tracing.EndSpan(ctx, sc, err) 337 }() 338 } 339 req, err := client.RevalidatePreparer(ctx, resourceGroupName, serverName) 340 if err != nil { 341 err = autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "Revalidate", nil, "Failure preparing request") 342 return 343 } 344 345 result, err = client.RevalidateSender(req) 346 if err != nil { 347 err = autorest.NewErrorWithError(err, "sql.EncryptionProtectorsClient", "Revalidate", result.Response(), "Failure sending request") 348 return 349 } 350 351 return 352} 353 354// RevalidatePreparer prepares the Revalidate request. 355func (client EncryptionProtectorsClient) RevalidatePreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 356 pathParameters := map[string]interface{}{ 357 "encryptionProtectorName": autorest.Encode("path", "current"), 358 "resourceGroupName": autorest.Encode("path", resourceGroupName), 359 "serverName": autorest.Encode("path", serverName), 360 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 361 } 362 363 const APIVersion = "2015-05-01-preview" 364 queryParameters := map[string]interface{}{ 365 "api-version": APIVersion, 366 } 367 368 preparer := autorest.CreatePreparer( 369 autorest.AsPost(), 370 autorest.WithBaseURL(client.BaseURI), 371 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/encryptionProtector/{encryptionProtectorName}/revalidate", pathParameters), 372 autorest.WithQueryParameters(queryParameters)) 373 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 374} 375 376// RevalidateSender sends the Revalidate request. The method will close the 377// http.Response Body if it receives an error. 378func (client EncryptionProtectorsClient) RevalidateSender(req *http.Request) (future EncryptionProtectorsRevalidateFuture, err error) { 379 var resp *http.Response 380 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 381 if err != nil { 382 return 383 } 384 future.Future, err = azure.NewFutureFromResponse(resp) 385 return 386} 387 388// RevalidateResponder handles the response to the Revalidate request. The method always 389// closes the http.Response Body. 390func (client EncryptionProtectorsClient) RevalidateResponder(resp *http.Response) (result autorest.Response, err error) { 391 err = autorest.Respond( 392 resp, 393 client.ByInspecting(), 394 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 395 autorest.ByClosing()) 396 result.Response = resp 397 return 398} 399