azure-arm-datalake-analytics
Version:
Microsoft Azure Data Lake Analytics Management Client Library for node
1,142 lines (1,111 loc) • 683 kB
JavaScript
/*
* 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;
/**
* Creates the specified secret for use with external data sources in the
* specified database. This is deprecated and will be removed in the next
* release. Please use CreateCredential instead.
*
* @param {string} accountName The Azure Data Lake Analytics account upon which
* to execute catalog operations.
*
* @param {string} databaseName The name of the database in which to create the
* secret.
*
* @param {string} secretName The name of the secret.
*
* @param {object} parameters The parameters required to create the secret
* (name and password)
*
* @param {string} parameters.password the password for the secret to pass in
*
* @param {string} [parameters.uri] the URI identifier for the secret in the
* format <hostname>:<port>
*
* @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 _createSecret(accountName, databaseName, secretName, parameters, 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 (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 (this.client.adlaCatalogDnsSuffix === null || this.client.adlaCatalogDnsSuffix === undefined || typeof this.client.adlaCatalogDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlaCatalogDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
throw new Error('databaseName cannot be null or undefined and it must be of type string.');
}
if (secretName === null || secretName === undefined || typeof secretName.valueOf() !== 'string') {
throw new Error('secretName cannot be null or undefined and it must be of type string.');
}
if (parameters === null || parameters === undefined) {
throw new Error('parameters cannot be null or undefined.');
}
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 (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('/') ? '' : '/') + 'catalog/usql/databases/{databaseName}/secrets/{secretName}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlaCatalogDnsSuffix}', this.client.adlaCatalogDnsSuffix);
requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
requestUrl = requestUrl.replace('{secretName}', encodeURIComponent(secretName));
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 = 'PUT';
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 (parameters !== null && parameters !== undefined) {
let requestModelMapper = new client.models['DataLakeAnalyticsCatalogSecretCreateOrUpdateParameters']().mapper();
requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
requestContent = JSON.stringify(requestModel);
}
} catch (error) {
let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
`payload - ${JSON.stringify(parameters, 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;
return callback(null, result, httpRequest, response);
});
}
/**
* Modifies the specified secret for use with external data sources in the
* specified database. This is deprecated and will be removed in the next
* release. Please use UpdateCredential instead.
*
* @param {string} accountName The Azure Data Lake Analytics account upon which
* to execute catalog operations.
*
* @param {string} databaseName The name of the database containing the secret.
*
* @param {string} secretName The name of the secret.
*
* @param {object} parameters The parameters required to modify the secret
* (name and password)
*
* @param {string} parameters.password the password for the secret to pass in
*
* @param {string} [parameters.uri] the URI identifier for the secret in the
* format <hostname>:<port>
*
* @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 _updateSecret(accountName, databaseName, secretName, parameters, 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 (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 (this.client.adlaCatalogDnsSuffix === null || this.client.adlaCatalogDnsSuffix === undefined || typeof this.client.adlaCatalogDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlaCatalogDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
throw new Error('databaseName cannot be null or undefined and it must be of type string.');
}
if (secretName === null || secretName === undefined || typeof secretName.valueOf() !== 'string') {
throw new Error('secretName cannot be null or undefined and it must be of type string.');
}
if (parameters === null || parameters === undefined) {
throw new Error('parameters cannot be null or undefined.');
}
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 (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('/') ? '' : '/') + 'catalog/usql/databases/{databaseName}/secrets/{secretName}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlaCatalogDnsSuffix}', this.client.adlaCatalogDnsSuffix);
requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
requestUrl = requestUrl.replace('{secretName}', encodeURIComponent(secretName));
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 = 'PATCH';
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 (parameters !== null && parameters !== undefined) {
let requestModelMapper = new client.models['DataLakeAnalyticsCatalogSecretCreateOrUpdateParameters']().mapper();
requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
requestContent = JSON.stringify(requestModel);
}
} catch (error) {
let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
`payload - ${JSON.stringify(parameters, 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;
return callback(null, result, httpRequest, response);
});
}
/**
* Deletes the specified secret in the specified database. This is deprecated
* and will be removed in the next release. Please use DeleteCredential
* instead.
*
* @param {string} accountName The Azure Data Lake Analytics account upon which
* to execute catalog operations.
*
* @param {string} databaseName The name of the database containing the secret.
*
* @param {string} secretName The name of the secret to delete
*
* @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 _deleteSecret(accountName, databaseName, secretName, 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 (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 (this.client.adlaCatalogDnsSuffix === null || this.client.adlaCatalogDnsSuffix === undefined || typeof this.client.adlaCatalogDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlaCatalogDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
throw new Error('databaseName cannot be null or undefined and it must be of type string.');
}
if (secretName === null || secretName === undefined || typeof secretName.valueOf() !== 'string') {
throw new Error('secretName 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 (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('/') ? '' : '/') + 'catalog/usql/databases/{databaseName}/secrets/{secretName}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlaCatalogDnsSuffix}', this.client.adlaCatalogDnsSuffix);
requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
requestUrl = requestUrl.replace('{secretName}', encodeURIComponent(secretName));
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 = 'DELETE';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['CloudError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
return callback(null, result, httpRequest, response);
});
}
/**
* Gets the specified secret in the specified database. This is deprecated and
* will be removed in the next release. Please use GetCredential instead.
*
* @param {string} accountName The Azure Data Lake Analytics account upon which
* to execute catalog operations.
*
* @param {string} databaseName The name of the database containing the secret.
*
* @param {string} secretName The name of the secret to get
*
* @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 USqlSecret} 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 _getSecret(accountName, databaseName, secretName, 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 (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 (this.client.adlaCatalogDnsSuffix === null || this.client.adlaCatalogDnsSuffix === undefined || typeof this.client.adlaCatalogDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlaCatalogDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
throw new Error('databaseName cannot be null or undefined and it must be of type string.');
}
if (secretName === null || secretName === undefined || typeof secretName.valueOf() !== 'string') {
throw new Error('secretName 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 (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('/') ? '' : '/') + 'catalog/usql/databases/{databaseName}/secrets/{secretName}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlaCatalogDnsSuffix}', this.client.adlaCatalogDnsSuffix);
requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
requestUrl = requestUrl.replace('{secretName}', encodeURIComponent(secretName));
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 = 'GET';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['CloudError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
// Deserialize Response
if (statusCode === 200) {
let parsedResponse = null;
try {
parsedResponse = JSON.parse(responseBody);
result = JSON.parse(responseBody);
if (parsedResponse !== null && parsedResponse !== undefined) {
let resultMapper = new client.models['USqlSecret']().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);
});
}
/**
* Deletes all secrets in the specified database. This is deprecated and will
* be removed in the next release. In the future, please only drop individual
* credentials using DeleteCredential
*
* @param {string} accountName The Azure Data Lake Analytics account upon which
* to execute catalog operations.
*
* @param {string} databaseName The name of the database containing the secret.
*
* @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 _deleteAllSecrets(accountName, databaseName, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('callback cannot be null.');
}
// Validate
try {
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 (this.client.adlaCatalogDnsSuffix === null || this.client.adlaCatalogDnsSuffix === undefined || typeof this.client.adlaCatalogDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlaCatalogDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
throw new Error('databaseName cannot be null or undefined and it must be of type string.');
}
if (this.client.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 (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('/') ? '' : '/') + 'catalog/usql/databases/{databaseName}/secrets';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlaCatalogDnsSuffix}', this.client.adlaCatalogDnsSuffix);
requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
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 = 'DELETE';
httpRequest.url = requestUrl;
httpRequest.headers = {};
// Set Headers
httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
if (this.client.generateClientRequestId) {
httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
}
if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
httpRequest.headers['accept-language'] = this.client.acceptLanguage;
}
if(options) {
for(let headerName in options['customHeaders']) {
if (options['customHeaders'].hasOwnProperty(headerName)) {
httpRequest.headers[headerName] = options['customHeaders'][headerName];
}
}
}
httpRequest.body = null;
// Send Request
return client.pipeline(httpRequest, (err, response, responseBody) => {
if (err) {
return callback(err);
}
let statusCode = response.statusCode;
if (statusCode !== 200) {
let error = new Error(responseBody);
error.statusCode = response.statusCode;
error.request = msRest.stripRequest(httpRequest);
error.response = msRest.stripResponse(response);
if (responseBody === '') responseBody = null;
let parsedErrorResponse;
try {
parsedErrorResponse = JSON.parse(responseBody);
if (parsedErrorResponse) {
if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
}
if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
let resultMapper = new client.models['CloudError']().mapper();
error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
}
} catch (defaultError) {
error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
`- "${responseBody}" for the default response.`;
return callback(error);
}
return callback(error);
}
// Create Result
let result = null;
if (responseBody === '') responseBody = null;
return callback(null, result, httpRequest, response);
});
}
/**
* Creates the specified credential for use with external data sources in the
* specified database.
*
* @param {string} accountName The Azure Data Lake Analytics account upon which
* to execute catalog operations.
*
* @param {string} databaseName The name of the database in which to create the
* credential. Note: This is NOT an external database name, but the name of an
* existing U-SQL database that should contain the new credential object.
*
* @param {string} credentialName The name of the credential.
*
* @param {object} parameters The parameters required to create the credential
* (name and password)
*
* @param {string} parameters.password the password for the credential and user
* with access to the data source.
*
* @param {string} parameters.uri the URI identifier for the data source this
* credential can connect to in the format <hostname>:<port>
*
* @param {string} parameters.userId the object identifier for the user
* associated with this credential with access to the data source.
*
* @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 _createCredential(accountName, databaseName, credentialName, parameters, 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 (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 (this.client.adlaCatalogDnsSuffix === null || this.client.adlaCatalogDnsSuffix === undefined || typeof this.client.adlaCatalogDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlaCatalogDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
throw new Error('databaseName cannot be null or undefined and it must be of type string.');
}
if (credentialName === null || credentialName === undefined || typeof credentialName.valueOf() !== 'string') {
throw new Error('credentialName cannot be null or undefined and it must be of type string.');
}
if (parameters === null || parameters === undefined) {
throw new Error('parameters cannot be null or undefined.');
}
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 (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('/') ? '' : '/') + 'catalog/usql/databases/{databaseName}/credentials/{credentialName}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlaCatalogDnsSuffix}', this.client.adlaCatalogDnsSuffix);
requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
requestUrl = requestUrl.replace('{credentialName}', encodeURIComponent(credentialName));
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 = 'PUT';
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 (parameters !== null && parameters !== undefined) {
let requestModelMapper = new client.models['DataLakeAnalyticsCatalogCredentialCreateParameters']().mapper();
requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
requestContent = JSON.stringify(requestModel);
}
} catch (error) {
let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
`payload - ${JSON.stringify(parameters, 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;
return callback(null, result, httpRequest, response);
});
}
/**
* Modifies the specified credential for use with external data sources in the
* specified database
*
* @param {string} accountName The Azure Data Lake Analytics account upon which
* to execute catalog operations.
*
* @param {string} databaseName The name of the database containing the
* credential.
*
* @param {string} credentialName The name of the credential.
*
* @param {object} parameters The parameters required to modify the credential
* (name and password)
*
* @param {string} [parameters.password] the current password for the
* credential and user with access to the data source. This is required if the
* requester is not the account owner.
*
* @param {string} [parameters.newPassword] the new password for the credential
* and user with access to the data source.
*
* @param {string} [parameters.uri] the URI identifier for the data source this
* credential can connect to in the format <hostname>:<port>
*
* @param {string} [parameters.userId] the object identifier for the user
* associated with this credential with access to the data source.
*
* @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 _updateCredential(accountName, databaseName, credentialName, parameters, 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 (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 (this.client.adlaCatalogDnsSuffix === null || this.client.adlaCatalogDnsSuffix === undefined || typeof this.client.adlaCatalogDnsSuffix.valueOf() !== 'string') {
throw new Error('this.client.adlaCatalogDnsSuffix cannot be null or undefined and it must be of type string.');
}
if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
throw new Error('databaseName cannot be null or undefined and it must be of type string.');
}
if (credentialName === null || credentialName === undefined || typeof credentialName.valueOf() !== 'string') {
throw new Error('credentialName cannot be null or undefined and it must be of type string.');
}
if (parameters === null || parameters === undefined) {
throw new Error('parameters cannot be null or undefined.');
}
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 (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('/') ? '' : '/') + 'catalog/usql/databases/{databaseName}/credentials/{credentialName}';
requestUrl = requestUrl.replace('{accountName}', accountName);
requestUrl = requestUrl.replace('{adlaCatalogDnsSuffix}', this.client.adlaCatalogDnsSuffix);
requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
requestUrl = requestUrl.replace('{credentialName}', encodeURIComponent(credentialName));
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 = 'PATCH';
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 (parameters !== null && parameters !== undefined) {
let requestModelMapper = new client.models['DataLakeAnalyticsCatalogCredentialUpdateParameters']().mapper();
requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
requestContent = JSON.stringify(requestModel);
}
} catch (error) {
let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
`payload - ${JSON.stringify(parameters, 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;
return callback(null, result, httpRequest, response);
});
}
/**
* Deletes the specified credential in the specified database
*
* @param {string} accountName The Azure Data Lake Analytics account upon which
* to execute catalog operations.
*
* @param {string} databaseName The name of the database containing the
* credential.
*
* @param {string} credentialName The name of the credential to delete
*
* @param {object} [options] Optional Parameters.
*
* @param {object} [options.parameters] The parameters to delete a credential
* if the current user is not the account owner.
*
* @param {string} [options.parameters.password] the current password for the
* credential and user with access to the data source. This is required if the
* requester is not the account owner.
*
* @param {boolean} [options.cascade] Indicates if the delete should be a
* cascading delete (which deletes all resources dependent on the credential as
* well as the credential) or not. If false will fail if there are any
* resources relying on the credential.
*
* @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 _deleteCredential(accountName, databaseName, credentialName, options, callback) {
/* jshint validthis: true */
let client = this.client;
if(!callback && typeof options === 'function') {
callback = options;
options = null;
}
if (!callback) {
throw new Error('