diff --git a/lib/services/cosmosdbManagement/lib/models/errorResponse.js b/lib/services/cosmosdbManagement/lib/models/errorResponse.js new file mode 100644 index 0000000000..32e994231a --- /dev/null +++ b/lib/services/cosmosdbManagement/lib/models/errorResponse.js @@ -0,0 +1,61 @@ +/* + * 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'; + +/** + * Error Response. + * + */ +class ErrorResponse { + /** + * Create a ErrorResponse. + * @member {string} [code] Error code. + * @member {string} [message] Error message indicating why the operation + * failed. + */ + constructor() { + } + + /** + * Defines the metadata of ErrorResponse + * + * @returns {object} metadata of ErrorResponse + * + */ + mapper() { + return { + required: false, + serializedName: 'ErrorResponse', + type: { + name: 'Composite', + className: 'ErrorResponse', + modelProperties: { + code: { + required: false, + serializedName: 'code', + type: { + name: 'String' + } + }, + message: { + required: false, + serializedName: 'message', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = ErrorResponse; diff --git a/lib/services/cosmosdbManagement/lib/models/index.d.ts b/lib/services/cosmosdbManagement/lib/models/index.d.ts index e9a69fa5b6..e03937ab72 100644 --- a/lib/services/cosmosdbManagement/lib/models/index.d.ts +++ b/lib/services/cosmosdbManagement/lib/models/index.d.ts @@ -204,6 +204,21 @@ export interface DatabaseAccount extends Resource { virtualNetworkRules?: VirtualNetworkRule[]; } +/** + * @class + * Initializes a new instance of the ErrorResponse class. + * @constructor + * Error Response. + * + * @member {string} [code] Error code. + * @member {string} [message] Error message indicating why the operation + * failed. + */ +export interface ErrorResponse { + code?: string; + message?: string; +} + /** * @class * Initializes a new instance of the FailoverPolicies class. @@ -216,6 +231,19 @@ export interface FailoverPolicies { failoverPolicies: FailoverPolicy[]; } +/** + * @class + * Initializes a new instance of the RegionForOnlineOffline class. + * @constructor + * Cosmos DB region to online or offline. + * + * @member {string} region Cosmos DB region, with spaces between words and each + * word capitalized. + */ +export interface RegionForOnlineOffline { + region: string; +} + /** * @class * Initializes a new instance of the DatabaseAccountCreateUpdateParameters class. diff --git a/lib/services/cosmosdbManagement/lib/models/index.js b/lib/services/cosmosdbManagement/lib/models/index.js index 3436075692..5cd558594d 100644 --- a/lib/services/cosmosdbManagement/lib/models/index.js +++ b/lib/services/cosmosdbManagement/lib/models/index.js @@ -25,7 +25,9 @@ exports.FailoverPolicy = require('./failoverPolicy'); exports.VirtualNetworkRule = require('./virtualNetworkRule'); exports.Resource = require('./resource'); exports.DatabaseAccount = require('./databaseAccount'); +exports.ErrorResponse = require('./errorResponse'); exports.FailoverPolicies = require('./failoverPolicies'); +exports.RegionForOnlineOffline = require('./regionForOnlineOffline'); exports.DatabaseAccountCreateUpdateParameters = require('./databaseAccountCreateUpdateParameters'); exports.DatabaseAccountPatchParameters = require('./databaseAccountPatchParameters'); exports.DatabaseAccountListReadOnlyKeysResult = require('./databaseAccountListReadOnlyKeysResult'); diff --git a/lib/services/cosmosdbManagement/lib/models/regionForOnlineOffline.js b/lib/services/cosmosdbManagement/lib/models/regionForOnlineOffline.js new file mode 100644 index 0000000000..fc1055a47e --- /dev/null +++ b/lib/services/cosmosdbManagement/lib/models/regionForOnlineOffline.js @@ -0,0 +1,53 @@ +/* + * 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'; + +/** + * Cosmos DB region to online or offline. + * + */ +class RegionForOnlineOffline { + /** + * Create a RegionForOnlineOffline. + * @member {string} region Cosmos DB region, with spaces between words and + * each word capitalized. + */ + constructor() { + } + + /** + * Defines the metadata of RegionForOnlineOffline + * + * @returns {object} metadata of RegionForOnlineOffline + * + */ + mapper() { + return { + required: false, + serializedName: 'RegionForOnlineOffline', + type: { + name: 'Composite', + className: 'RegionForOnlineOffline', + modelProperties: { + region: { + required: true, + serializedName: 'region', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = RegionForOnlineOffline; diff --git a/lib/services/cosmosdbManagement/lib/operations/databaseAccounts.js b/lib/services/cosmosdbManagement/lib/operations/databaseAccounts.js index d1f84412e5..60907651e9 100644 --- a/lib/services/cosmosdbManagement/lib/operations/databaseAccounts.js +++ b/lib/services/cosmosdbManagement/lib/operations/databaseAccounts.js @@ -1172,6 +1172,146 @@ function _listConnectionStrings(resourceGroupName, accountName, options, callbac }); } + +/** + * Offline the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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 _offlineRegion(resourceGroupName, accountName, regionParameterForOffline, 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.'); + } + + // Send request + this.beginOfflineRegion(resourceGroupName, accountName, regionParameterForOffline, options, (err, parsedResult, httpRequest, response) => { + if (err) return callback(err); + + let initialResult = new msRest.HttpOperationResponse(); + initialResult.request = httpRequest; + initialResult.response = response; + initialResult.body = response.body; + client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => { + if (err) return callback(err); + + // Create Result + let result = null; + + httpRequest = pollingResult.request; + response = pollingResult.response; + let responseBody = pollingResult.body; + if (responseBody === '') responseBody = null; + + // Deserialize Response + + return callback(null, result, httpRequest, response); + }); + }); +} + + +/** + * Online the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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 _onlineRegion(resourceGroupName, accountName, regionParameterForOnline, 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.'); + } + + // Send request + this.beginOnlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, (err, parsedResult, httpRequest, response) => { + if (err) return callback(err); + + let initialResult = new msRest.HttpOperationResponse(); + initialResult.request = httpRequest; + initialResult.response = response; + initialResult.body = response.body; + client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => { + if (err) return callback(err); + + // Create Result + let result = null; + + httpRequest = pollingResult.request; + response = pollingResult.response; + let responseBody = pollingResult.body; + if (responseBody === '') responseBody = null; + + // Deserialize Response + + return callback(null, result, httpRequest, response); + }); + }); +} + /** * Lists the read-only access keys for the specified Azure Cosmos DB database * account. @@ -2844,18 +2984,18 @@ function _beginFailoverPriorityChange(resourceGroupName, accountName, failoverPa } /** - * Regenerates an access key for the specified Azure Cosmos DB database + * Offline the specified region for the specified Azure Cosmos DB database * account. * * @param {string} resourceGroupName Name of an Azure resource group. * * @param {string} accountName Cosmos DB database account name. * - * @param {object} keyToRegenerate The name of the key to regenerate. + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. * - * @param {string} keyToRegenerate.keyKind The access key to regenerate. - * Possible values include: 'primary', 'secondary', 'primaryReadonly', - * 'secondaryReadonly' + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. * * @param {object} [options] Optional Parameters. * @@ -2874,7 +3014,7 @@ function _beginFailoverPriorityChange(resourceGroupName, accountName, failoverPa * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _beginRegenerateKey(resourceGroupName, accountName, keyToRegenerate, options, callback) { +function _beginOfflineRegion(resourceGroupName, accountName, regionParameterForOffline, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -2922,8 +3062,8 @@ function _beginRegenerateKey(resourceGroupName, accountName, keyToRegenerate, op if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') { throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.'); } - if (keyToRegenerate === null || keyToRegenerate === undefined) { - throw new Error('keyToRegenerate cannot be null or undefined.'); + if (regionParameterForOffline === null || regionParameterForOffline === undefined) { + throw new Error('regionParameterForOffline cannot be null or undefined.'); } 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.'); @@ -2934,7 +3074,7 @@ function _beginRegenerateKey(resourceGroupName, accountName, keyToRegenerate, op // Construct URL let baseUrl = this.client.baseUri; - let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/regenerateKey'; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/offlineRegion'; requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName)); @@ -2968,14 +3108,14 @@ function _beginRegenerateKey(resourceGroupName, accountName, keyToRegenerate, op let requestContent = null; let requestModel = null; try { - if (keyToRegenerate !== null && keyToRegenerate !== undefined) { - let requestModelMapper = new client.models['DatabaseAccountRegenerateKeyParameters']().mapper(); - requestModel = client.serialize(requestModelMapper, keyToRegenerate, 'keyToRegenerate'); + if (regionParameterForOffline !== null && regionParameterForOffline !== undefined) { + let requestModelMapper = new client.models['RegionForOnlineOffline']().mapper(); + requestModel = client.serialize(requestModelMapper, regionParameterForOffline, 'regionParameterForOffline'); requestContent = JSON.stringify(requestModel); } } catch (error) { let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + - `payload - ${JSON.stringify(keyToRegenerate, null, 2)}.`); + `payload - ${JSON.stringify(regionParameterForOffline, null, 2)}.`); return callback(serializationError); } httpRequest.body = requestContent; @@ -2995,12 +3135,13 @@ function _beginRegenerateKey(resourceGroupName, accountName, keyToRegenerate, op 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; + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; } if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { - let resultMapper = new client.models['CloudError']().mapper(); + let resultMapper = new client.models['ErrorResponse']().mapper(); error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); } } catch (defaultError) { @@ -3018,86 +3159,441 @@ function _beginRegenerateKey(resourceGroupName, accountName, keyToRegenerate, op }); } -/** Class representing a DatabaseAccounts. */ -class DatabaseAccounts { - /** - * Create a DatabaseAccounts. - * @param {CosmosDBManagementClient} client Reference to the service client. - */ - constructor(client) { - this.client = client; - this._get = _get; - this._patch = _patch; - this._createOrUpdate = _createOrUpdate; - this._deleteMethod = _deleteMethod; - this._failoverPriorityChange = _failoverPriorityChange; - this._list = _list; - this._listByResourceGroup = _listByResourceGroup; - this._listKeys = _listKeys; - this._listConnectionStrings = _listConnectionStrings; - this._listReadOnlyKeys = _listReadOnlyKeys; - this._regenerateKey = _regenerateKey; - this._checkNameExists = _checkNameExists; - this._listMetrics = _listMetrics; - this._listUsages = _listUsages; - this._listMetricDefinitions = _listMetricDefinitions; - this._beginPatch = _beginPatch; - this._beginCreateOrUpdate = _beginCreateOrUpdate; - this._beginDeleteMethod = _beginDeleteMethod; - this._beginFailoverPriorityChange = _beginFailoverPriorityChange; - this._beginRegenerateKey = _beginRegenerateKey; +/** + * Online the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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 _beginOnlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; } - - /** - * Retrieves the properties of an existing Azure Cosmos DB database account. - * - * @param {string} resourceGroupName Name of an Azure resource group. - * - * @param {string} accountName Cosmos DB database account name. - * - * @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. - */ - getWithHttpOperationResponse(resourceGroupName, accountName, options) { - let client = this.client; - let self = this; - return new Promise((resolve, reject) => { - self._get(resourceGroupName, accountName, options, (err, result, request, response) => { - let httpOperationResponse = new msRest.HttpOperationResponse(request, response); - httpOperationResponse.body = result; - if (err) { reject(err); } - else { resolve(httpOperationResponse); } - return; - }); - }); + if (!callback) { + throw new Error('callback cannot be null.'); } - - /** - * Retrieves the properties of an existing Azure Cosmos DB database account. - * - * @param {string} resourceGroupName Name of an Azure resource group. - * - * @param {string} accountName Cosmos DB database account name. - * - * @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 + // Validate + try { + 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 (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 (resourceGroupName !== null && resourceGroupName !== undefined) { + if (resourceGroupName.length > 90) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90'); + } + if (resourceGroupName.length < 1) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1'); + } + if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/'); + } + } + if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') { + throw new Error('accountName cannot be null or undefined and it must be of type string.'); + } + if (accountName !== null && accountName !== undefined) { + if (accountName.length > 50) + { + throw new Error('"accountName" should satisfy the constraint - "MaxLength": 50'); + } + if (accountName.length < 3) + { + throw new Error('"accountName" should satisfy the constraint - "MinLength": 3'); + } + } + if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') { + throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.'); + } + if (regionParameterForOnline === null || regionParameterForOnline === undefined) { + throw new Error('regionParameterForOnline cannot be null or undefined.'); + } + 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.DocumentDB/databaseAccounts/{accountName}/onlineRegion'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + 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]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (regionParameterForOnline !== null && regionParameterForOnline !== undefined) { + let requestModelMapper = new client.models['RegionForOnlineOffline']().mapper(); + requestModel = client.serialize(requestModelMapper, regionParameterForOnline, 'regionParameterForOnline'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(regionParameterForOnline, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200 && statusCode !== 202) { + 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) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().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; + + return callback(null, result, httpRequest, response); + }); +} + +/** + * Regenerates an access key for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} keyToRegenerate The name of the key to regenerate. + * + * @param {string} keyToRegenerate.keyKind The access key to regenerate. + * Possible values include: 'primary', 'secondary', 'primaryReadonly', + * 'secondaryReadonly' + * + * @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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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 _beginRegenerateKey(resourceGroupName, accountName, keyToRegenerate, 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 (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 (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 (resourceGroupName !== null && resourceGroupName !== undefined) { + if (resourceGroupName.length > 90) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90'); + } + if (resourceGroupName.length < 1) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1'); + } + if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null) + { + throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/'); + } + } + if (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') { + throw new Error('accountName cannot be null or undefined and it must be of type string.'); + } + if (accountName !== null && accountName !== undefined) { + if (accountName.length > 50) + { + throw new Error('"accountName" should satisfy the constraint - "MaxLength": 50'); + } + if (accountName.length < 3) + { + throw new Error('"accountName" should satisfy the constraint - "MinLength": 3'); + } + } + if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') { + throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.'); + } + if (keyToRegenerate === null || keyToRegenerate === undefined) { + throw new Error('keyToRegenerate cannot be null or undefined.'); + } + 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.DocumentDB/databaseAccounts/{accountName}/regenerateKey'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'POST'; + 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]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (keyToRegenerate !== null && keyToRegenerate !== undefined) { + let requestModelMapper = new client.models['DatabaseAccountRegenerateKeyParameters']().mapper(); + requestModel = client.serialize(requestModelMapper, keyToRegenerate, 'keyToRegenerate'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(keyToRegenerate, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200 && statusCode !== 202) { + 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; + + return callback(null, result, httpRequest, response); + }); +} + +/** Class representing a DatabaseAccounts. */ +class DatabaseAccounts { + /** + * Create a DatabaseAccounts. + * @param {CosmosDBManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._get = _get; + this._patch = _patch; + this._createOrUpdate = _createOrUpdate; + this._deleteMethod = _deleteMethod; + this._failoverPriorityChange = _failoverPriorityChange; + this._list = _list; + this._listByResourceGroup = _listByResourceGroup; + this._listKeys = _listKeys; + this._listConnectionStrings = _listConnectionStrings; + this._offlineRegion = _offlineRegion; + this._onlineRegion = _onlineRegion; + this._listReadOnlyKeys = _listReadOnlyKeys; + this._regenerateKey = _regenerateKey; + this._checkNameExists = _checkNameExists; + this._listMetrics = _listMetrics; + this._listUsages = _listUsages; + this._listMetricDefinitions = _listMetricDefinitions; + this._beginPatch = _beginPatch; + this._beginCreateOrUpdate = _beginCreateOrUpdate; + this._beginDeleteMethod = _beginDeleteMethod; + this._beginFailoverPriorityChange = _beginFailoverPriorityChange; + this._beginOfflineRegion = _beginOfflineRegion; + this._beginOnlineRegion = _beginOnlineRegion; + this._beginRegenerateKey = _beginRegenerateKey; + } + + /** + * Retrieves the properties of an existing Azure Cosmos DB database account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @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. + */ + getWithHttpOperationResponse(resourceGroupName, accountName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(resourceGroupName, accountName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Retrieves the properties of an existing Azure Cosmos DB database account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @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 {DatabaseAccount} - The deserialized result object. * @@ -3673,7 +4169,179 @@ class DatabaseAccounts { * * {Promise} A promise is returned * - * @resolve {DatabaseAccountsListResult} - The deserialized result object. + * @resolve {DatabaseAccountsListResult} - 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 DatabaseAccountsListResult} 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. + */ + list(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._list(options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._list(options, optionalCallback); + } + } + + /** + * Lists all the Azure Cosmos DB database accounts available under the given + * resource group. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @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. + */ + listByResourceGroupWithHttpOperationResponse(resourceGroupName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists all the Azure Cosmos DB database accounts available under the given + * resource group. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @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 {DatabaseAccountsListResult} - 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 DatabaseAccountsListResult} 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. + */ + listByResourceGroup(resourceGroupName, 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._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listByResourceGroup(resourceGroupName, options, optionalCallback); + } + } + + /** + * Lists the access keys for the specified Azure Cosmos DB database account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @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. + */ + listKeysWithHttpOperationResponse(resourceGroupName, accountName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listKeys(resourceGroupName, accountName, 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 access keys for the specified Azure Cosmos DB database account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @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 {DatabaseAccountListKeysResult} - The deserialized result object. * * @reject {Error} - The error object. * @@ -3682,14 +4350,14 @@ class DatabaseAccounts { * {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 DatabaseAccountsListResult} for more + * See {@link DatabaseAccountListKeysResult} 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. */ - list(options, optionalCallback) { + listKeys(resourceGroupName, accountName, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3698,23 +4366,25 @@ class DatabaseAccounts { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._list(options, (err, result, request, response) => { + self._listKeys(resourceGroupName, accountName, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._list(options, optionalCallback); + return self._listKeys(resourceGroupName, accountName, options, optionalCallback); } } /** - * Lists all the Azure Cosmos DB database accounts available under the given - * resource group. + * Lists the connection strings for the specified Azure Cosmos DB database + * account. * * @param {string} resourceGroupName Name of an Azure resource group. * + * @param {string} accountName Cosmos DB database account name. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -3722,15 +4392,15 @@ class DatabaseAccounts { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error} - The error object. */ - listByResourceGroupWithHttpOperationResponse(resourceGroupName, options) { + listConnectionStringsWithHttpOperationResponse(resourceGroupName, accountName, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => { + self._listConnectionStrings(resourceGroupName, accountName, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3741,11 +4411,13 @@ class DatabaseAccounts { } /** - * Lists all the Azure Cosmos DB database accounts available under the given - * resource group. + * Lists the connection strings for the specified Azure Cosmos DB database + * account. * * @param {string} resourceGroupName Name of an Azure resource group. * + * @param {string} accountName Cosmos DB database account name. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -3758,7 +4430,7 @@ class DatabaseAccounts { * * {Promise} A promise is returned * - * @resolve {DatabaseAccountsListResult} - The deserialized result object. + * @resolve {DatabaseAccountListConnectionStringsResult} - The deserialized result object. * * @reject {Error} - The error object. * @@ -3767,14 +4439,14 @@ class DatabaseAccounts { * {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 DatabaseAccountsListResult} for more - * information. + * See {@link DatabaseAccountListConnectionStringsResult} + * 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. */ - listByResourceGroup(resourceGroupName, options, optionalCallback) { + listConnectionStrings(resourceGroupName, accountName, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3783,24 +4455,31 @@ class DatabaseAccounts { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => { + self._listConnectionStrings(resourceGroupName, accountName, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listByResourceGroup(resourceGroupName, options, optionalCallback); + return self._listConnectionStrings(resourceGroupName, accountName, options, optionalCallback); } } /** - * Lists the access keys for the specified Azure Cosmos DB database account. + * Offline the specified region for the specified Azure Cosmos DB database + * account. * * @param {string} resourceGroupName Name of an Azure resource group. * * @param {string} accountName Cosmos DB database account name. * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -3808,15 +4487,15 @@ class DatabaseAccounts { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error} - The error object. */ - listKeysWithHttpOperationResponse(resourceGroupName, accountName, options) { + offlineRegionWithHttpOperationResponse(resourceGroupName, accountName, regionParameterForOffline, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listKeys(resourceGroupName, accountName, options, (err, result, request, response) => { + self._offlineRegion(resourceGroupName, accountName, regionParameterForOffline, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3827,12 +4506,19 @@ class DatabaseAccounts { } /** - * Lists the access keys for the specified Azure Cosmos DB database account. + * Offline the specified region for the specified Azure Cosmos DB database + * account. * * @param {string} resourceGroupName Name of an Azure resource group. * * @param {string} accountName Cosmos DB database account name. * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -3845,7 +4531,7 @@ class DatabaseAccounts { * * {Promise} A promise is returned * - * @resolve {DatabaseAccountListKeysResult} - The deserialized result object. + * @resolve {null} - The deserialized result object. * * @reject {Error} - The error object. * @@ -3853,15 +4539,13 @@ class DatabaseAccounts { * * {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 DatabaseAccountListKeysResult} for more - * information. + * {null} [result] - The deserialized result object if an error did not occur. * * {object} [request] - The HTTP Request object if an error did not occur. * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listKeys(resourceGroupName, accountName, options, optionalCallback) { + offlineRegion(resourceGroupName, accountName, regionParameterForOffline, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3870,25 +4554,31 @@ class DatabaseAccounts { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listKeys(resourceGroupName, accountName, options, (err, result, request, response) => { + self._offlineRegion(resourceGroupName, accountName, regionParameterForOffline, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listKeys(resourceGroupName, accountName, options, optionalCallback); + return self._offlineRegion(resourceGroupName, accountName, regionParameterForOffline, options, optionalCallback); } } /** - * Lists the connection strings for the specified Azure Cosmos DB database + * Online the specified region for the specified Azure Cosmos DB database * account. * * @param {string} resourceGroupName Name of an Azure resource group. * * @param {string} accountName Cosmos DB database account name. * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -3896,15 +4586,15 @@ class DatabaseAccounts { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error} - The error object. */ - listConnectionStringsWithHttpOperationResponse(resourceGroupName, accountName, options) { + onlineRegionWithHttpOperationResponse(resourceGroupName, accountName, regionParameterForOnline, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listConnectionStrings(resourceGroupName, accountName, options, (err, result, request, response) => { + self._onlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3915,13 +4605,19 @@ class DatabaseAccounts { } /** - * Lists the connection strings for the specified Azure Cosmos DB database + * Online the specified region for the specified Azure Cosmos DB database * account. * * @param {string} resourceGroupName Name of an Azure resource group. * * @param {string} accountName Cosmos DB database account name. * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * * @param {object} [options] Optional Parameters. * * @param {object} [options.customHeaders] Headers that will be added to the @@ -3934,7 +4630,7 @@ class DatabaseAccounts { * * {Promise} A promise is returned * - * @resolve {DatabaseAccountListConnectionStringsResult} - The deserialized result object. + * @resolve {null} - The deserialized result object. * * @reject {Error} - The error object. * @@ -3942,15 +4638,13 @@ class DatabaseAccounts { * * {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 DatabaseAccountListConnectionStringsResult} - * for more information. + * {null} [result] - The deserialized result object if an error did not occur. * * {object} [request] - The HTTP Request object if an error did not occur. * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listConnectionStrings(resourceGroupName, accountName, options, optionalCallback) { + onlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3959,14 +4653,14 @@ class DatabaseAccounts { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listConnectionStrings(resourceGroupName, accountName, options, (err, result, request, response) => { + self._onlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listConnectionStrings(resourceGroupName, accountName, options, optionalCallback); + return self._onlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, optionalCallback); } } @@ -5016,6 +5710,204 @@ class DatabaseAccounts { } } + /** + * Offline the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + */ + beginOfflineRegionWithHttpOperationResponse(resourceGroupName, accountName, regionParameterForOffline, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._beginOfflineRegion(resourceGroupName, accountName, regionParameterForOffline, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Offline the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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 {null} - 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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + beginOfflineRegion(resourceGroupName, accountName, regionParameterForOffline, 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._beginOfflineRegion(resourceGroupName, accountName, regionParameterForOffline, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._beginOfflineRegion(resourceGroupName, accountName, regionParameterForOffline, options, optionalCallback); + } + } + + /** + * Online the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + */ + beginOnlineRegionWithHttpOperationResponse(resourceGroupName, accountName, regionParameterForOnline, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._beginOnlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Online the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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 {null} - 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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {object} [request] - The HTTP Request object if an error did not occur. + * + * {stream} [response] - The HTTP Response stream if an error did not occur. + */ + beginOnlineRegion(resourceGroupName, accountName, regionParameterForOnline, 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._beginOnlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._beginOnlineRegion(resourceGroupName, accountName, regionParameterForOnline, options, optionalCallback); + } + } + /** * Regenerates an access key for the specified Azure Cosmos DB database * account. diff --git a/lib/services/cosmosdbManagement/lib/operations/index.d.ts b/lib/services/cosmosdbManagement/lib/operations/index.d.ts index 1073980bde..e3dc7e98c0 100644 --- a/lib/services/cosmosdbManagement/lib/operations/index.d.ts +++ b/lib/services/cosmosdbManagement/lib/operations/index.d.ts @@ -700,6 +700,150 @@ export interface DatabaseAccounts { listConnectionStrings(resourceGroupName: string, accountName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + /** + * Offline the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + */ + offlineRegionWithHttpOperationResponse(resourceGroupName: string, accountName: string, regionParameterForOffline: models.RegionForOnlineOffline, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Offline the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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 {null} - 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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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. + */ + offlineRegion(resourceGroupName: string, accountName: string, regionParameterForOffline: models.RegionForOnlineOffline, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + offlineRegion(resourceGroupName: string, accountName: string, regionParameterForOffline: models.RegionForOnlineOffline, callback: ServiceCallback): void; + offlineRegion(resourceGroupName: string, accountName: string, regionParameterForOffline: models.RegionForOnlineOffline, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Online the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + */ + onlineRegionWithHttpOperationResponse(resourceGroupName: string, accountName: string, regionParameterForOnline: models.RegionForOnlineOffline, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Online the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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 {null} - 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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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. + */ + onlineRegion(resourceGroupName: string, accountName: string, regionParameterForOnline: models.RegionForOnlineOffline, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + onlineRegion(resourceGroupName: string, accountName: string, regionParameterForOnline: models.RegionForOnlineOffline, callback: ServiceCallback): void; + onlineRegion(resourceGroupName: string, accountName: string, regionParameterForOnline: models.RegionForOnlineOffline, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + /** * Lists the read-only access keys for the specified Azure Cosmos DB database * account. @@ -1476,6 +1620,150 @@ export interface DatabaseAccounts { beginFailoverPriorityChange(resourceGroupName: string, accountName: string, failoverParameters: models.FailoverPolicies, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + /** + * Offline the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + */ + beginOfflineRegionWithHttpOperationResponse(resourceGroupName: string, accountName: string, regionParameterForOffline: models.RegionForOnlineOffline, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Offline the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOffline Cosmos DB region to offline for + * the database account. + * + * @param {string} regionParameterForOffline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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 {null} - 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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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. + */ + beginOfflineRegion(resourceGroupName: string, accountName: string, regionParameterForOffline: models.RegionForOnlineOffline, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + beginOfflineRegion(resourceGroupName: string, accountName: string, regionParameterForOffline: models.RegionForOnlineOffline, callback: ServiceCallback): void; + beginOfflineRegion(resourceGroupName: string, accountName: string, regionParameterForOffline: models.RegionForOnlineOffline, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Online the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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. + */ + beginOnlineRegionWithHttpOperationResponse(resourceGroupName: string, accountName: string, regionParameterForOnline: models.RegionForOnlineOffline, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Online the specified region for the specified Azure Cosmos DB database + * account. + * + * @param {string} resourceGroupName Name of an Azure resource group. + * + * @param {string} accountName Cosmos DB database account name. + * + * @param {object} regionParameterForOnline Cosmos DB region to online for the + * database account. + * + * @param {string} regionParameterForOnline.region Cosmos DB region, with + * spaces between words and each word capitalized. + * + * @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 {null} - 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. + * + * {null} [result] - The deserialized result object if an error did not occur. + * + * {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. + */ + beginOnlineRegion(resourceGroupName: string, accountName: string, regionParameterForOnline: models.RegionForOnlineOffline, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + beginOnlineRegion(resourceGroupName: string, accountName: string, regionParameterForOnline: models.RegionForOnlineOffline, callback: ServiceCallback): void; + beginOnlineRegion(resourceGroupName: string, accountName: string, regionParameterForOnline: models.RegionForOnlineOffline, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + /** * Regenerates an access key for the specified Azure Cosmos DB database * account. diff --git a/lib/services/cosmosdbManagement/package.json b/lib/services/cosmosdbManagement/package.json index 92ec1639b8..f72d19dee8 100644 --- a/lib/services/cosmosdbManagement/package.json +++ b/lib/services/cosmosdbManagement/package.json @@ -4,10 +4,13 @@ "description": "CosmosDBManagementClient Library with typescript type definitions for node", "version": "1.1.1-preview", "dependencies": { - "ms-rest": "^2.3.2", + "ms-rest": "^2.3.3", "ms-rest-azure": "^2.5.5" }, - "keywords": [ "node", "azure" ], + "keywords": [ + "node", + "azure" + ], "license": "MIT", "main": "./lib/cosmosDBManagementClient.js", "types": "./lib/cosmosDBManagementClient.d.ts",