diff --git a/lib/services/searchManagement/LICENSE.txt b/lib/services/searchManagement/LICENSE.txt index 5431ba98b9..8f3d856145 100644 --- a/lib/services/searchManagement/LICENSE.txt +++ b/lib/services/searchManagement/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018 Microsoft +Copyright (c) 2019 Microsoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/services/searchManagement/lib/operations/index.d.ts b/lib/services/searchManagement/lib/operations/index.d.ts index ccef8a88d1..98d1703d36 100644 --- a/lib/services/searchManagement/lib/operations/index.d.ts +++ b/lib/services/searchManagement/lib/operations/index.d.ts @@ -1094,6 +1094,72 @@ export interface Services { listByResourceGroup(resourceGroupName: string, options: { searchManagementRequestOptions? : models.SearchManagementRequestOptions, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + /** + * Gets a list of all Search services in the given subscription. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.searchManagementRequestOptions] Additional + * parameters for the operation + * + * @param {uuid} [options.searchManagementRequestOptions.clientRequestId] A + * client-generated GUID value that identifies this request. If specified, this + * will be included in response information as a way to track the request. + * + * @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. + */ + listBySubscriptionWithHttpOperationResponse(options?: { searchManagementRequestOptions? : models.SearchManagementRequestOptions, customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Gets a list of all Search services in the given subscription. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.searchManagementRequestOptions] Additional + * parameters for the operation + * + * @param {uuid} [options.searchManagementRequestOptions.clientRequestId] A + * client-generated GUID value that identifies this request. If specified, this + * will be included in response information as a way to track the request. + * + * @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 {SearchServiceListResult} - 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. + * + * {SearchServiceListResult} [result] - The deserialized result object if an error did not occur. + * See {@link SearchServiceListResult} 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. + */ + listBySubscription(options?: { searchManagementRequestOptions? : models.SearchManagementRequestOptions, customHeaders? : { [headerName: string]: string; } }): Promise; + listBySubscription(callback: ServiceCallback): void; + listBySubscription(options: { searchManagementRequestOptions? : models.SearchManagementRequestOptions, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + /** * Checks whether or not the given Search service name is available for use. * Search service names must be globally unique since they are part of the diff --git a/lib/services/searchManagement/lib/operations/services.js b/lib/services/searchManagement/lib/operations/services.js index 1267c1075c..e9fd1a7d25 100644 --- a/lib/services/searchManagement/lib/operations/services.js +++ b/lib/services/searchManagement/lib/operations/services.js @@ -870,6 +870,163 @@ function _listByResourceGroup(resourceGroupName, options, callback) { }); } +/** + * Gets a list of all Search services in the given subscription. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.searchManagementRequestOptions] Additional + * parameters for the operation + * + * @param {uuid} [options.searchManagementRequestOptions.clientRequestId] A + * client-generated GUID value that identifies this request. If specified, this + * will be included in response information as a way to track the request. + * + * @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 SearchServiceListResult} 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 _listBySubscription(options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + let searchManagementRequestOptions = (options && options.searchManagementRequestOptions !== undefined) ? options.searchManagementRequestOptions : undefined; + // Validate + try { + 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.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') { + throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + let clientRequestId; + try { + if (searchManagementRequestOptions !== null && searchManagementRequestOptions !== undefined) + { + clientRequestId = searchManagementRequestOptions.clientRequestId; + if (clientRequestId !== null && clientRequestId !== undefined && !(typeof clientRequestId.valueOf() === 'string' && msRest.isValidUuid(clientRequestId))) { + throw new Error('clientRequestId must be of type string and must be a valid uuid.'); + } + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Search/searchServices'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + 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 (clientRequestId !== undefined && clientRequestId !== null) { + httpRequest.headers['x-ms-client-request-id'] = clientRequestId.toString(); + } + 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['SearchServiceListResult']().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); + }); +} + /** * Checks whether or not the given Search service name is available for use. * Search service names must be globally unique since they are part of the @@ -1323,6 +1480,7 @@ class Services { this._get = _get; this._deleteMethod = _deleteMethod; this._listByResourceGroup = _listByResourceGroup; + this._listBySubscription = _listBySubscription; this._checkNameAvailability = _checkNameAvailability; this._beginCreateOrUpdate = _beginCreateOrUpdate; } @@ -2033,6 +2191,99 @@ class Services { } } + /** + * Gets a list of all Search services in the given subscription. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.searchManagementRequestOptions] Additional + * parameters for the operation + * + * @param {uuid} [options.searchManagementRequestOptions.clientRequestId] A + * client-generated GUID value that identifies this request. If specified, this + * will be included in response information as a way to track the request. + * + * @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. + */ + listBySubscriptionWithHttpOperationResponse(options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listBySubscription(options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Gets a list of all Search services in the given subscription. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.searchManagementRequestOptions] Additional + * parameters for the operation + * + * @param {uuid} [options.searchManagementRequestOptions.clientRequestId] A + * client-generated GUID value that identifies this request. If specified, this + * will be included in response information as a way to track the request. + * + * @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 {SearchServiceListResult} - 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 SearchServiceListResult} 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. + */ + listBySubscription(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._listBySubscription(options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listBySubscription(options, optionalCallback); + } + } + /** * Checks whether or not the given Search service name is available for use. * Search service names must be globally unique since they are part of the