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// DatabaseTableAuditingPoliciesClient is the the Azure SQL Database management API provides a RESTful set of web 29// services that interact with Azure SQL Database services to manage your databases. The API enables you to create, 30// retrieve, update, and delete databases. 31type DatabaseTableAuditingPoliciesClient struct { 32 BaseClient 33} 34 35// NewDatabaseTableAuditingPoliciesClient creates an instance of the DatabaseTableAuditingPoliciesClient client. 36func NewDatabaseTableAuditingPoliciesClient(subscriptionID string) DatabaseTableAuditingPoliciesClient { 37 return NewDatabaseTableAuditingPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewDatabaseTableAuditingPoliciesClientWithBaseURI creates an instance of the DatabaseTableAuditingPoliciesClient 41// client using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI 42// (sovereign clouds, Azure stack). 43func NewDatabaseTableAuditingPoliciesClientWithBaseURI(baseURI string, subscriptionID string) DatabaseTableAuditingPoliciesClient { 44 return DatabaseTableAuditingPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// CreateOrUpdate creates or updates a database's table auditing policy. Table auditing is deprecated, use blob 48// auditing instead. 49// Parameters: 50// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 51// from the Azure Resource Manager API or the portal. 52// serverName - the name of the server. 53// databaseName - the name of the database for which the table auditing policy will be defined. 54// parameters - the database table auditing policy. 55func (client DatabaseTableAuditingPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters DatabaseTableAuditingPolicy) (result DatabaseTableAuditingPolicy, err error) { 56 if tracing.IsEnabled() { 57 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseTableAuditingPoliciesClient.CreateOrUpdate") 58 defer func() { 59 sc := -1 60 if result.Response.Response != nil { 61 sc = result.Response.Response.StatusCode 62 } 63 tracing.EndSpan(ctx, sc, err) 64 }() 65 } 66 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, databaseName, parameters) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") 69 return 70 } 71 72 resp, err := client.CreateOrUpdateSender(req) 73 if err != nil { 74 result.Response = autorest.Response{Response: resp} 75 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "CreateOrUpdate", resp, "Failure sending request") 76 return 77 } 78 79 result, err = client.CreateOrUpdateResponder(resp) 80 if err != nil { 81 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request") 82 return 83 } 84 85 return 86} 87 88// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 89func (client DatabaseTableAuditingPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters DatabaseTableAuditingPolicy) (*http.Request, error) { 90 pathParameters := map[string]interface{}{ 91 "databaseName": autorest.Encode("path", databaseName), 92 "resourceGroupName": autorest.Encode("path", resourceGroupName), 93 "serverName": autorest.Encode("path", serverName), 94 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 95 "tableAuditingPolicyName": autorest.Encode("path", "default"), 96 } 97 98 const APIVersion = "2014-04-01" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 parameters.Kind = nil 104 parameters.Location = nil 105 preparer := autorest.CreatePreparer( 106 autorest.AsContentType("application/json; charset=utf-8"), 107 autorest.AsPut(), 108 autorest.WithBaseURL(client.BaseURI), 109 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingPolicies/{tableAuditingPolicyName}", pathParameters), 110 autorest.WithJSON(parameters), 111 autorest.WithQueryParameters(queryParameters)) 112 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 113} 114 115// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 116// http.Response Body if it receives an error. 117func (client DatabaseTableAuditingPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 118 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 119} 120 121// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 122// closes the http.Response Body. 123func (client DatabaseTableAuditingPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result DatabaseTableAuditingPolicy, err error) { 124 err = autorest.Respond( 125 resp, 126 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 127 autorest.ByUnmarshallingJSON(&result), 128 autorest.ByClosing()) 129 result.Response = autorest.Response{Response: resp} 130 return 131} 132 133// Get gets a database's table auditing policy. Table auditing is deprecated, use blob auditing instead. 134// Parameters: 135// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 136// from the Azure Resource Manager API or the portal. 137// serverName - the name of the server. 138// databaseName - the name of the database for which the table audit policy is defined. 139func (client DatabaseTableAuditingPoliciesClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result DatabaseTableAuditingPolicy, err error) { 140 if tracing.IsEnabled() { 141 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseTableAuditingPoliciesClient.Get") 142 defer func() { 143 sc := -1 144 if result.Response.Response != nil { 145 sc = result.Response.Response.StatusCode 146 } 147 tracing.EndSpan(ctx, sc, err) 148 }() 149 } 150 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, databaseName) 151 if err != nil { 152 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "Get", nil, "Failure preparing request") 153 return 154 } 155 156 resp, err := client.GetSender(req) 157 if err != nil { 158 result.Response = autorest.Response{Response: resp} 159 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "Get", resp, "Failure sending request") 160 return 161 } 162 163 result, err = client.GetResponder(resp) 164 if err != nil { 165 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "Get", resp, "Failure responding to request") 166 return 167 } 168 169 return 170} 171 172// GetPreparer prepares the Get request. 173func (client DatabaseTableAuditingPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 174 pathParameters := map[string]interface{}{ 175 "databaseName": autorest.Encode("path", databaseName), 176 "resourceGroupName": autorest.Encode("path", resourceGroupName), 177 "serverName": autorest.Encode("path", serverName), 178 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 179 "tableAuditingPolicyName": autorest.Encode("path", "default"), 180 } 181 182 const APIVersion = "2014-04-01" 183 queryParameters := map[string]interface{}{ 184 "api-version": APIVersion, 185 } 186 187 preparer := autorest.CreatePreparer( 188 autorest.AsGet(), 189 autorest.WithBaseURL(client.BaseURI), 190 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingPolicies/{tableAuditingPolicyName}", pathParameters), 191 autorest.WithQueryParameters(queryParameters)) 192 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 193} 194 195// GetSender sends the Get request. The method will close the 196// http.Response Body if it receives an error. 197func (client DatabaseTableAuditingPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { 198 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 199} 200 201// GetResponder handles the response to the Get request. The method always 202// closes the http.Response Body. 203func (client DatabaseTableAuditingPoliciesClient) GetResponder(resp *http.Response) (result DatabaseTableAuditingPolicy, err error) { 204 err = autorest.Respond( 205 resp, 206 azure.WithErrorUnlessStatusCode(http.StatusOK), 207 autorest.ByUnmarshallingJSON(&result), 208 autorest.ByClosing()) 209 result.Response = autorest.Response{Response: resp} 210 return 211} 212 213// ListByDatabase lists a database's table auditing policies. Table auditing is deprecated, use blob auditing instead. 214// Parameters: 215// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 216// from the Azure Resource Manager API or the portal. 217// serverName - the name of the server. 218// databaseName - the name of the database for which the table audit policy is defined. 219func (client DatabaseTableAuditingPoliciesClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result DatabaseTableAuditingPolicyListResult, err error) { 220 if tracing.IsEnabled() { 221 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseTableAuditingPoliciesClient.ListByDatabase") 222 defer func() { 223 sc := -1 224 if result.Response.Response != nil { 225 sc = result.Response.Response.StatusCode 226 } 227 tracing.EndSpan(ctx, sc, err) 228 }() 229 } 230 req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName) 231 if err != nil { 232 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "ListByDatabase", nil, "Failure preparing request") 233 return 234 } 235 236 resp, err := client.ListByDatabaseSender(req) 237 if err != nil { 238 result.Response = autorest.Response{Response: resp} 239 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "ListByDatabase", resp, "Failure sending request") 240 return 241 } 242 243 result, err = client.ListByDatabaseResponder(resp) 244 if err != nil { 245 err = autorest.NewErrorWithError(err, "sql.DatabaseTableAuditingPoliciesClient", "ListByDatabase", resp, "Failure responding to request") 246 return 247 } 248 249 return 250} 251 252// ListByDatabasePreparer prepares the ListByDatabase request. 253func (client DatabaseTableAuditingPoliciesClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 254 pathParameters := map[string]interface{}{ 255 "databaseName": autorest.Encode("path", databaseName), 256 "resourceGroupName": autorest.Encode("path", resourceGroupName), 257 "serverName": autorest.Encode("path", serverName), 258 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 259 } 260 261 const APIVersion = "2014-04-01" 262 queryParameters := map[string]interface{}{ 263 "api-version": APIVersion, 264 } 265 266 preparer := autorest.CreatePreparer( 267 autorest.AsGet(), 268 autorest.WithBaseURL(client.BaseURI), 269 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingPolicies", pathParameters), 270 autorest.WithQueryParameters(queryParameters)) 271 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 272} 273 274// ListByDatabaseSender sends the ListByDatabase request. The method will close the 275// http.Response Body if it receives an error. 276func (client DatabaseTableAuditingPoliciesClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) { 277 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 278} 279 280// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always 281// closes the http.Response Body. 282func (client DatabaseTableAuditingPoliciesClient) ListByDatabaseResponder(resp *http.Response) (result DatabaseTableAuditingPolicyListResult, err error) { 283 err = autorest.Respond( 284 resp, 285 azure.WithErrorUnlessStatusCode(http.StatusOK), 286 autorest.ByUnmarshallingJSON(&result), 287 autorest.ByClosing()) 288 result.Response = autorest.Response{Response: resp} 289 return 290} 291