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/tracing" 14 "net/http" 15) 16 17// ExtendedServerBlobAuditingPoliciesClient is the the Azure SQL Database management API provides a RESTful set of web 18// services that interact with Azure SQL Database services to manage your databases. The API enables you to create, 19// retrieve, update, and delete databases. 20type ExtendedServerBlobAuditingPoliciesClient struct { 21 BaseClient 22} 23 24// NewExtendedServerBlobAuditingPoliciesClient creates an instance of the ExtendedServerBlobAuditingPoliciesClient 25// client. 26func NewExtendedServerBlobAuditingPoliciesClient(subscriptionID string) ExtendedServerBlobAuditingPoliciesClient { 27 return NewExtendedServerBlobAuditingPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewExtendedServerBlobAuditingPoliciesClientWithBaseURI creates an instance of the 31// ExtendedServerBlobAuditingPoliciesClient client using a custom endpoint. Use this when interacting with an Azure 32// cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 33func NewExtendedServerBlobAuditingPoliciesClientWithBaseURI(baseURI string, subscriptionID string) ExtendedServerBlobAuditingPoliciesClient { 34 return ExtendedServerBlobAuditingPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)} 35} 36 37// CreateOrUpdate creates or updates an extended server's blob auditing policy. 38// Parameters: 39// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 40// from the Azure Resource Manager API or the portal. 41// serverName - the name of the server. 42// parameters - properties of extended blob auditing policy 43func (client ExtendedServerBlobAuditingPoliciesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, parameters ExtendedServerBlobAuditingPolicy) (result ExtendedServerBlobAuditingPoliciesCreateOrUpdateFuture, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/ExtendedServerBlobAuditingPoliciesClient.CreateOrUpdate") 46 defer func() { 47 sc := -1 48 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 49 sc = result.FutureAPI.Response().StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, parameters) 55 if err != nil { 56 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request") 57 return 58 } 59 60 result, err = client.CreateOrUpdateSender(req) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "CreateOrUpdate", nil, "Failure sending request") 63 return 64 } 65 66 return 67} 68 69// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 70func (client ExtendedServerBlobAuditingPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ExtendedServerBlobAuditingPolicy) (*http.Request, error) { 71 pathParameters := map[string]interface{}{ 72 "blobAuditingPolicyName": autorest.Encode("path", "default"), 73 "resourceGroupName": autorest.Encode("path", resourceGroupName), 74 "serverName": autorest.Encode("path", serverName), 75 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 76 } 77 78 const APIVersion = "2017-03-01-preview" 79 queryParameters := map[string]interface{}{ 80 "api-version": APIVersion, 81 } 82 83 preparer := autorest.CreatePreparer( 84 autorest.AsContentType("application/json; charset=utf-8"), 85 autorest.AsPut(), 86 autorest.WithBaseURL(client.BaseURI), 87 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}", pathParameters), 88 autorest.WithJSON(parameters), 89 autorest.WithQueryParameters(queryParameters)) 90 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 91} 92 93// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 94// http.Response Body if it receives an error. 95func (client ExtendedServerBlobAuditingPoliciesClient) CreateOrUpdateSender(req *http.Request) (future ExtendedServerBlobAuditingPoliciesCreateOrUpdateFuture, err error) { 96 var resp *http.Response 97 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 98 if err != nil { 99 return 100 } 101 var azf azure.Future 102 azf, err = azure.NewFutureFromResponse(resp) 103 future.FutureAPI = &azf 104 future.Result = future.result 105 return 106} 107 108// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 109// closes the http.Response Body. 110func (client ExtendedServerBlobAuditingPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ExtendedServerBlobAuditingPolicy, err error) { 111 err = autorest.Respond( 112 resp, 113 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 114 autorest.ByUnmarshallingJSON(&result), 115 autorest.ByClosing()) 116 result.Response = autorest.Response{Response: resp} 117 return 118} 119 120// Get gets an extended server's blob auditing policy. 121// Parameters: 122// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 123// from the Azure Resource Manager API or the portal. 124// serverName - the name of the server. 125func (client ExtendedServerBlobAuditingPoliciesClient) Get(ctx context.Context, resourceGroupName string, serverName string) (result ExtendedServerBlobAuditingPolicy, err error) { 126 if tracing.IsEnabled() { 127 ctx = tracing.StartSpan(ctx, fqdn+"/ExtendedServerBlobAuditingPoliciesClient.Get") 128 defer func() { 129 sc := -1 130 if result.Response.Response != nil { 131 sc = result.Response.Response.StatusCode 132 } 133 tracing.EndSpan(ctx, sc, err) 134 }() 135 } 136 req, err := client.GetPreparer(ctx, resourceGroupName, serverName) 137 if err != nil { 138 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "Get", nil, "Failure preparing request") 139 return 140 } 141 142 resp, err := client.GetSender(req) 143 if err != nil { 144 result.Response = autorest.Response{Response: resp} 145 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "Get", resp, "Failure sending request") 146 return 147 } 148 149 result, err = client.GetResponder(resp) 150 if err != nil { 151 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "Get", resp, "Failure responding to request") 152 return 153 } 154 155 return 156} 157 158// GetPreparer prepares the Get request. 159func (client ExtendedServerBlobAuditingPoliciesClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 160 pathParameters := map[string]interface{}{ 161 "blobAuditingPolicyName": autorest.Encode("path", "default"), 162 "resourceGroupName": autorest.Encode("path", resourceGroupName), 163 "serverName": autorest.Encode("path", serverName), 164 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 165 } 166 167 const APIVersion = "2017-03-01-preview" 168 queryParameters := map[string]interface{}{ 169 "api-version": APIVersion, 170 } 171 172 preparer := autorest.CreatePreparer( 173 autorest.AsGet(), 174 autorest.WithBaseURL(client.BaseURI), 175 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings/{blobAuditingPolicyName}", pathParameters), 176 autorest.WithQueryParameters(queryParameters)) 177 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 178} 179 180// GetSender sends the Get request. The method will close the 181// http.Response Body if it receives an error. 182func (client ExtendedServerBlobAuditingPoliciesClient) GetSender(req *http.Request) (*http.Response, error) { 183 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 184} 185 186// GetResponder handles the response to the Get request. The method always 187// closes the http.Response Body. 188func (client ExtendedServerBlobAuditingPoliciesClient) GetResponder(resp *http.Response) (result ExtendedServerBlobAuditingPolicy, err error) { 189 err = autorest.Respond( 190 resp, 191 azure.WithErrorUnlessStatusCode(http.StatusOK), 192 autorest.ByUnmarshallingJSON(&result), 193 autorest.ByClosing()) 194 result.Response = autorest.Response{Response: resp} 195 return 196} 197 198// ListByServer lists extended auditing settings of a server. 199// Parameters: 200// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 201// from the Azure Resource Manager API or the portal. 202// serverName - the name of the server. 203func (client ExtendedServerBlobAuditingPoliciesClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ExtendedServerBlobAuditingPolicyListResultPage, err error) { 204 if tracing.IsEnabled() { 205 ctx = tracing.StartSpan(ctx, fqdn+"/ExtendedServerBlobAuditingPoliciesClient.ListByServer") 206 defer func() { 207 sc := -1 208 if result.esbaplr.Response.Response != nil { 209 sc = result.esbaplr.Response.Response.StatusCode 210 } 211 tracing.EndSpan(ctx, sc, err) 212 }() 213 } 214 result.fn = client.listByServerNextResults 215 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 216 if err != nil { 217 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "ListByServer", nil, "Failure preparing request") 218 return 219 } 220 221 resp, err := client.ListByServerSender(req) 222 if err != nil { 223 result.esbaplr.Response = autorest.Response{Response: resp} 224 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "ListByServer", resp, "Failure sending request") 225 return 226 } 227 228 result.esbaplr, err = client.ListByServerResponder(resp) 229 if err != nil { 230 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "ListByServer", resp, "Failure responding to request") 231 return 232 } 233 if result.esbaplr.hasNextLink() && result.esbaplr.IsEmpty() { 234 err = result.NextWithContext(ctx) 235 return 236 } 237 238 return 239} 240 241// ListByServerPreparer prepares the ListByServer request. 242func (client ExtendedServerBlobAuditingPoliciesClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 243 pathParameters := map[string]interface{}{ 244 "resourceGroupName": autorest.Encode("path", resourceGroupName), 245 "serverName": autorest.Encode("path", serverName), 246 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 247 } 248 249 const APIVersion = "2017-03-01-preview" 250 queryParameters := map[string]interface{}{ 251 "api-version": APIVersion, 252 } 253 254 preparer := autorest.CreatePreparer( 255 autorest.AsGet(), 256 autorest.WithBaseURL(client.BaseURI), 257 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/extendedAuditingSettings", pathParameters), 258 autorest.WithQueryParameters(queryParameters)) 259 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 260} 261 262// ListByServerSender sends the ListByServer request. The method will close the 263// http.Response Body if it receives an error. 264func (client ExtendedServerBlobAuditingPoliciesClient) ListByServerSender(req *http.Request) (*http.Response, error) { 265 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 266} 267 268// ListByServerResponder handles the response to the ListByServer request. The method always 269// closes the http.Response Body. 270func (client ExtendedServerBlobAuditingPoliciesClient) ListByServerResponder(resp *http.Response) (result ExtendedServerBlobAuditingPolicyListResult, err error) { 271 err = autorest.Respond( 272 resp, 273 azure.WithErrorUnlessStatusCode(http.StatusOK), 274 autorest.ByUnmarshallingJSON(&result), 275 autorest.ByClosing()) 276 result.Response = autorest.Response{Response: resp} 277 return 278} 279 280// listByServerNextResults retrieves the next set of results, if any. 281func (client ExtendedServerBlobAuditingPoliciesClient) listByServerNextResults(ctx context.Context, lastResults ExtendedServerBlobAuditingPolicyListResult) (result ExtendedServerBlobAuditingPolicyListResult, err error) { 282 req, err := lastResults.extendedServerBlobAuditingPolicyListResultPreparer(ctx) 283 if err != nil { 284 return result, autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "listByServerNextResults", nil, "Failure preparing next results request") 285 } 286 if req == nil { 287 return 288 } 289 resp, err := client.ListByServerSender(req) 290 if err != nil { 291 result.Response = autorest.Response{Response: resp} 292 return result, autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "listByServerNextResults", resp, "Failure sending next results request") 293 } 294 result, err = client.ListByServerResponder(resp) 295 if err != nil { 296 err = autorest.NewErrorWithError(err, "sql.ExtendedServerBlobAuditingPoliciesClient", "listByServerNextResults", resp, "Failure responding to next results request") 297 } 298 return 299} 300 301// ListByServerComplete enumerates all values, automatically crossing page boundaries as required. 302func (client ExtendedServerBlobAuditingPoliciesClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string) (result ExtendedServerBlobAuditingPolicyListResultIterator, err error) { 303 if tracing.IsEnabled() { 304 ctx = tracing.StartSpan(ctx, fqdn+"/ExtendedServerBlobAuditingPoliciesClient.ListByServer") 305 defer func() { 306 sc := -1 307 if result.Response().Response.Response != nil { 308 sc = result.page.Response().Response.Response.StatusCode 309 } 310 tracing.EndSpan(ctx, sc, err) 311 }() 312 } 313 result.page, err = client.ListByServer(ctx, resourceGroupName, serverName) 314 return 315} 316