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// DatabaseVulnerabilityAssessmentsClient 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 DatabaseVulnerabilityAssessmentsClient struct { 21 BaseClient 22} 23 24// NewDatabaseVulnerabilityAssessmentsClient creates an instance of the DatabaseVulnerabilityAssessmentsClient client. 25func NewDatabaseVulnerabilityAssessmentsClient(subscriptionID string) DatabaseVulnerabilityAssessmentsClient { 26 return NewDatabaseVulnerabilityAssessmentsClientWithBaseURI(DefaultBaseURI, subscriptionID) 27} 28 29// NewDatabaseVulnerabilityAssessmentsClientWithBaseURI creates an instance of the 30// DatabaseVulnerabilityAssessmentsClient client using a custom endpoint. Use this when interacting with an Azure 31// cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 32func NewDatabaseVulnerabilityAssessmentsClientWithBaseURI(baseURI string, subscriptionID string) DatabaseVulnerabilityAssessmentsClient { 33 return DatabaseVulnerabilityAssessmentsClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// CreateOrUpdate creates or updates the database's vulnerability assessment. 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// databaseName - the name of the database for which the vulnerability assessment is defined. 42// parameters - the requested resource. 43func (client DatabaseVulnerabilityAssessmentsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters DatabaseVulnerabilityAssessment) (result DatabaseVulnerabilityAssessment, err error) { 44 if tracing.IsEnabled() { 45 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentsClient.CreateOrUpdate") 46 defer func() { 47 sc := -1 48 if result.Response.Response != nil { 49 sc = result.Response.Response.StatusCode 50 } 51 tracing.EndSpan(ctx, sc, err) 52 }() 53 } 54 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, serverName, databaseName, parameters) 55 if err != nil { 56 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "CreateOrUpdate", nil, "Failure preparing request") 57 return 58 } 59 60 resp, err := client.CreateOrUpdateSender(req) 61 if err != nil { 62 result.Response = autorest.Response{Response: resp} 63 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "CreateOrUpdate", resp, "Failure sending request") 64 return 65 } 66 67 result, err = client.CreateOrUpdateResponder(resp) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "CreateOrUpdate", resp, "Failure responding to request") 70 return 71 } 72 73 return 74} 75 76// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 77func (client DatabaseVulnerabilityAssessmentsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, parameters DatabaseVulnerabilityAssessment) (*http.Request, error) { 78 pathParameters := map[string]interface{}{ 79 "databaseName": autorest.Encode("path", databaseName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "serverName": autorest.Encode("path", serverName), 82 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 83 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 84 } 85 86 const APIVersion = "2017-03-01-preview" 87 queryParameters := map[string]interface{}{ 88 "api-version": APIVersion, 89 } 90 91 preparer := autorest.CreatePreparer( 92 autorest.AsContentType("application/json; charset=utf-8"), 93 autorest.AsPut(), 94 autorest.WithBaseURL(client.BaseURI), 95 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", pathParameters), 96 autorest.WithJSON(parameters), 97 autorest.WithQueryParameters(queryParameters)) 98 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 99} 100 101// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 102// http.Response Body if it receives an error. 103func (client DatabaseVulnerabilityAssessmentsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) { 104 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 105} 106 107// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 108// closes the http.Response Body. 109func (client DatabaseVulnerabilityAssessmentsClient) CreateOrUpdateResponder(resp *http.Response) (result DatabaseVulnerabilityAssessment, err error) { 110 err = autorest.Respond( 111 resp, 112 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 113 autorest.ByUnmarshallingJSON(&result), 114 autorest.ByClosing()) 115 result.Response = autorest.Response{Response: resp} 116 return 117} 118 119// Delete removes the database's vulnerability assessment. 120// Parameters: 121// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 122// from the Azure Resource Manager API or the portal. 123// serverName - the name of the server. 124// databaseName - the name of the database for which the vulnerability assessment is defined. 125func (client DatabaseVulnerabilityAssessmentsClient) Delete(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result autorest.Response, err error) { 126 if tracing.IsEnabled() { 127 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentsClient.Delete") 128 defer func() { 129 sc := -1 130 if result.Response != nil { 131 sc = result.Response.StatusCode 132 } 133 tracing.EndSpan(ctx, sc, err) 134 }() 135 } 136 req, err := client.DeletePreparer(ctx, resourceGroupName, serverName, databaseName) 137 if err != nil { 138 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "Delete", nil, "Failure preparing request") 139 return 140 } 141 142 resp, err := client.DeleteSender(req) 143 if err != nil { 144 result.Response = resp 145 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "Delete", resp, "Failure sending request") 146 return 147 } 148 149 result, err = client.DeleteResponder(resp) 150 if err != nil { 151 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "Delete", resp, "Failure responding to request") 152 return 153 } 154 155 return 156} 157 158// DeletePreparer prepares the Delete request. 159func (client DatabaseVulnerabilityAssessmentsClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 160 pathParameters := map[string]interface{}{ 161 "databaseName": autorest.Encode("path", databaseName), 162 "resourceGroupName": autorest.Encode("path", resourceGroupName), 163 "serverName": autorest.Encode("path", serverName), 164 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 165 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 166 } 167 168 const APIVersion = "2017-03-01-preview" 169 queryParameters := map[string]interface{}{ 170 "api-version": APIVersion, 171 } 172 173 preparer := autorest.CreatePreparer( 174 autorest.AsDelete(), 175 autorest.WithBaseURL(client.BaseURI), 176 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", pathParameters), 177 autorest.WithQueryParameters(queryParameters)) 178 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 179} 180 181// DeleteSender sends the Delete request. The method will close the 182// http.Response Body if it receives an error. 183func (client DatabaseVulnerabilityAssessmentsClient) DeleteSender(req *http.Request) (*http.Response, error) { 184 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 185} 186 187// DeleteResponder handles the response to the Delete request. The method always 188// closes the http.Response Body. 189func (client DatabaseVulnerabilityAssessmentsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 190 err = autorest.Respond( 191 resp, 192 azure.WithErrorUnlessStatusCode(http.StatusOK), 193 autorest.ByClosing()) 194 result.Response = resp 195 return 196} 197 198// Get gets the database's vulnerability assessment. 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. 203// databaseName - the name of the database for which the vulnerability assessment is defined. 204func (client DatabaseVulnerabilityAssessmentsClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result DatabaseVulnerabilityAssessment, err error) { 205 if tracing.IsEnabled() { 206 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentsClient.Get") 207 defer func() { 208 sc := -1 209 if result.Response.Response != nil { 210 sc = result.Response.Response.StatusCode 211 } 212 tracing.EndSpan(ctx, sc, err) 213 }() 214 } 215 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, databaseName) 216 if err != nil { 217 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "Get", nil, "Failure preparing request") 218 return 219 } 220 221 resp, err := client.GetSender(req) 222 if err != nil { 223 result.Response = autorest.Response{Response: resp} 224 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "Get", resp, "Failure sending request") 225 return 226 } 227 228 result, err = client.GetResponder(resp) 229 if err != nil { 230 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "Get", resp, "Failure responding to request") 231 return 232 } 233 234 return 235} 236 237// GetPreparer prepares the Get request. 238func (client DatabaseVulnerabilityAssessmentsClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 239 pathParameters := map[string]interface{}{ 240 "databaseName": autorest.Encode("path", databaseName), 241 "resourceGroupName": autorest.Encode("path", resourceGroupName), 242 "serverName": autorest.Encode("path", serverName), 243 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 244 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 245 } 246 247 const APIVersion = "2017-03-01-preview" 248 queryParameters := map[string]interface{}{ 249 "api-version": APIVersion, 250 } 251 252 preparer := autorest.CreatePreparer( 253 autorest.AsGet(), 254 autorest.WithBaseURL(client.BaseURI), 255 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}", pathParameters), 256 autorest.WithQueryParameters(queryParameters)) 257 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 258} 259 260// GetSender sends the Get request. The method will close the 261// http.Response Body if it receives an error. 262func (client DatabaseVulnerabilityAssessmentsClient) GetSender(req *http.Request) (*http.Response, error) { 263 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 264} 265 266// GetResponder handles the response to the Get request. The method always 267// closes the http.Response Body. 268func (client DatabaseVulnerabilityAssessmentsClient) GetResponder(resp *http.Response) (result DatabaseVulnerabilityAssessment, err error) { 269 err = autorest.Respond( 270 resp, 271 azure.WithErrorUnlessStatusCode(http.StatusOK), 272 autorest.ByUnmarshallingJSON(&result), 273 autorest.ByClosing()) 274 result.Response = autorest.Response{Response: resp} 275 return 276} 277 278// ListByDatabase lists the vulnerability assessment policies associated with a database. 279// Parameters: 280// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 281// from the Azure Resource Manager API or the portal. 282// serverName - the name of the server. 283// databaseName - the name of the database for which the vulnerability assessment policies are defined. 284func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result DatabaseVulnerabilityAssessmentListResultPage, err error) { 285 if tracing.IsEnabled() { 286 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentsClient.ListByDatabase") 287 defer func() { 288 sc := -1 289 if result.dvalr.Response.Response != nil { 290 sc = result.dvalr.Response.Response.StatusCode 291 } 292 tracing.EndSpan(ctx, sc, err) 293 }() 294 } 295 result.fn = client.listByDatabaseNextResults 296 req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName) 297 if err != nil { 298 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "ListByDatabase", nil, "Failure preparing request") 299 return 300 } 301 302 resp, err := client.ListByDatabaseSender(req) 303 if err != nil { 304 result.dvalr.Response = autorest.Response{Response: resp} 305 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "ListByDatabase", resp, "Failure sending request") 306 return 307 } 308 309 result.dvalr, err = client.ListByDatabaseResponder(resp) 310 if err != nil { 311 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "ListByDatabase", resp, "Failure responding to request") 312 return 313 } 314 if result.dvalr.hasNextLink() && result.dvalr.IsEmpty() { 315 err = result.NextWithContext(ctx) 316 return 317 } 318 319 return 320} 321 322// ListByDatabasePreparer prepares the ListByDatabase request. 323func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 324 pathParameters := map[string]interface{}{ 325 "databaseName": autorest.Encode("path", databaseName), 326 "resourceGroupName": autorest.Encode("path", resourceGroupName), 327 "serverName": autorest.Encode("path", serverName), 328 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 329 } 330 331 const APIVersion = "2017-03-01-preview" 332 queryParameters := map[string]interface{}{ 333 "api-version": APIVersion, 334 } 335 336 preparer := autorest.CreatePreparer( 337 autorest.AsGet(), 338 autorest.WithBaseURL(client.BaseURI), 339 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments", pathParameters), 340 autorest.WithQueryParameters(queryParameters)) 341 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 342} 343 344// ListByDatabaseSender sends the ListByDatabase request. The method will close the 345// http.Response Body if it receives an error. 346func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) { 347 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 348} 349 350// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always 351// closes the http.Response Body. 352func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabaseResponder(resp *http.Response) (result DatabaseVulnerabilityAssessmentListResult, err error) { 353 err = autorest.Respond( 354 resp, 355 azure.WithErrorUnlessStatusCode(http.StatusOK), 356 autorest.ByUnmarshallingJSON(&result), 357 autorest.ByClosing()) 358 result.Response = autorest.Response{Response: resp} 359 return 360} 361 362// listByDatabaseNextResults retrieves the next set of results, if any. 363func (client DatabaseVulnerabilityAssessmentsClient) listByDatabaseNextResults(ctx context.Context, lastResults DatabaseVulnerabilityAssessmentListResult) (result DatabaseVulnerabilityAssessmentListResult, err error) { 364 req, err := lastResults.databaseVulnerabilityAssessmentListResultPreparer(ctx) 365 if err != nil { 366 return result, autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", nil, "Failure preparing next results request") 367 } 368 if req == nil { 369 return 370 } 371 resp, err := client.ListByDatabaseSender(req) 372 if err != nil { 373 result.Response = autorest.Response{Response: resp} 374 return result, autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", resp, "Failure sending next results request") 375 } 376 result, err = client.ListByDatabaseResponder(resp) 377 if err != nil { 378 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentsClient", "listByDatabaseNextResults", resp, "Failure responding to next results request") 379 } 380 return 381} 382 383// ListByDatabaseComplete enumerates all values, automatically crossing page boundaries as required. 384func (client DatabaseVulnerabilityAssessmentsClient) ListByDatabaseComplete(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result DatabaseVulnerabilityAssessmentListResultIterator, err error) { 385 if tracing.IsEnabled() { 386 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentsClient.ListByDatabase") 387 defer func() { 388 sc := -1 389 if result.Response().Response.Response != nil { 390 sc = result.page.Response().Response.Response.StatusCode 391 } 392 tracing.EndSpan(ctx, sc, err) 393 }() 394 } 395 result.page, err = client.ListByDatabase(ctx, resourceGroupName, serverName, databaseName) 396 return 397} 398