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. 43func NewDatabaseVulnerabilityAssessmentScansClientWithBaseURI(baseURI string, subscriptionID string) DatabaseVulnerabilityAssessmentScansClient { 44 return DatabaseVulnerabilityAssessmentScansClient{NewWithBaseURI(baseURI, subscriptionID)} 45} 46 47// Export convert an existing scan result to a human readable format. If already exists nothing happens 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// databaseName - the name of the scanned database. 53// scanID - the vulnerability assessment scan Id. 54func (client DatabaseVulnerabilityAssessmentScansClient) Export(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (result DatabaseVulnerabilityAssessmentScansExport, err error) { 55 if tracing.IsEnabled() { 56 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.Export") 57 defer func() { 58 sc := -1 59 if result.Response.Response != nil { 60 sc = result.Response.Response.StatusCode 61 } 62 tracing.EndSpan(ctx, sc, err) 63 }() 64 } 65 req, err := client.ExportPreparer(ctx, resourceGroupName, serverName, databaseName, scanID) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Export", nil, "Failure preparing request") 68 return 69 } 70 71 resp, err := client.ExportSender(req) 72 if err != nil { 73 result.Response = autorest.Response{Response: resp} 74 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Export", resp, "Failure sending request") 75 return 76 } 77 78 result, err = client.ExportResponder(resp) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "Export", resp, "Failure responding to request") 81 } 82 83 return 84} 85 86// ExportPreparer prepares the Export request. 87func (client DatabaseVulnerabilityAssessmentScansClient) ExportPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "databaseName": autorest.Encode("path", databaseName), 90 "resourceGroupName": autorest.Encode("path", resourceGroupName), 91 "scanId": autorest.Encode("path", scanID), 92 "serverName": autorest.Encode("path", serverName), 93 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 94 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 95 } 96 97 const APIVersion = "2017-10-01-preview" 98 queryParameters := map[string]interface{}{ 99 "api-version": APIVersion, 100 } 101 102 preparer := autorest.CreatePreparer( 103 autorest.AsPost(), 104 autorest.WithBaseURL(client.BaseURI), 105 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/export", pathParameters), 106 autorest.WithQueryParameters(queryParameters)) 107 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 108} 109 110// ExportSender sends the Export request. The method will close the 111// http.Response Body if it receives an error. 112func (client DatabaseVulnerabilityAssessmentScansClient) ExportSender(req *http.Request) (*http.Response, error) { 113 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 114 return autorest.SendWithSender(client, req, sd...) 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 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 197 return autorest.SendWithSender(client, req, sd...) 198} 199 200// GetResponder handles the response to the Get request. The method always 201// closes the http.Response Body. 202func (client DatabaseVulnerabilityAssessmentScansClient) GetResponder(resp *http.Response) (result VulnerabilityAssessmentScanRecord, err error) { 203 err = autorest.Respond( 204 resp, 205 client.ByInspecting(), 206 azure.WithErrorUnlessStatusCode(http.StatusOK), 207 autorest.ByUnmarshallingJSON(&result), 208 autorest.ByClosing()) 209 result.Response = autorest.Response{Response: resp} 210 return 211} 212 213// InitiateScan executes a Vulnerability Assessment database scan. 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. 219// scanID - the vulnerability assessment scan Id of the scan to retrieve. 220func (client DatabaseVulnerabilityAssessmentScansClient) InitiateScan(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (result DatabaseVulnerabilityAssessmentScansInitiateScanFuture, err error) { 221 if tracing.IsEnabled() { 222 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.InitiateScan") 223 defer func() { 224 sc := -1 225 if result.Response() != nil { 226 sc = result.Response().StatusCode 227 } 228 tracing.EndSpan(ctx, sc, err) 229 }() 230 } 231 req, err := client.InitiateScanPreparer(ctx, resourceGroupName, serverName, databaseName, scanID) 232 if err != nil { 233 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "InitiateScan", nil, "Failure preparing request") 234 return 235 } 236 237 result, err = client.InitiateScanSender(req) 238 if err != nil { 239 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "InitiateScan", result.Response(), "Failure sending request") 240 return 241 } 242 243 return 244} 245 246// InitiateScanPreparer prepares the InitiateScan request. 247func (client DatabaseVulnerabilityAssessmentScansClient) InitiateScanPreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string, scanID string) (*http.Request, error) { 248 pathParameters := map[string]interface{}{ 249 "databaseName": autorest.Encode("path", databaseName), 250 "resourceGroupName": autorest.Encode("path", resourceGroupName), 251 "scanId": autorest.Encode("path", scanID), 252 "serverName": autorest.Encode("path", serverName), 253 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 254 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 255 } 256 257 const APIVersion = "2017-10-01-preview" 258 queryParameters := map[string]interface{}{ 259 "api-version": APIVersion, 260 } 261 262 preparer := autorest.CreatePreparer( 263 autorest.AsPost(), 264 autorest.WithBaseURL(client.BaseURI), 265 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans/{scanId}/initiateScan", pathParameters), 266 autorest.WithQueryParameters(queryParameters)) 267 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 268} 269 270// InitiateScanSender sends the InitiateScan request. The method will close the 271// http.Response Body if it receives an error. 272func (client DatabaseVulnerabilityAssessmentScansClient) InitiateScanSender(req *http.Request) (future DatabaseVulnerabilityAssessmentScansInitiateScanFuture, err error) { 273 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 274 var resp *http.Response 275 resp, err = autorest.SendWithSender(client, req, sd...) 276 if err != nil { 277 return 278 } 279 future.Future, err = azure.NewFutureFromResponse(resp) 280 return 281} 282 283// InitiateScanResponder handles the response to the InitiateScan request. The method always 284// closes the http.Response Body. 285func (client DatabaseVulnerabilityAssessmentScansClient) InitiateScanResponder(resp *http.Response) (result autorest.Response, err error) { 286 err = autorest.Respond( 287 resp, 288 client.ByInspecting(), 289 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 290 autorest.ByClosing()) 291 result.Response = resp 292 return 293} 294 295// ListByDatabase lists the vulnerability assessment scans of a database. 296// Parameters: 297// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value 298// from the Azure Resource Manager API or the portal. 299// serverName - the name of the server. 300// databaseName - the name of the database. 301func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabase(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result VulnerabilityAssessmentScanRecordListResultPage, err error) { 302 if tracing.IsEnabled() { 303 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.ListByDatabase") 304 defer func() { 305 sc := -1 306 if result.vasrlr.Response.Response != nil { 307 sc = result.vasrlr.Response.Response.StatusCode 308 } 309 tracing.EndSpan(ctx, sc, err) 310 }() 311 } 312 result.fn = client.listByDatabaseNextResults 313 req, err := client.ListByDatabasePreparer(ctx, resourceGroupName, serverName, databaseName) 314 if err != nil { 315 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "ListByDatabase", nil, "Failure preparing request") 316 return 317 } 318 319 resp, err := client.ListByDatabaseSender(req) 320 if err != nil { 321 result.vasrlr.Response = autorest.Response{Response: resp} 322 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "ListByDatabase", resp, "Failure sending request") 323 return 324 } 325 326 result.vasrlr, err = client.ListByDatabaseResponder(resp) 327 if err != nil { 328 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "ListByDatabase", resp, "Failure responding to request") 329 } 330 331 return 332} 333 334// ListByDatabasePreparer prepares the ListByDatabase request. 335func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabasePreparer(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (*http.Request, error) { 336 pathParameters := map[string]interface{}{ 337 "databaseName": autorest.Encode("path", databaseName), 338 "resourceGroupName": autorest.Encode("path", resourceGroupName), 339 "serverName": autorest.Encode("path", serverName), 340 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 341 "vulnerabilityAssessmentName": autorest.Encode("path", "default"), 342 } 343 344 const APIVersion = "2017-10-01-preview" 345 queryParameters := map[string]interface{}{ 346 "api-version": APIVersion, 347 } 348 349 preparer := autorest.CreatePreparer( 350 autorest.AsGet(), 351 autorest.WithBaseURL(client.BaseURI), 352 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments/{vulnerabilityAssessmentName}/scans", pathParameters), 353 autorest.WithQueryParameters(queryParameters)) 354 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 355} 356 357// ListByDatabaseSender sends the ListByDatabase request. The method will close the 358// http.Response Body if it receives an error. 359func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabaseSender(req *http.Request) (*http.Response, error) { 360 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 361 return autorest.SendWithSender(client, req, sd...) 362} 363 364// ListByDatabaseResponder handles the response to the ListByDatabase request. The method always 365// closes the http.Response Body. 366func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabaseResponder(resp *http.Response) (result VulnerabilityAssessmentScanRecordListResult, err error) { 367 err = autorest.Respond( 368 resp, 369 client.ByInspecting(), 370 azure.WithErrorUnlessStatusCode(http.StatusOK), 371 autorest.ByUnmarshallingJSON(&result), 372 autorest.ByClosing()) 373 result.Response = autorest.Response{Response: resp} 374 return 375} 376 377// listByDatabaseNextResults retrieves the next set of results, if any. 378func (client DatabaseVulnerabilityAssessmentScansClient) listByDatabaseNextResults(ctx context.Context, lastResults VulnerabilityAssessmentScanRecordListResult) (result VulnerabilityAssessmentScanRecordListResult, err error) { 379 req, err := lastResults.vulnerabilityAssessmentScanRecordListResultPreparer(ctx) 380 if err != nil { 381 return result, autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "listByDatabaseNextResults", nil, "Failure preparing next results request") 382 } 383 if req == nil { 384 return 385 } 386 resp, err := client.ListByDatabaseSender(req) 387 if err != nil { 388 result.Response = autorest.Response{Response: resp} 389 return result, autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "listByDatabaseNextResults", resp, "Failure sending next results request") 390 } 391 result, err = client.ListByDatabaseResponder(resp) 392 if err != nil { 393 err = autorest.NewErrorWithError(err, "sql.DatabaseVulnerabilityAssessmentScansClient", "listByDatabaseNextResults", resp, "Failure responding to next results request") 394 } 395 return 396} 397 398// ListByDatabaseComplete enumerates all values, automatically crossing page boundaries as required. 399func (client DatabaseVulnerabilityAssessmentScansClient) ListByDatabaseComplete(ctx context.Context, resourceGroupName string, serverName string, databaseName string) (result VulnerabilityAssessmentScanRecordListResultIterator, err error) { 400 if tracing.IsEnabled() { 401 ctx = tracing.StartSpan(ctx, fqdn+"/DatabaseVulnerabilityAssessmentScansClient.ListByDatabase") 402 defer func() { 403 sc := -1 404 if result.Response().Response.Response != nil { 405 sc = result.page.Response().Response.Response.StatusCode 406 } 407 tracing.EndSpan(ctx, sc, err) 408 }() 409 } 410 result.page, err = client.ListByDatabase(ctx, resourceGroupName, serverName, databaseName) 411 return 412} 413