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// DataMaskingPoliciesClient 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 DataMaskingPoliciesClient struct { 32 BaseClient 33} 34 35// NewDataMaskingPoliciesClient creates an instance of the DataMaskingPoliciesClient client. 36func NewDataMaskingPoliciesClient(subscriptionID string) DataMaskingPoliciesClient { 37 return NewDataMaskingPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewDataMaskingPoliciesClientWithBaseURI creates an instance of the DataMaskingPoliciesClient 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 NewDataMaskingPoliciesClientWithBaseURI(baseURI string, subscriptionID string) DataMaskingPoliciesClient { 44 return DataMaskingPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// CreateOrUpdate creates or updates a database data masking 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// databaseName - the name of the database. 53// parameters - parameters for creating or updating a data masking policy. 54func (client DataMaskingPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters DataMaskingPolicy) (result DataMaskingPolicy, err error) { 55 if tracing.IsEnabled() { 56 ctx = tracing.StartSpan(ctx, fqdn+"/DataMaskingPoliciesClient.CreateOrUpdate") 57 defer func() { 58 sc := -1 59 if result.Response.Response != nil { 60 sc = result.Response.Response.StatusCode 61 } 62 tracing.EndSpan(ctx, sc, err) 63 }() 64 } 65 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, databaseName, parameters) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "sql.DataMaskingPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") 68 return 69 } 70 71 resp, err := client.CreateOrUpdateSender(req) 72 if err != nil { 73 result.Response = autorest.Response{Response: resp} 74 err = autorest.NewErrorWithError(err, "sql.DataMaskingPoliciesClient", "CreateOrUpdate", resp, "Failure sending request") 75 return 76 } 77 78 result, err = client.CreateOrUpdateResponder(resp) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "sql.DataMaskingPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request") 81 } 82 83 return 84} 85 86// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 87func (client DataMaskingPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters DataMaskingPolicy) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "databaseName": autorest.Encode("path", databaseName), 90 "dataMaskingPolicyName": autorest.Encode("path", "Default"), 91 "resourceGroupName": autorest.Encode("path", resourceGroupName), 92 "serverName": autorest.Encode("path", serverName), 93 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 94 } 95 96 const APIVersion = "2014-04-01" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 } 100 101 parameters.Location = nil 102 parameters.Kind = nil 103 preparer := autorest.CreatePreparer( 104 autorest.AsContentType("application/json; charset=utf-8"), 105 autorest.AsPut(), 106 autorest.WithBaseURL(client.BaseURI), 107 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}", pathParameters), 108 autorest.WithJSON(parameters), 109 autorest.WithQueryParameters(queryParameters)) 110 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 111} 112 113// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 114// http.Response Body if it receives an error. 115func (client DataMaskingPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 116 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 117} 118 119// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 120// closes the http.Response Body. 121func (client DataMaskingPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result DataMaskingPolicy, err error) { 122 err = autorest.Respond( 123 resp, 124 client.ByInspecting(), 125 azure.WithErrorUnlessStatusCode(http.StatusOK), 126 autorest.ByUnmarshallingJSON(&result), 127 autorest.ByClosing()) 128 result.Response = autorest.Response{Response: resp} 129 return 130} 131 132// Get gets a database data masking policy. 133// Parameters: 134// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 135// from the Azure Resource Manager API or the portal. 136// serverName - the name of the server. 137// databaseName - the name of the database. 138func (client DataMaskingPoliciesClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result DataMaskingPolicy, err error) { 139 if tracing.IsEnabled() { 140 ctx = tracing.StartSpan(ctx, fqdn+"/DataMaskingPoliciesClient.Get") 141 defer func() { 142 sc := -1 143 if result.Response.Response != nil { 144 sc = result.Response.Response.StatusCode 145 } 146 tracing.EndSpan(ctx, sc, err) 147 }() 148 } 149 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, databaseName) 150 if err != nil { 151 err = autorest.NewErrorWithError(err, "sql.DataMaskingPoliciesClient", "Get", nil, "Failure preparing request") 152 return 153 } 154 155 resp, err := client.GetSender(req) 156 if err != nil { 157 result.Response = autorest.Response{Response: resp} 158 err = autorest.NewErrorWithError(err, "sql.DataMaskingPoliciesClient", "Get", resp, "Failure sending request") 159 return 160 } 161 162 result, err = client.GetResponder(resp) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "sql.DataMaskingPoliciesClient", "Get", resp, "Failure responding to request") 165 } 166 167 return 168} 169 170// GetPreparer prepares the Get request. 171func (client DataMaskingPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 172 pathParameters := map[string]interface{}{ 173 "databaseName": autorest.Encode("path", databaseName), 174 "dataMaskingPolicyName": autorest.Encode("path", "Default"), 175 "resourceGroupName": autorest.Encode("path", resourceGroupName), 176 "serverName": autorest.Encode("path", serverName), 177 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 178 } 179 180 const APIVersion = "2014-04-01" 181 queryParameters := map[string]interface{}{ 182 "api-version": APIVersion, 183 } 184 185 preparer := autorest.CreatePreparer( 186 autorest.AsGet(), 187 autorest.WithBaseURL(client.BaseURI), 188 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/dataMaskingPolicies/{dataMaskingPolicyName}", pathParameters), 189 autorest.WithQueryParameters(queryParameters)) 190 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 191} 192 193// GetSender sends the Get request. The method will close the 194// http.Response Body if it receives an error. 195func (client DataMaskingPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { 196 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 197} 198 199// GetResponder handles the response to the Get request. The method always 200// closes the http.Response Body. 201func (client DataMaskingPoliciesClient) GetResponder(resp *http.Response) (result DataMaskingPolicy, err error) { 202 err = autorest.Respond( 203 resp, 204 client.ByInspecting(), 205 azure.WithErrorUnlessStatusCode(http.StatusOK), 206 autorest.ByUnmarshallingJSON(&result), 207 autorest.ByClosing()) 208 result.Response = autorest.Response{Response: resp} 209 return 210} 211