diff --git a/lib/services/sqlManagement2/lib/models/databaseVulnerabilityAssessment.js b/lib/services/sqlManagement2/lib/models/databaseVulnerabilityAssessment.js index 34fd870857..9ec9b0bde6 100644 --- a/lib/services/sqlManagement2/lib/models/databaseVulnerabilityAssessment.js +++ b/lib/services/sqlManagement2/lib/models/databaseVulnerabilityAssessment.js @@ -20,16 +20,18 @@ const models = require('./index'); class DatabaseVulnerabilityAssessment extends models['ProxyResource'] { /** * Create a DatabaseVulnerabilityAssessment. - * @member {string} storageContainerPath A blob storage container path to + * @member {string} [storageContainerPath] A blob storage container path to * hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if + * server level vulnerability assessment policy doesn't set * @member {string} [storageContainerSasKey] A shared access signature (SAS * Key) that has write access to the blob container specified in * 'storageContainerPath' parameter. If 'storageAccountAccessKey' isn't * specified, StorageContainerSasKey is required. * @member {string} [storageAccountAccessKey] Specifies the identifier key of - * the vulnerability assessment storage account. If 'StorageContainerSasKey' - * isn't specified, storageAccountAccessKey is required. + * the storage account for vulnerability assessment scan results. If + * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is + * required. * @member {object} [recurringScans] The recurring scans settings * @member {boolean} [recurringScans.isEnabled] Recurring scans state. * @member {boolean} [recurringScans.emailSubscriptionAdmins] Specifies that @@ -81,7 +83,7 @@ class DatabaseVulnerabilityAssessment extends models['ProxyResource'] { } }, storageContainerPath: { - required: true, + required: false, serializedName: 'properties.storageContainerPath', type: { name: 'String' diff --git a/lib/services/sqlManagement2/lib/models/databaseVulnerabilityAssessmentListResult.js b/lib/services/sqlManagement2/lib/models/databaseVulnerabilityAssessmentListResult.js new file mode 100644 index 0000000000..9ecd67425f --- /dev/null +++ b/lib/services/sqlManagement2/lib/models/databaseVulnerabilityAssessmentListResult.js @@ -0,0 +1,69 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +/** + * A list of the database's vulnerability assessments. + */ +class DatabaseVulnerabilityAssessmentListResult extends Array { + /** + * Create a DatabaseVulnerabilityAssessmentListResult. + * @member {string} [nextLink] Link to retrieve next page of results. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of DatabaseVulnerabilityAssessmentListResult + * + * @returns {object} metadata of DatabaseVulnerabilityAssessmentListResult + * + */ + mapper() { + return { + required: false, + serializedName: 'DatabaseVulnerabilityAssessmentListResult', + type: { + name: 'Composite', + className: 'DatabaseVulnerabilityAssessmentListResult', + modelProperties: { + value: { + required: false, + readOnly: true, + serializedName: '', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'DatabaseVulnerabilityAssessmentElementType', + type: { + name: 'Composite', + className: 'DatabaseVulnerabilityAssessment' + } + } + } + }, + nextLink: { + required: false, + readOnly: true, + serializedName: 'nextLink', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = DatabaseVulnerabilityAssessmentListResult; diff --git a/lib/services/sqlManagement2/lib/models/index.d.ts b/lib/services/sqlManagement2/lib/models/index.d.ts index 412213bcbd..f39672a466 100644 --- a/lib/services/sqlManagement2/lib/models/index.d.ts +++ b/lib/services/sqlManagement2/lib/models/index.d.ts @@ -2419,15 +2419,18 @@ export interface VulnerabilityAssessmentRecurringScansProperties { * @constructor * A database vulnerability assessment. * - * @member {string} storageContainerPath A blob storage container path to hold - * the scan results (e.g. https://myStorage.blob.core.windows.net/VaScans/). + * @member {string} [storageContainerPath] A blob storage container path to + * hold the scan results (e.g. + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * @member {string} [storageContainerSasKey] A shared access signature (SAS * Key) that has write access to the blob container specified in * 'storageContainerPath' parameter. If 'storageAccountAccessKey' isn't * specified, StorageContainerSasKey is required. * @member {string} [storageAccountAccessKey] Specifies the identifier key of - * the vulnerability assessment storage account. If 'StorageContainerSasKey' - * isn't specified, storageAccountAccessKey is required. + * the storage account for vulnerability assessment scan results. If + * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is + * required. * @member {object} [recurringScans] The recurring scans settings * @member {boolean} [recurringScans.isEnabled] Recurring scans state. * @member {boolean} [recurringScans.emailSubscriptionAdmins] Specifies that @@ -2437,7 +2440,7 @@ export interface VulnerabilityAssessmentRecurringScansProperties { * addresses to which the scan notification is sent. */ export interface DatabaseVulnerabilityAssessment extends ProxyResource { - storageContainerPath: string; + storageContainerPath?: string; storageContainerSasKey?: string; storageAccountAccessKey?: string; recurringScans?: VulnerabilityAssessmentRecurringScansProperties; @@ -4674,6 +4677,18 @@ export interface VirtualNetworkRuleListResult extends Array readonly nextLink?: string; } +/** + * @class + * Initializes a new instance of the DatabaseVulnerabilityAssessmentListResult class. + * @constructor + * A list of the database's vulnerability assessments. + * + * @member {string} [nextLink] Link to retrieve next page of results. + */ +export interface DatabaseVulnerabilityAssessmentListResult extends Array { + readonly nextLink?: string; +} + /** * @class * Initializes a new instance of the JobAgentListResult class. diff --git a/lib/services/sqlManagement2/lib/models/index.js b/lib/services/sqlManagement2/lib/models/index.js index cad04db922..ab078409ef 100644 --- a/lib/services/sqlManagement2/lib/models/index.js +++ b/lib/services/sqlManagement2/lib/models/index.js @@ -195,6 +195,7 @@ exports.SyncGroupListResult = require('./syncGroupListResult'); exports.SyncMemberListResult = require('./syncMemberListResult'); exports.SubscriptionUsageListResult = require('./subscriptionUsageListResult'); exports.VirtualNetworkRuleListResult = require('./virtualNetworkRuleListResult'); +exports.DatabaseVulnerabilityAssessmentListResult = require('./databaseVulnerabilityAssessmentListResult'); exports.JobAgentListResult = require('./jobAgentListResult'); exports.JobCredentialListResult = require('./jobCredentialListResult'); exports.JobExecutionListResult = require('./jobExecutionListResult'); diff --git a/lib/services/sqlManagement2/lib/operations/databaseVulnerabilityAssessments.js b/lib/services/sqlManagement2/lib/operations/databaseVulnerabilityAssessments.js index 1bbb114efc..890f1ae5fb 100644 --- a/lib/services/sqlManagement2/lib/operations/databaseVulnerabilityAssessments.js +++ b/lib/services/sqlManagement2/lib/operations/databaseVulnerabilityAssessments.js @@ -183,9 +183,10 @@ function _get(resourceGroupName, serverName, databaseName, options, callback) { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -193,9 +194,9 @@ function _get(resourceGroupName, serverName, databaseName, options, callback) { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -522,6 +523,287 @@ function _deleteMethod(resourceGroupName, serverName, databaseName, options, cal }); } +/** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} serverName The name of the server. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment policies are defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _listByDatabase(resourceGroupName, serverName, databaseName, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + let apiVersion = '2017-03-01-preview'; + // Validate + try { + if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') { + throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.'); + } + if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') { + throw new Error('serverName cannot be null or undefined and it must be of type string.'); + } + if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') { + throw new Error('databaseName cannot be null or undefined and it must be of type string.'); + } + if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') { + throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/vulnerabilityAssessments'; + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName)); + requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName)); + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['DatabaseVulnerabilityAssessmentListResult']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _listByDatabaseNext(nextPageLink, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { + throw new Error('nextPageLink cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let requestUrl = '{nextLink}'; + requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['DatabaseVulnerabilityAssessmentListResult']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + /** Class representing a DatabaseVulnerabilityAssessments. */ class DatabaseVulnerabilityAssessments { /** @@ -533,6 +815,8 @@ class DatabaseVulnerabilityAssessments { this._get = _get; this._createOrUpdate = _createOrUpdate; this._deleteMethod = _deleteMethod; + this._listByDatabase = _listByDatabase; + this._listByDatabaseNext = _listByDatabaseNext; } /** @@ -646,9 +930,10 @@ class DatabaseVulnerabilityAssessments { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -656,9 +941,9 @@ class DatabaseVulnerabilityAssessments { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -711,9 +996,10 @@ class DatabaseVulnerabilityAssessments { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -721,9 +1007,9 @@ class DatabaseVulnerabilityAssessments { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -880,6 +1166,188 @@ class DatabaseVulnerabilityAssessments { } } + /** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} serverName The name of the server. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment policies are defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + listByDatabaseWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listByDatabase(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} serverName The name of the server. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment policies are defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {DatabaseVulnerabilityAssessmentListResult} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + listByDatabase(resourceGroupName, serverName, databaseName, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._listByDatabase(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listByDatabase(resourceGroupName, serverName, databaseName, options, optionalCallback); + } + } + + /** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + listByDatabaseNextWithHttpOperationResponse(nextPageLink, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listByDatabaseNext(nextPageLink, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {DatabaseVulnerabilityAssessmentListResult} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + listByDatabaseNext(nextPageLink, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._listByDatabaseNext(nextPageLink, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listByDatabaseNext(nextPageLink, options, optionalCallback); + } + } + } module.exports = DatabaseVulnerabilityAssessments; diff --git a/lib/services/sqlManagement2/lib/operations/index.d.ts b/lib/services/sqlManagement2/lib/operations/index.d.ts index 752cc9a1ff..6b48777e12 100644 --- a/lib/services/sqlManagement2/lib/operations/index.d.ts +++ b/lib/services/sqlManagement2/lib/operations/index.d.ts @@ -18882,9 +18882,10 @@ export interface DatabaseVulnerabilityAssessments { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -18892,9 +18893,9 @@ export interface DatabaseVulnerabilityAssessments { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -18935,9 +18936,10 @@ export interface DatabaseVulnerabilityAssessments { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -18945,9 +18947,9 @@ export interface DatabaseVulnerabilityAssessments { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -19060,6 +19062,134 @@ export interface DatabaseVulnerabilityAssessments { deleteMethod(resourceGroupName: string, serverName: string, databaseName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; deleteMethod(resourceGroupName: string, serverName: string, databaseName: string, callback: ServiceCallback): void; deleteMethod(resourceGroupName: string, serverName: string, databaseName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} serverName The name of the server. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment policies are defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + listByDatabaseWithHttpOperationResponse(resourceGroupName: string, serverName: string, databaseName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} serverName The name of the server. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment policies are defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {DatabaseVulnerabilityAssessmentListResult} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {DatabaseVulnerabilityAssessmentListResult} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + listByDatabase(resourceGroupName: string, serverName: string, databaseName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + listByDatabase(resourceGroupName: string, serverName: string, databaseName: string, callback: ServiceCallback): void; + listByDatabase(resourceGroupName: string, serverName: string, databaseName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + listByDatabaseNextWithHttpOperationResponse(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Lists the vulnerability assessment policies associated with a database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {DatabaseVulnerabilityAssessmentListResult} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {DatabaseVulnerabilityAssessmentListResult} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + listByDatabaseNext(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + listByDatabaseNext(nextPageLink: string, callback: ServiceCallback): void; + listByDatabaseNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } /** @@ -28447,9 +28577,10 @@ export interface ManagedDatabaseVulnerabilityAssessments { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -28457,9 +28588,9 @@ export interface ManagedDatabaseVulnerabilityAssessments { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -28500,9 +28631,10 @@ export interface ManagedDatabaseVulnerabilityAssessments { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -28510,9 +28642,9 @@ export interface ManagedDatabaseVulnerabilityAssessments { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -28625,6 +28757,134 @@ export interface ManagedDatabaseVulnerabilityAssessments { deleteMethod(resourceGroupName: string, managedInstanceName: string, databaseName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; deleteMethod(resourceGroupName: string, managedInstanceName: string, databaseName: string, callback: ServiceCallback): void; deleteMethod(resourceGroupName: string, managedInstanceName: string, databaseName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} managedInstanceName The name of the managed instance. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment is defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + listByDatabaseWithHttpOperationResponse(resourceGroupName: string, managedInstanceName: string, databaseName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} managedInstanceName The name of the managed instance. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment is defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {DatabaseVulnerabilityAssessmentListResult} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {DatabaseVulnerabilityAssessmentListResult} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + listByDatabase(resourceGroupName: string, managedInstanceName: string, databaseName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + listByDatabase(resourceGroupName: string, managedInstanceName: string, databaseName: string, callback: ServiceCallback): void; + listByDatabase(resourceGroupName: string, managedInstanceName: string, databaseName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + */ + listByDatabaseNextWithHttpOperationResponse(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {ServiceCallback} [optionalCallback] - The optional callback. + * + * @returns {ServiceCallback|Promise} If a callback was passed as the last + * parameter then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned. + * + * @resolve {DatabaseVulnerabilityAssessmentListResult} - The deserialized result object. + * + * @reject {Error|ServiceError} - The error object. + * + * {ServiceCallback} optionalCallback(err, result, request, response) + * + * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. + * + * {DatabaseVulnerabilityAssessmentListResult} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {WebResource} [request] - The HTTP Request object if an error did not occur. + * + * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. + */ + listByDatabaseNext(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + listByDatabaseNext(nextPageLink: string, callback: ServiceCallback): void; + listByDatabaseNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } /** diff --git a/lib/services/sqlManagement2/lib/operations/managedDatabaseVulnerabilityAssessments.js b/lib/services/sqlManagement2/lib/operations/managedDatabaseVulnerabilityAssessments.js index 6c70a5df17..cd3e275962 100644 --- a/lib/services/sqlManagement2/lib/operations/managedDatabaseVulnerabilityAssessments.js +++ b/lib/services/sqlManagement2/lib/operations/managedDatabaseVulnerabilityAssessments.js @@ -183,9 +183,10 @@ function _get(resourceGroupName, managedInstanceName, databaseName, options, cal * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -193,9 +194,9 @@ function _get(resourceGroupName, managedInstanceName, databaseName, options, cal * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -522,6 +523,287 @@ function _deleteMethod(resourceGroupName, managedInstanceName, databaseName, opt }); } +/** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} managedInstanceName The name of the managed instance. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment is defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _listByDatabase(resourceGroupName, managedInstanceName, databaseName, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + let apiVersion = '2017-10-01-preview'; + // Validate + try { + if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') { + throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.'); + } + if (managedInstanceName === null || managedInstanceName === undefined || typeof managedInstanceName.valueOf() !== 'string') { + throw new Error('managedInstanceName cannot be null or undefined and it must be of type string.'); + } + if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') { + throw new Error('databaseName cannot be null or undefined and it must be of type string.'); + } + if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') { + throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/vulnerabilityAssessments'; + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{managedInstanceName}', encodeURIComponent(managedInstanceName)); + requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName)); + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['DatabaseVulnerabilityAssessmentListResult']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + +/** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ +function _listByDatabaseNext(nextPageLink, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { + throw new Error('nextPageLink cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let requestUrl = '{nextLink}'; + requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['DatabaseVulnerabilityAssessmentListResult']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError.request = msRest.stripRequest(httpRequest); + deserializationError.response = msRest.stripResponse(response); + return callback(deserializationError); + } + } + + return callback(null, result, httpRequest, response); + }); +} + /** Class representing a ManagedDatabaseVulnerabilityAssessments. */ class ManagedDatabaseVulnerabilityAssessments { /** @@ -533,6 +815,8 @@ class ManagedDatabaseVulnerabilityAssessments { this._get = _get; this._createOrUpdate = _createOrUpdate; this._deleteMethod = _deleteMethod; + this._listByDatabase = _listByDatabase; + this._listByDatabaseNext = _listByDatabaseNext; } /** @@ -646,9 +930,10 @@ class ManagedDatabaseVulnerabilityAssessments { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -656,9 +941,9 @@ class ManagedDatabaseVulnerabilityAssessments { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -711,9 +996,10 @@ class ManagedDatabaseVulnerabilityAssessments { * * @param {object} parameters The requested resource. * - * @param {string} parameters.storageContainerPath A blob storage container + * @param {string} [parameters.storageContainerPath] A blob storage container * path to hold the scan results (e.g. - * https://myStorage.blob.core.windows.net/VaScans/). + * https://myStorage.blob.core.windows.net/VaScans/). It is required if server + * level vulnerability assessment policy doesn't set * * @param {string} [parameters.storageContainerSasKey] A shared access * signature (SAS Key) that has write access to the blob container specified in @@ -721,9 +1007,9 @@ class ManagedDatabaseVulnerabilityAssessments { * specified, StorageContainerSasKey is required. * * @param {string} [parameters.storageAccountAccessKey] Specifies the - * identifier key of the vulnerability assessment storage account. If - * 'StorageContainerSasKey' isn't specified, storageAccountAccessKey is - * required. + * identifier key of the storage account for vulnerability assessment scan + * results. If 'StorageContainerSasKey' isn't specified, + * storageAccountAccessKey is required. * * @param {object} [parameters.recurringScans] The recurring scans settings * @@ -880,6 +1166,188 @@ class ManagedDatabaseVulnerabilityAssessments { } } + /** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} managedInstanceName The name of the managed instance. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment is defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + listByDatabaseWithHttpOperationResponse(resourceGroupName, managedInstanceName, databaseName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listByDatabase(resourceGroupName, managedInstanceName, databaseName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} resourceGroupName The name of the resource group that + * contains the resource. You can obtain this value from the Azure Resource + * Manager API or the portal. + * + * @param {string} managedInstanceName The name of the managed instance. + * + * @param {string} databaseName The name of the database for which the + * vulnerability assessment is defined. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {DatabaseVulnerabilityAssessmentListResult} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + listByDatabase(resourceGroupName, managedInstanceName, databaseName, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._listByDatabase(resourceGroupName, managedInstanceName, databaseName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listByDatabase(resourceGroupName, managedInstanceName, databaseName, options, optionalCallback); + } + } + + /** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + listByDatabaseNextWithHttpOperationResponse(nextPageLink, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listByDatabaseNext(nextPageLink, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists the vulnerability assessments of a managed database. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} [optionalCallback] - The optional callback. + * + * @returns {function|Promise} If a callback was passed as the last parameter + * then it returns the callback else returns a Promise. + * + * {Promise} A promise is returned + * + * @resolve {DatabaseVulnerabilityAssessmentListResult} - The deserialized result object. + * + * @reject {Error} - The error object. + * + * {function} optionalCallback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link DatabaseVulnerabilityAssessmentListResult} + * for more information. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + listByDatabaseNext(nextPageLink, options, optionalCallback) { + let client = this.client; + let self = this; + if (!optionalCallback && typeof options === 'function') { + optionalCallback = options; + options = null; + } + if (!optionalCallback) { + return new Promise((resolve, reject) => { + self._listByDatabaseNext(nextPageLink, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listByDatabaseNext(nextPageLink, options, optionalCallback); + } + } + } module.exports = ManagedDatabaseVulnerabilityAssessments; diff --git a/lib/services/sqlManagement2/package.json b/lib/services/sqlManagement2/package.json index acebc7d4e2..676b9ea2b1 100644 --- a/lib/services/sqlManagement2/package.json +++ b/lib/services/sqlManagement2/package.json @@ -2,7 +2,7 @@ "name": "azure-arm-sql", "author": "Microsoft Corporation", "description": "SqlManagementClient Library with typescript type definitions for node", - "version": "5.2.0", + "version": "5.3.0", "dependencies": { "ms-rest": "^2.3.3", "ms-rest-azure": "^2.5.5"