diff --git a/lib/services/recoveryServicesManagement/lib/models/index.d.ts b/lib/services/recoveryServicesManagement/lib/models/index.d.ts index 3d0367939c..ed859d22be 100644 --- a/lib/services/recoveryServicesManagement/lib/models/index.d.ts +++ b/lib/services/recoveryServicesManagement/lib/models/index.d.ts @@ -326,6 +326,35 @@ export interface Resource extends BaseResource { eTag?: string; } +/** + * Resource information, as sent to the regional resource provider from Global RP. +*/ +export interface ResourceNameAvailabilityInput { + type?: string; + name?: string; +} + +/** + * Response for check name availability API. Resource provider will set availability as true | + * false. +*/ +export interface ResourceNameAvailabilityResponse { + nameAvailable?: boolean; + reason?: string; + message?: string; +} + +/** + * Response for check name availability API. Resource provider will set availability as true | + * false. +*/ +export interface ResourceNameAvailabilityResponseResource extends Resource { + /** + * ResourceNameAvailabilityResponseResource properties + */ + properties?: ResourceNameAvailabilityResponse; +} + /** * Identifies the unique system identifier for each Azure resource. */ diff --git a/lib/services/recoveryServicesManagement/lib/models/index.js b/lib/services/recoveryServicesManagement/lib/models/index.js index dbda3919aa..a481401921 100644 --- a/lib/services/recoveryServicesManagement/lib/models/index.js +++ b/lib/services/recoveryServicesManagement/lib/models/index.js @@ -33,6 +33,9 @@ exports.ClientDiscoveryForServiceSpecification = require('./clientDiscoveryForSe exports.ClientDiscoveryForProperties = require('./clientDiscoveryForProperties'); exports.ClientDiscoveryValueForSingleApi = require('./clientDiscoveryValueForSingleApi'); exports.Resource = require('./resource'); +exports.ResourceNameAvailabilityInput = require('./resourceNameAvailabilityInput'); +exports.ResourceNameAvailabilityResponse = require('./resourceNameAvailabilityResponse'); +exports.ResourceNameAvailabilityResponseResource = require('./resourceNameAvailabilityResponseResource'); exports.Sku = require('./sku'); exports.TrackedResource = require('./trackedResource'); exports.PatchTrackedResource = require('./patchTrackedResource'); diff --git a/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityInput.js b/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityInput.js new file mode 100644 index 0000000000..72ea9ea4a8 --- /dev/null +++ b/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityInput.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'; + +/** + * Resource information, as sent to the regional resource provider from Global + * RP. + * + */ +class ResourceNameAvailabilityInput { + /** + * Create a ResourceNameAvailabilityInput. + * @property {string} [type] + * @property {string} [name] + */ + constructor() { + } + + /** + * Defines the metadata of ResourceNameAvailabilityInput + * + * @returns {object} metadata of ResourceNameAvailabilityInput + * + */ + mapper() { + return { + required: false, + serializedName: 'ResourceNameAvailabilityInput', + type: { + name: 'Composite', + className: 'ResourceNameAvailabilityInput', + modelProperties: { + type: { + required: false, + serializedName: 'type', + type: { + name: 'String' + } + }, + name: { + required: false, + serializedName: 'name', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = ResourceNameAvailabilityInput; diff --git a/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityResponse.js b/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityResponse.js new file mode 100644 index 0000000000..715cacf93f --- /dev/null +++ b/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityResponse.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'; + +/** + * Response for check name availability API. Resource provider will set + * availability as true | false. + * + */ +class ResourceNameAvailabilityResponse { + /** + * Create a ResourceNameAvailabilityResponse. + * @property {boolean} [nameAvailable] + * @property {string} [reason] + * @property {string} [message] + */ + constructor() { + } + + /** + * Defines the metadata of ResourceNameAvailabilityResponse + * + * @returns {object} metadata of ResourceNameAvailabilityResponse + * + */ + mapper() { + return { + required: false, + serializedName: 'ResourceNameAvailabilityResponse', + type: { + name: 'Composite', + className: 'ResourceNameAvailabilityResponse', + modelProperties: { + nameAvailable: { + required: false, + serializedName: 'nameAvailable', + type: { + name: 'Boolean' + } + }, + reason: { + required: false, + serializedName: 'reason', + type: { + name: 'String' + } + }, + message: { + required: false, + serializedName: 'message', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = ResourceNameAvailabilityResponse; diff --git a/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityResponseResource.js b/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityResponseResource.js new file mode 100644 index 0000000000..4a249ae098 --- /dev/null +++ b/lib/services/recoveryServicesManagement/lib/models/resourceNameAvailabilityResponseResource.js @@ -0,0 +1,93 @@ +/* + * 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'; + +const models = require('./index'); + +/** + * Response for check name availability API. Resource provider will set + * availability as true | false. + * + * @extends models['Resource'] + */ +class ResourceNameAvailabilityResponseResource extends models['Resource'] { + /** + * Create a ResourceNameAvailabilityResponseResource. + * @property {object} [properties] ResourceNameAvailabilityResponseResource + * properties + * @property {boolean} [properties.nameAvailable] + * @property {string} [properties.reason] + * @property {string} [properties.message] + */ + constructor() { + super(); + } + + /** + * Defines the metadata of ResourceNameAvailabilityResponseResource + * + * @returns {object} metadata of ResourceNameAvailabilityResponseResource + * + */ + mapper() { + return { + required: false, + serializedName: 'ResourceNameAvailabilityResponseResource', + type: { + name: 'Composite', + className: 'ResourceNameAvailabilityResponseResource', + modelProperties: { + id: { + required: false, + readOnly: true, + serializedName: 'id', + type: { + name: 'String' + } + }, + name: { + required: false, + readOnly: true, + serializedName: 'name', + type: { + name: 'String' + } + }, + type: { + required: false, + readOnly: true, + serializedName: 'type', + type: { + name: 'String' + } + }, + eTag: { + required: false, + serializedName: 'eTag', + type: { + name: 'String' + } + }, + properties: { + required: false, + serializedName: 'properties', + type: { + name: 'Composite', + className: 'ResourceNameAvailabilityResponse' + } + } + } + } + }; + } +} + +module.exports = ResourceNameAvailabilityResponseResource; diff --git a/lib/services/recoveryServicesManagement/lib/operations/checkResourceNameAvailability.js b/lib/services/recoveryServicesManagement/lib/operations/checkResourceNameAvailability.js new file mode 100644 index 0000000000..247c34ef57 --- /dev/null +++ b/lib/services/recoveryServicesManagement/lib/operations/checkResourceNameAvailability.js @@ -0,0 +1,303 @@ +/* + * 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'; + +const msRest = require('ms-rest'); +const msRestAzure = require('ms-rest-azure'); +const WebResource = msRest.WebResource; + +/** + * @summary API to check for resource name availability. + * A name is available if no other resource exists that has the same + * SubscriptionId, Resource Name and Type + * or if one or more such resources exist, each of these must be GCed and their + * time of deletion be more than 24 Hours Ago + * + * @param {string} location Location of the resource + * + * @param {object} input Contains information about Resource type and Resource + * name + * + * @param {string} [input.type] + * + * @param {string} [input.name] + * + * @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 ResourceNameAvailabilityResponseResource} + * 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 _post(location, input, 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 (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 (location === null || location === undefined || typeof location.valueOf() !== 'string') { + throw new Error('location cannot be null or undefined and it must be of type string.'); + } + if (input === null || input === undefined) { + throw new Error('input 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}/providers/Microsoft.RecoveryServices/locations/{location}/checkNameAvailability'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{location}', encodeURIComponent(location)); + 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 (input !== null && input !== undefined) { + let requestModelMapper = new client.models['ResourceNameAvailabilityInput']().mapper(); + requestModel = client.serialize(requestModelMapper, input, 'input'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(input, 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) { + 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['ResourceNameAvailabilityResponseResource']().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 CheckResourceNameAvailability. */ +class CheckResourceNameAvailability { + /** + * Create a CheckResourceNameAvailability. + * @param {RecoveryServicesClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._post = _post; + } + + /** + * @summary API to check for resource name availability. + * A name is available if no other resource exists that has the same + * SubscriptionId, Resource Name and Type + * or if one or more such resources exist, each of these must be GCed and their + * time of deletion be more than 24 Hours Ago + * + * @param {string} location Location of the resource + * + * @param {object} input Contains information about Resource type and Resource + * name + * + * @param {string} [input.type] + * + * @param {string} [input.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. + */ + postWithHttpOperationResponse(location, input, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._post(location, input, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * @summary API to check for resource name availability. + * A name is available if no other resource exists that has the same + * SubscriptionId, Resource Name and Type + * or if one or more such resources exist, each of these must be GCed and their + * time of deletion be more than 24 Hours Ago + * + * @param {string} location Location of the resource + * + * @param {object} input Contains information about Resource type and Resource + * name + * + * @param {string} [input.type] + * + * @param {string} [input.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 {ResourceNameAvailabilityResponseResource} - 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 ResourceNameAvailabilityResponseResource} + * 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. + */ + post(location, input, 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._post(location, input, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._post(location, input, options, optionalCallback); + } + } + +} + +module.exports = CheckResourceNameAvailability; diff --git a/lib/services/recoveryServicesManagement/lib/operations/index.d.ts b/lib/services/recoveryServicesManagement/lib/operations/index.d.ts index 870c6183fa..167374f08d 100644 --- a/lib/services/recoveryServicesManagement/lib/operations/index.d.ts +++ b/lib/services/recoveryServicesManagement/lib/operations/index.d.ts @@ -254,6 +254,93 @@ export interface ReplicationUsages { list(resourceGroupName: string, vaultName: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } +/** + * @class + * CheckResourceNameAvailability + * __NOTE__: An instance of this class is automatically created for an + * instance of the RecoveryServicesClient. + */ +export interface CheckResourceNameAvailability { + + + /** + * @summary API to check for resource name availability. + * A name is available if no other resource exists that has the same + * SubscriptionId, Resource Name and Type + * or if one or more such resources exist, each of these must be GCed and their + * time of deletion be more than 24 Hours Ago + * + * @param {string} location Location of the resource + * + * @param {object} input Contains information about Resource type and Resource + * name + * + * @param {string} [input.type] + * + * @param {string} [input.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|ServiceError} - The error object. + */ + postWithHttpOperationResponse(location: string, input: models.ResourceNameAvailabilityInput, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * @summary API to check for resource name availability. + * A name is available if no other resource exists that has the same + * SubscriptionId, Resource Name and Type + * or if one or more such resources exist, each of these must be GCed and their + * time of deletion be more than 24 Hours Ago + * + * @param {string} location Location of the resource + * + * @param {object} input Contains information about Resource type and Resource + * name + * + * @param {string} [input.type] + * + * @param {string} [input.name] + * + * @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 {ResourceNameAvailabilityResponseResource} - 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. + * + * {ResourceNameAvailabilityResponseResource} [result] - The deserialized result object if an error did not occur. + * See {@link ResourceNameAvailabilityResponseResource} + * 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. + */ + post(location: string, input: models.ResourceNameAvailabilityInput, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + post(location: string, input: models.ResourceNameAvailabilityInput, callback: ServiceCallback): void; + post(location: string, input: models.ResourceNameAvailabilityInput, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} + /** * @class * Vaults diff --git a/lib/services/recoveryServicesManagement/lib/operations/index.js b/lib/services/recoveryServicesManagement/lib/operations/index.js index 128e63656c..b32ddfa3cb 100644 --- a/lib/services/recoveryServicesManagement/lib/operations/index.js +++ b/lib/services/recoveryServicesManagement/lib/operations/index.js @@ -17,6 +17,7 @@ exports.VaultCertificates = require('./vaultCertificates'); exports.RegisteredIdentities = require('./registeredIdentities'); exports.ReplicationUsages = require('./replicationUsages'); +exports.CheckResourceNameAvailability = require('./checkResourceNameAvailability'); exports.Vaults = require('./vaults'); exports.Operations = require('./operations'); exports.VaultExtendedInfoOperations = require('./vaultExtendedInfoOperations'); diff --git a/lib/services/recoveryServicesManagement/lib/recoveryServicesClient.d.ts b/lib/services/recoveryServicesManagement/lib/recoveryServicesClient.d.ts index bd798ed905..c9dd425a5f 100644 --- a/lib/services/recoveryServicesManagement/lib/recoveryServicesClient.d.ts +++ b/lib/services/recoveryServicesManagement/lib/recoveryServicesClient.d.ts @@ -59,6 +59,7 @@ export default class RecoveryServicesClient extends AzureServiceClient { vaultCertificates: operations.VaultCertificates; registeredIdentities: operations.RegisteredIdentities; replicationUsages: operations.ReplicationUsages; + checkResourceNameAvailability: operations.CheckResourceNameAvailability; vaults: operations.Vaults; operations: operations.Operations; vaultExtendedInfoOperations: operations.VaultExtendedInfoOperations; diff --git a/lib/services/recoveryServicesManagement/lib/recoveryServicesClient.js b/lib/services/recoveryServicesManagement/lib/recoveryServicesClient.js index b5c1f52cb8..b07f3adc76 100644 --- a/lib/services/recoveryServicesManagement/lib/recoveryServicesClient.js +++ b/lib/services/recoveryServicesManagement/lib/recoveryServicesClient.js @@ -75,6 +75,7 @@ class RecoveryServicesClient extends ServiceClient { this.vaultCertificates = new operations.VaultCertificates(this); this.registeredIdentities = new operations.RegisteredIdentities(this); this.replicationUsages = new operations.ReplicationUsages(this); + this.checkResourceNameAvailability = new operations.CheckResourceNameAvailability(this); this.vaults = new operations.Vaults(this); this.operations = new operations.Operations(this); this.vaultExtendedInfoOperations = new operations.VaultExtendedInfoOperations(this);