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// DatabaseVulnerabilityAssessmentScansClient is the the Azure SQL Database management API provides a RESTful set of 29// web 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 DatabaseVulnerabilityAssessmentScansClient struct { 32 BaseClient 33} 34 35// NewDatabaseVulnerabilityAssessmentScansClient creates an instance of the DatabaseVulnerabilityAssessmentScansClient 36// client. 37func NewDatabaseVulnerabilityAssessmentScansClient(subscriptionID string) DatabaseVulnerabilityAssessmentScansClient { 38 return NewDatabaseVulnerabilityAssessmentScansClientWithBaseURI(DefaultBaseURI, subscriptionID) 39} 40 41// NewDatabaseVulnerabilityAssessmentScansClientWithBaseURI creates an instance of the 42// DatabaseVulnerabilityAssessmentScansClient client using a custom endpoint. Use this when interacting with an Azure 43// cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 44func NewDatabaseVulnerabilityAssessmentScansClientWithBaseURI(baseURI string, subscriptionID string) DatabaseVulnerabilityAssessmentScansClient { 45 return DatabaseVulnerabilityAssessmentScansClient{NewWithBaseURI(baseURI, subscriptionID)} 46} 47 48// Export convert an existing scan result to a human readable format. If already exists nothing happens 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 scanned database. 54// scanID - the vulnerability assessment scan Id. 55func (client DatabaseVulnerabilityAssessmentScansClient) Export(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (result DatabaseVulnerabilityAssessmentScansExport, err error) { 56 if tracing.IsEnabled() { 57 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.Export") 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.ExportPreparer(ctx, resourceGroupName, serverName, databaseName, scanID) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Export", nil, "Failure preparing request") 69 return 70 } 71 72 resp, err := client.ExportSender(req) 73 if err != nil { 74 result.Response = autorest.Response{Response: resp} 75 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Export", resp, "Failure sending request") 76 return 77 } 78 79 result, err = client.ExportResponder(resp) 80 if err != nil { 81 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Export", resp, "Failure responding to request") 82 } 83 84 return 85} 86 87// ExportPreparer prepares the Export request. 88func (client DatabaseVulnerabilityAssessmentScansClient) ExportPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (*http.Request, error) { 89 pathParameters := map[string]interface{}{ 90 "databaseName": autorest.Encode("path", databaseName), 91 "resourceGroupName": autorest.Encode("path", resourceGroupName), 92 "scanId": autorest.Encode("path", scanID), 93 "serverName": autorest.Encode("path", serverName), 94 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 95 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 96 } 97 98 const APIVersion = "2017-10-01-preview" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 preparer := autorest.CreatePreparer( 104 autorest.AsPost(), 105 autorest.WithBaseURL(client.BaseURI), 106 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export", pathParameters), 107 autorest.WithQueryParameters(queryParameters)) 108 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 109} 110 111// ExportSender sends the Export request. The method will close the 112// http.Response Body if it receives an error. 113func (client DatabaseVulnerabilityAssessmentScansClient) ExportSender(req *http.Request) (*http.Response, error) { 114 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 115} 116 117// ExportResponder handles the response to the Export request. The method always 118// closes the http.Response Body. 119func (client DatabaseVulnerabilityAssessmentScansClient) ExportResponder(resp *http.Response) (result DatabaseVulnerabilityAssessmentScansExport, err error) { 120 err = autorest.Respond( 121 resp, 122 client.ByInspecting(), 123 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// Get gets a vulnerability assessment scan record of a database. 131// Parameters: 132// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 133// from the Azure Resource Manager API or the portal. 134// serverName - the name of the server. 135// databaseName - the name of the database. 136// scanID - the vulnerability assessment scan Id of the scan to retrieve. 137func (client DatabaseVulnerabilityAssessmentScansClient) Get(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (result VulnerabilityAssessmentScanRecord, err error) { 138 if tracing.IsEnabled() { 139 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.Get") 140 defer func() { 141 sc := -1 142 if result.Response.Response != nil { 143 sc = result.Response.Response.StatusCode 144 } 145 tracing.EndSpan(ctx, sc, err) 146 }() 147 } 148 req, err := client.GetPreparer(ctx, resourceGroupName, serverName, databaseName, scanID) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Get", nil, "Failure preparing request") 151 return 152 } 153 154 resp, err := client.GetSender(req) 155 if err != nil { 156 result.Response = autorest.Response{Response: resp} 157 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Get", resp, "Failure sending request") 158 return 159 } 160 161 result, err = client.GetResponder(resp) 162 if err != nil { 163 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Get", resp, "Failure responding to request") 164 } 165 166 return 167} 168 169// GetPreparer prepares the Get request. 170func (client DatabaseVulnerabilityAssessmentScansClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (*http.Request, error) { 171 pathParameters := map[string]interface{}{ 172 "databaseName": autorest.Encode("path", databaseName), 173 "resourceGroupName": autorest.Encode("path", resourceGroupName), 174 "scanId": autorest.Encode("path", scanID), 175 "serverName": autorest.Encode("path", serverName), 176 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 177 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 178 } 179 180 const APIVersion = "2017-10-01-preview" 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}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}", 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 DatabaseVulnerabilityAssessmentScansClient) 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 DatabaseVulnerabilityAssessmentScansClient) GetResponder(resp *http.Response) (result VulnerabilityAssessmentScanRecord, 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 212// InitiateScan executes a Vulnerability Assessment database scan. 213// Parameters: 214// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 215// from the Azure Resource Manager API or the portal. 216// serverName - the name of the server. 217// databaseName - the name of the database. 218// scanID - the vulnerability assessment scan Id of the scan to retrieve. 219func (client DatabaseVulnerabilityAssessmentScansClient) InitiateScan(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (result DatabaseVulnerabilityAssessmentScansInitiateScanFuture, err error) { 220 if tracing.IsEnabled() { 221 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.InitiateScan") 222 defer func() { 223 sc := -1 224 if result.Response() != nil { 225 sc = result.Response().StatusCode 226 } 227 tracing.EndSpan(ctx, sc, err) 228 }() 229 } 230 req, err := client.InitiateScanPreparer(ctx, resourceGroupName, serverName, databaseName, scanID) 231 if err != nil { 232 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "InitiateScan", nil, "Failure preparing request") 233 return 234 } 235 236 result, err = client.InitiateScanSender(req) 237 if err != nil { 238 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "InitiateScan", result.Response(), "Failure sending request") 239 return 240 } 241 242 return 243} 244 245// InitiateScanPreparer prepares the InitiateScan request. 246func (client DatabaseVulnerabilityAssessmentScansClient) InitiateScanPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (*http.Request, error) { 247 pathParameters := map[string]interface{}{ 248 "databaseName": autorest.Encode("path", databaseName), 249 "resourceGroupName": autorest.Encode("path", resourceGroupName), 250 "scanId": autorest.Encode("path", scanID), 251 "serverName": autorest.Encode("path", serverName), 252 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 253 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 254 } 255 256 const APIVersion = "2017-10-01-preview" 257 queryParameters := map[string]interface{}{ 258 "api-version": APIVersion, 259 } 260 261 preparer := autorest.CreatePreparer( 262 autorest.AsPost(), 263 autorest.WithBaseURL(client.BaseURI), 264 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan", pathParameters), 265 autorest.WithQueryParameters(queryParameters)) 266 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 267} 268 269// InitiateScanSender sends the InitiateScan request. The method will close the 270// http.Response Body if it receives an error. 271func (client DatabaseVulnerabilityAssessmentScansClient) InitiateScanSender(req *http.Request) (future DatabaseVulnerabilityAssessmentScansInitiateScanFuture, err error) { 272 var resp *http.Response 273 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 274 if err != nil { 275 return 276 } 277 future.Future, err = azure.NewFutureFromResponse(resp) 278 return 279} 280 281// InitiateScanResponder handles the response to the InitiateScan request. The method always 282// closes the http.Response Body. 283func (client DatabaseVulnerabilityAssessmentScansClient) InitiateScanResponder(resp *http.Response) (result autorest.Response, err error) { 284 err = autorest.Respond( 285 resp, 286 client.ByInspecting(), 287 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 288 autorest.ByClosing()) 289 result.Response = resp 290 return 291} 292 293// ListByDatabase lists the vulnerability assessment scans of a database. 294// Parameters: 295// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 296// from the Azure Resource Manager API or the portal. 297// serverName - the name of the server. 298// databaseName - the name of the database. 299func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result VulnerabilityAssessmentScanRecordListResultPage, err error) { 300 if tracing.IsEnabled() { 301 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.ListByDatabase") 302 defer func() { 303 sc := -1 304 if result.vasrlr.Response.Response != nil { 305 sc = result.vasrlr.Response.Response.StatusCode 306 } 307 tracing.EndSpan(ctx, sc, err) 308 }() 309 } 310 result.fn = client.listByDatabaseNextResults 311 req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName) 312 if err != nil { 313 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "ListByDatabase", nil, "Failure preparing request") 314 return 315 } 316 317 resp, err := client.ListByDatabaseSender(req) 318 if err != nil { 319 result.vasrlr.Response = autorest.Response{Response: resp} 320 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "ListByDatabase", resp, "Failure sending request") 321 return 322 } 323 324 result.vasrlr, err = client.ListByDatabaseResponder(resp) 325 if err != nil { 326 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "ListByDatabase", resp, "Failure responding to request") 327 } 328 329 return 330} 331 332// ListByDatabasePreparer prepares the ListByDatabase request. 333func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 334 pathParameters := map[string]interface{}{ 335 "databaseName": autorest.Encode("path", databaseName), 336 "resourceGroupName": autorest.Encode("path", resourceGroupName), 337 "serverName": autorest.Encode("path", serverName), 338 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 339 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 340 } 341 342 const APIVersion = "2017-10-01-preview" 343 queryParameters := map[string]interface{}{ 344 "api-version": APIVersion, 345 } 346 347 preparer := autorest.CreatePreparer( 348 autorest.AsGet(), 349 autorest.WithBaseURL(client.BaseURI), 350 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans", pathParameters), 351 autorest.WithQueryParameters(queryParameters)) 352 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 353} 354 355// ListByDatabaseSender sends the ListByDatabase request. The method will close the 356// http.Response Body if it receives an error. 357func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) { 358 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 359} 360 361// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always 362// closes the http.Response Body. 363func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabaseResponder(resp *http.Response) (result VulnerabilityAssessmentScanRecordListResult, err error) { 364 err = autorest.Respond( 365 resp, 366 client.ByInspecting(), 367 azure.WithErrorUnlessStatusCode(http.StatusOK), 368 autorest.ByUnmarshallingJSON(&result), 369 autorest.ByClosing()) 370 result.Response = autorest.Response{Response: resp} 371 return 372} 373 374// listByDatabaseNextResults retrieves the next set of results, if any. 375func (client DatabaseVulnerabilityAssessmentScansClient) listByDatabaseNextResults(ctx context.Context, lastResults VulnerabilityAssessmentScanRecordListResult) (result VulnerabilityAssessmentScanRecordListResult, err error) { 376 req, err := lastResults.vulnerabilityAssessmentScanRecordListResultPreparer(ctx) 377 if err != nil { 378 return result, autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "listByDatabaseNextResults", nil, "Failure preparing next results request") 379 } 380 if req == nil { 381 return 382 } 383 resp, err := client.ListByDatabaseSender(req) 384 if err != nil { 385 result.Response = autorest.Response{Response: resp} 386 return result, autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "listByDatabaseNextResults", resp, "Failure sending next results request") 387 } 388 result, err = client.ListByDatabaseResponder(resp) 389 if err != nil { 390 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "listByDatabaseNextResults", resp, "Failure responding to next results request") 391 } 392 return 393} 394 395// ListByDatabaseComplete enumerates all values, automatically crossing page boundaries as required. 396func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabaseComplete(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result VulnerabilityAssessmentScanRecordListResultIterator, err error) { 397 if tracing.IsEnabled() { 398 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.ListByDatabase") 399 defer func() { 400 sc := -1 401 if result.Response().Response.Response != nil { 402 sc = result.page.Response().Response.Response.StatusCode 403 } 404 tracing.EndSpan(ctx, sc, err) 405 }() 406 } 407 result.page, err = client.ListByDatabase(ctx, resourceGroupName, serverName, databaseName) 408 return 409} 410