Skip to content
This repository was archived by the owner on May 5, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions lib/services/cdnManagement/lib/cdnManagementClient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { AzureServiceClient, AzureServiceClientOptions } from 'ms-rest-azure';
import * as models from "./models";
import * as operations from "./operations";

declare class CdnManagementClient extends AzureServiceClient {
export default class CdnManagementClient extends AzureServiceClient {
/**
* Initializes a new instance of the CdnManagementClient class.
* @constructor
Expand Down Expand Up @@ -123,6 +123,64 @@ declare class CdnManagementClient extends AzureServiceClient {
checkNameAvailability(name: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<models.CheckNameAvailabilityOutput>): void;


/**
* Check the availability of a resource name. This is needed for resources
* where name is globally unique, such as a CDN endpoint.
*
* @param {string} name The resource name to validate.
*
* @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<CheckNameAvailabilityOutput>} - The deserialized result object.
*
* @reject {Error|ServiceError} - The error object.
*/
checkNameAvailabilityWithSubscriptionWithHttpOperationResponse(name: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise<HttpOperationResponse<models.CheckNameAvailabilityOutput>>;

/**
* Check the availability of a resource name. This is needed for resources
* where name is globally unique, such as a CDN endpoint.
*
* @param {string} name The resource name to validate.
*
* @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 {CheckNameAvailabilityOutput} - 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.
*
* {CheckNameAvailabilityOutput} [result] - The deserialized result object if an error did not occur.
* See {@link CheckNameAvailabilityOutput} 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.
*/
checkNameAvailabilityWithSubscription(name: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise<models.CheckNameAvailabilityOutput>;
checkNameAvailabilityWithSubscription(name: string, callback: ServiceCallback<models.CheckNameAvailabilityOutput>): void;
checkNameAvailabilityWithSubscription(name: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<models.CheckNameAvailabilityOutput>): void;


/**
* Check if the probe path is a valid path and the file can be accessed. Probe
* path is the path to a file hosted on the origin server to help accelerate
Expand Down Expand Up @@ -184,4 +242,4 @@ declare class CdnManagementClient extends AzureServiceClient {
validateProbe(probeURL: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback<models.ValidateProbeOutput>): void;
}

export = CdnManagementClient;
export { CdnManagementClient, models as CdnManagementModels };
253 changes: 253 additions & 0 deletions lib/services/cdnManagement/lib/cdnManagementClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,170 @@ function _checkNameAvailability(name, options, callback) {
});
}

/**
* Check the availability of a resource name. This is needed for resources
* where name is globally unique, such as a CDN endpoint.
*
* @param {string} name The resource name to validate.
*
* @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 CheckNameAvailabilityOutput} 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 _checkNameAvailabilityWithSubscription(name, options, callback) {
/* jshint validthis: true */
let client = this;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
// Validate
try {
if (this.subscriptionId === null || this.subscriptionId === undefined || typeof this.subscriptionId.valueOf() !== 'string') {
throw new Error('this.subscriptionId cannot be null or undefined and it must be of type string.');
}
if (this.apiVersion === null || this.apiVersion === undefined || typeof this.apiVersion.valueOf() !== 'string') {
throw new Error('this.apiVersion cannot be null or undefined and it must be of type string.');
}
if (name === null || name === undefined || typeof name.valueOf() !== 'string') {
throw new Error('name cannot be null or undefined and it must be of type string.');
}
if (this.acceptLanguage !== null && this.acceptLanguage !== undefined && typeof this.acceptLanguage.valueOf() !== 'string') {
throw new Error('this.acceptLanguage must be of type string.');
}
} catch (error) {
return callback(error);
}
let checkNameAvailabilityInput = new client.models['CheckNameAvailabilityInput']();
try {
if (name !== null && name !== undefined)
{
checkNameAvailabilityInput.name = name;
}
} catch (error) {
return callback(error);
}

// Construct URL
let baseUrl = this.baseUri;
let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Cdn/checkNameAvailability';
requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.subscriptionId));
let queryParameters = [];
queryParameters.push('api-version=' + encodeURIComponent(this.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.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.acceptLanguage !== undefined && this.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.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 (checkNameAvailabilityInput !== null && checkNameAvailabilityInput !== undefined) {
let requestModelMapper = new client.models['CheckNameAvailabilityInput']().mapper();
requestModel = client.serialize(requestModelMapper, checkNameAvailabilityInput, 'checkNameAvailabilityInput');
requestContent = JSON.stringify(requestModel);
}
} catch (error) {
let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
`payload - ${JSON.stringify(checkNameAvailabilityInput, 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) {
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;
// 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['CheckNameAvailabilityOutput']().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);
});
}

/**
* Check if the probe path is a valid path and the file can be accessed. Probe
* path is the path to a file hosted on the origin server to help accelerate
Expand Down Expand Up @@ -403,6 +567,7 @@ class CdnManagementClient extends ServiceClient {
this.edgeNodes = new operations.EdgeNodes(this);
this.models = models;
this._checkNameAvailability = _checkNameAvailability;
this._checkNameAvailabilityWithSubscription = _checkNameAvailabilityWithSubscription;
this._validateProbe = _validateProbe;
msRest.addSerializationMixin(this);
}
Expand Down Expand Up @@ -492,6 +657,91 @@ class CdnManagementClient extends ServiceClient {
}
}

/**
* Check the availability of a resource name. This is needed for resources
* where name is globally unique, such as a CDN endpoint.
*
* @param {string} name The resource name to validate.
*
* @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<CheckNameAvailabilityOutput>} - The deserialized result object.
*
* @reject {Error} - The error object.
*/
checkNameAvailabilityWithSubscriptionWithHttpOperationResponse(name, options) {
let client = this;
let self = this;
return new Promise((resolve, reject) => {
self._checkNameAvailabilityWithSubscription(name, options, (err, result, request, response) => {
let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
httpOperationResponse.body = result;
if (err) { reject(err); }
else { resolve(httpOperationResponse); }
return;
});
});
}

/**
* Check the availability of a resource name. This is needed for resources
* where name is globally unique, such as a CDN endpoint.
*
* @param {string} name The resource name to validate.
*
* @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 {CheckNameAvailabilityOutput} - 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 CheckNameAvailabilityOutput} 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.
*/
checkNameAvailabilityWithSubscription(name, options, optionalCallback) {
let client = this;
let self = this;
if (!optionalCallback && typeof options === 'function') {
optionalCallback = options;
options = null;
}
if (!optionalCallback) {
return new Promise((resolve, reject) => {
self._checkNameAvailabilityWithSubscription(name, options, (err, result, request, response) => {
if (err) { reject(err); }
else { resolve(result); }
return;
});
});
} else {
return self._checkNameAvailabilityWithSubscription(name, options, optionalCallback);
}
}

/**
* Check if the probe path is a valid path and the file can be accessed. Probe
* path is the path to a file hosted on the origin server to help accelerate
Expand Down Expand Up @@ -583,3 +833,6 @@ class CdnManagementClient extends ServiceClient {
}

module.exports = CdnManagementClient;
module.exports['default'] = CdnManagementClient;
module.exports.CdnManagementClient = CdnManagementClient;
module.exports.CdnManagementModels = models;