1package sql 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// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// TdeCertificatesClient is the the Azure SQL Database management API provides a RESTful set of web services that 19// interact with Azure SQL Database services to manage your databases. The API enables you to create, retrieve, update, 20// and delete databases. 21type TdeCertificatesClient struct { 22 BaseClient 23} 24 25// NewTdeCertificatesClient creates an instance of the TdeCertificatesClient client. 26func NewTdeCertificatesClient(subscriptionID string) TdeCertificatesClient { 27 return NewTdeCertificatesClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewTdeCertificatesClientWithBaseURI creates an instance of the TdeCertificatesClient client using a custom endpoint. 31// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 32func NewTdeCertificatesClientWithBaseURI(baseURI string, subscriptionID string) TdeCertificatesClient { 33 return TdeCertificatesClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// Create creates a TDE certificate for a given server. 37// Parameters: 38// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 39// from the Azure Resource Manager API or the portal. 40// serverName - the name of the server. 41// parameters - the requested TDE certificate to be created or updated. 42func (client TdeCertificatesClient) Create(ctx context.Context, resourceGroupName string, serverName string, parameters TdeCertificate) (result TdeCertificatesCreateFuture, err error) { 43 if tracing.IsEnabled() { 44 ctx = tracing.StartSpan(ctx, fqdn+"/TdeCertificatesClient.Create") 45 defer func() { 46 sc := -1 47 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 48 sc = result.FutureAPI.Response().StatusCode 49 } 50 tracing.EndSpan(ctx, sc, err) 51 }() 52 } 53 if err := validation.Validate([]validation.Validation{ 54 {TargetValue: parameters, 55 Constraints: []validation.Constraint{{Target: "parameters.TdeCertificateProperties", Name: validation.Null, Rule: false, 56 Chain: []validation.Constraint{{Target: "parameters.TdeCertificateProperties.PrivateBlob", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 57 return result, validation.NewError("sql.TdeCertificatesClient", "Create", err.Error()) 58 } 59 60 req, err := client.CreatePreparer(ctx, resourceGroupName, serverName, parameters) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "sql.TdeCertificatesClient", "Create", nil, "Failure preparing request") 63 return 64 } 65 66 result, err = client.CreateSender(req) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "sql.TdeCertificatesClient", "Create", nil, "Failure sending request") 69 return 70 } 71 72 return 73} 74 75// CreatePreparer prepares the Create request. 76func (client TdeCertificatesClient) CreatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters TdeCertificate) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "resourceGroupName": autorest.Encode("path", resourceGroupName), 79 "serverName": autorest.Encode("path", serverName), 80 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 81 } 82 83 const APIVersion = "2017-10-01-preview" 84 queryParameters := map[string]interface{}{ 85 "api-version": APIVersion, 86 } 87 88 preparer := autorest.CreatePreparer( 89 autorest.AsContentType("application/json; charset=utf-8"), 90 autorest.AsPost(), 91 autorest.WithBaseURL(client.BaseURI), 92 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/tdeCertificates", pathParameters), 93 autorest.WithJSON(parameters), 94 autorest.WithQueryParameters(queryParameters)) 95 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 96} 97 98// CreateSender sends the Create request. The method will close the 99// http.Response Body if it receives an error. 100func (client TdeCertificatesClient) CreateSender(req *http.Request) (future TdeCertificatesCreateFuture, err error) { 101 var resp *http.Response 102 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 103 if err != nil { 104 return 105 } 106 var azf azure.Future 107 azf, err = azure.NewFutureFromResponse(resp) 108 future.FutureAPI = &azf 109 future.Result = future.result 110 return 111} 112 113// CreateResponder handles the response to the Create request. The method always 114// closes the http.Response Body. 115func (client TdeCertificatesClient) CreateResponder(resp *http.Response) (result autorest.Response, err error) { 116 err = autorest.Respond( 117 resp, 118 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 119 autorest.ByClosing()) 120 result.Response = resp 121 return 122} 123