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// ServerBlobAuditingPoliciesClient 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 ServerBlobAuditingPoliciesClient struct { 32 BaseClient 33} 34 35// NewServerBlobAuditingPoliciesClient creates an instance of the ServerBlobAuditingPoliciesClient client. 36func NewServerBlobAuditingPoliciesClient(subscriptionID string) ServerBlobAuditingPoliciesClient { 37 return NewServerBlobAuditingPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewServerBlobAuditingPoliciesClientWithBaseURI creates an instance of the ServerBlobAuditingPoliciesClient client 41// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 42// clouds, Azure stack). 43func NewServerBlobAuditingPoliciesClientWithBaseURI(baseURI string, subscriptionID string) ServerBlobAuditingPoliciesClient { 44 return ServerBlobAuditingPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// CreateOrUpdate creates or updates a server's blob auditing 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 - properties of blob auditing policy 53func (client ServerBlobAuditingPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, parameters ServerBlobAuditingPolicy) (result ServerBlobAuditingPoliciesCreateOrUpdateFuture, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/ServerBlobAuditingPoliciesClient.CreateOrUpdate") 56 defer func() { 57 sc := -1 58 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 59 sc = result.FutureAPI.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.ServerBlobAuditingPoliciesClient", "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.ServerBlobAuditingPoliciesClient", "CreateOrUpdate", nil, "Failure sending request") 73 return 74 } 75 76 return 77} 78 79// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 80func (client ServerBlobAuditingPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerBlobAuditingPolicy) (*http.Request, error) { 81 pathParameters := map[string]interface{}{ 82 "blobAuditingPolicyName": autorest.Encode("path", "default"), 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "serverName": autorest.Encode("path", serverName), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2017-03-01-preview" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 93 preparer := autorest.CreatePreparer( 94 autorest.AsContentType("application/json; charset=utf-8"), 95 autorest.AsPut(), 96 autorest.WithBaseURL(client.BaseURI), 97 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}", pathParameters), 98 autorest.WithJSON(parameters), 99 autorest.WithQueryParameters(queryParameters)) 100 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 101} 102 103// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 104// http.Response Body if it receives an error. 105func (client ServerBlobAuditingPoliciesClient) CreateOrUpdateSender(req *http.Request) (future ServerBlobAuditingPoliciesCreateOrUpdateFuture, err error) { 106 var resp *http.Response 107 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 108 if err != nil { 109 return 110 } 111 var azf azure.Future 112 azf, err = azure.NewFutureFromResponse(resp) 113 future.FutureAPI = &azf 114 future.Result = func(client ServerBlobAuditingPoliciesClient) (sbap ServerBlobAuditingPolicy, err error) { 115 var done bool 116 done, err = future.DoneWithContext(context.Background(), client) 117 if err != nil { 118 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") 119 return 120 } 121 if !done { 122 err = azure.NewAsyncOpIncompleteError("sql.ServerBlobAuditingPoliciesCreateOrUpdateFuture") 123 return 124 } 125 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 126 sbap.Response.Response, err = future.GetResult(sender) 127 if sbap.Response.Response == nil && err == nil { 128 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesCreateOrUpdateFuture", "Result", nil, "received nil response and error") 129 } 130 if err == nil && sbap.Response.Response.StatusCode != http.StatusNoContent { 131 sbap, err = client.CreateOrUpdateResponder(sbap.Response.Response) 132 if err != nil { 133 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesCreateOrUpdateFuture", "Result", sbap.Response.Response, "Failure responding to request") 134 } 135 } 136 return 137 } 138 return 139} 140 141// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 142// closes the http.Response Body. 143func (client ServerBlobAuditingPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ServerBlobAuditingPolicy, err error) { 144 err = autorest.Respond( 145 resp, 146 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 147 autorest.ByUnmarshallingJSON(&result), 148 autorest.ByClosing()) 149 result.Response = autorest.Response{Response: resp} 150 return 151} 152 153// Get gets a server's blob auditing policy. 154// Parameters: 155// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 156// from the Azure Resource Manager API or the portal. 157// serverName - the name of the server. 158func (client ServerBlobAuditingPoliciesClient) Get(ctx context.Context, resourceGroupName string, serverName string) (result ServerBlobAuditingPolicy, err error) { 159 if tracing.IsEnabled() { 160 ctx = tracing.StartSpan(ctx, fqdn+"/ServerBlobAuditingPoliciesClient.Get") 161 defer func() { 162 sc := -1 163 if result.Response.Response != nil { 164 sc = result.Response.Response.StatusCode 165 } 166 tracing.EndSpan(ctx, sc, err) 167 }() 168 } 169 req, err := client.GetPreparer(ctx, resourceGroupName, serverName) 170 if err != nil { 171 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "Get", nil, "Failure preparing request") 172 return 173 } 174 175 resp, err := client.GetSender(req) 176 if err != nil { 177 result.Response = autorest.Response{Response: resp} 178 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "Get", resp, "Failure sending request") 179 return 180 } 181 182 result, err = client.GetResponder(resp) 183 if err != nil { 184 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "Get", resp, "Failure responding to request") 185 return 186 } 187 188 return 189} 190 191// GetPreparer prepares the Get request. 192func (client ServerBlobAuditingPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 193 pathParameters := map[string]interface{}{ 194 "blobAuditingPolicyName": autorest.Encode("path", "default"), 195 "resourceGroupName": autorest.Encode("path", resourceGroupName), 196 "serverName": autorest.Encode("path", serverName), 197 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 198 } 199 200 const APIVersion = "2017-03-01-preview" 201 queryParameters := map[string]interface{}{ 202 "api-version": APIVersion, 203 } 204 205 preparer := autorest.CreatePreparer( 206 autorest.AsGet(), 207 autorest.WithBaseURL(client.BaseURI), 208 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings/{blobAuditingPolicyName}", pathParameters), 209 autorest.WithQueryParameters(queryParameters)) 210 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 211} 212 213// GetSender sends the Get request. The method will close the 214// http.Response Body if it receives an error. 215func (client ServerBlobAuditingPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { 216 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 217} 218 219// GetResponder handles the response to the Get request. The method always 220// closes the http.Response Body. 221func (client ServerBlobAuditingPoliciesClient) GetResponder(resp *http.Response) (result ServerBlobAuditingPolicy, err error) { 222 err = autorest.Respond( 223 resp, 224 azure.WithErrorUnlessStatusCode(http.StatusOK), 225 autorest.ByUnmarshallingJSON(&result), 226 autorest.ByClosing()) 227 result.Response = autorest.Response{Response: resp} 228 return 229} 230 231// ListByServer lists auditing settings of a server. 232// Parameters: 233// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 234// from the Azure Resource Manager API or the portal. 235// serverName - the name of the server. 236func (client ServerBlobAuditingPoliciesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ServerBlobAuditingPolicyListResultPage, err error) { 237 if tracing.IsEnabled() { 238 ctx = tracing.StartSpan(ctx, fqdn+"/ServerBlobAuditingPoliciesClient.ListByServer") 239 defer func() { 240 sc := -1 241 if result.sbaplr.Response.Response != nil { 242 sc = result.sbaplr.Response.Response.StatusCode 243 } 244 tracing.EndSpan(ctx, sc, err) 245 }() 246 } 247 result.fn = client.listByServerNextResults 248 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 249 if err != nil { 250 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "ListByServer", nil, "Failure preparing request") 251 return 252 } 253 254 resp, err := client.ListByServerSender(req) 255 if err != nil { 256 result.sbaplr.Response = autorest.Response{Response: resp} 257 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "ListByServer", resp, "Failure sending request") 258 return 259 } 260 261 result.sbaplr, err = client.ListByServerResponder(resp) 262 if err != nil { 263 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "ListByServer", resp, "Failure responding to request") 264 return 265 } 266 if result.sbaplr.hasNextLink() && result.sbaplr.IsEmpty() { 267 err = result.NextWithContext(ctx) 268 return 269 } 270 271 return 272} 273 274// ListByServerPreparer prepares the ListByServer request. 275func (client ServerBlobAuditingPoliciesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 276 pathParameters := map[string]interface{}{ 277 "resourceGroupName": autorest.Encode("path", resourceGroupName), 278 "serverName": autorest.Encode("path", serverName), 279 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 280 } 281 282 const APIVersion = "2017-03-01-preview" 283 queryParameters := map[string]interface{}{ 284 "api-version": APIVersion, 285 } 286 287 preparer := autorest.CreatePreparer( 288 autorest.AsGet(), 289 autorest.WithBaseURL(client.BaseURI), 290 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/auditingSettings", pathParameters), 291 autorest.WithQueryParameters(queryParameters)) 292 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 293} 294 295// ListByServerSender sends the ListByServer request. The method will close the 296// http.Response Body if it receives an error. 297func (client ServerBlobAuditingPoliciesClient) ListByServerSender(req *http.Request) (*http.Response, error) { 298 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 299} 300 301// ListByServerResponder handles the response to the ListByServer request. The method always 302// closes the http.Response Body. 303func (client ServerBlobAuditingPoliciesClient) ListByServerResponder(resp *http.Response) (result ServerBlobAuditingPolicyListResult, err error) { 304 err = autorest.Respond( 305 resp, 306 azure.WithErrorUnlessStatusCode(http.StatusOK), 307 autorest.ByUnmarshallingJSON(&result), 308 autorest.ByClosing()) 309 result.Response = autorest.Response{Response: resp} 310 return 311} 312 313// listByServerNextResults retrieves the next set of results, if any. 314func (client ServerBlobAuditingPoliciesClient) listByServerNextResults(ctx context.Context, lastResults ServerBlobAuditingPolicyListResult) (result ServerBlobAuditingPolicyListResult, err error) { 315 req, err := lastResults.serverBlobAuditingPolicyListResultPreparer(ctx) 316 if err != nil { 317 return result, autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "listByServerNextResults", nil, "Failure preparing next results request") 318 } 319 if req == nil { 320 return 321 } 322 resp, err := client.ListByServerSender(req) 323 if err != nil { 324 result.Response = autorest.Response{Response: resp} 325 return result, autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "listByServerNextResults", resp, "Failure sending next results request") 326 } 327 result, err = client.ListByServerResponder(resp) 328 if err != nil { 329 err = autorest.NewErrorWithError(err, "sql.ServerBlobAuditingPoliciesClient", "listByServerNextResults", resp, "Failure responding to next results request") 330 } 331 return 332} 333 334// ListByServerComplete enumerates all values, automatically crossing page boundaries as required. 335func (client ServerBlobAuditingPoliciesClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string) (result ServerBlobAuditingPolicyListResultIterator, err error) { 336 if tracing.IsEnabled() { 337 ctx = tracing.StartSpan(ctx, fqdn+"/ServerBlobAuditingPoliciesClient.ListByServer") 338 defer func() { 339 sc := -1 340 if result.Response().Response.Response != nil { 341 sc = result.page.Response().Response.Response.StatusCode 342 } 343 tracing.EndSpan(ctx, sc, err) 344 }() 345 } 346 result.page, err = client.ListByServer(ctx, resourceGroupName, serverName) 347 return 348} 349