diff --git a/lib/services/applicationinsights/lib/lib/operations/index.d.ts b/lib/services/applicationinsights/lib/lib/operations/index.d.ts index 29d0386ff3..09810323cd 100644 --- a/lib/services/applicationinsights/lib/lib/operations/index.d.ts +++ b/lib/services/applicationinsights/lib/lib/operations/index.d.ts @@ -4156,6 +4156,71 @@ export interface WorkbooksOperations { export interface WorkbookOperations { + /** + * Get a single workbook by its resourceName. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} location The name of location where workbook is stored. + * + * @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. + */ + getWithHttpOperationResponse(resourceGroupName: string, resourceName: string, location: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Get a single workbook by its resourceName. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} location The name of location where workbook is stored. + * + * @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 {Workbook} - 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. + * + * {Workbook} [result] - The deserialized result object if an error did not occur. + * See {@link Workbook} 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. + */ + get(resourceGroupName: string, resourceName: string, location: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + get(resourceGroupName: string, resourceName: string, location: string, callback: ServiceCallback): void; + get(resourceGroupName: string, resourceName: string, location: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + /** * Delete a workbook. * @@ -4500,139 +4565,4 @@ export interface WorkbookOperations { update(resourceGroupName: string, resourceName: string, workbookProperties: models.Workbook, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; update(resourceGroupName: string, resourceName: string, workbookProperties: models.Workbook, callback: ServiceCallback): void; update(resourceGroupName: string, resourceName: string, workbookProperties: models.Workbook, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - - - /** - * Get a single workbook by its resourceName. - * - * @param {string} resourceName The name of the Application Insights component - * resource. - * - * @param {string} location The name of location where workbook is stored. - * - * @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. - */ - getWithHttpOperationResponse(resourceName: string, location: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; - - /** - * Get a single workbook by its resourceName. - * - * @param {string} resourceName The name of the Application Insights component - * resource. - * - * @param {string} location The name of location where workbook is stored. - * - * @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 {Workbook} - 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. - * - * {Workbook} [result] - The deserialized result object if an error did not occur. - * See {@link Workbook} 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. - */ - get(resourceName: string, location: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - get(resourceName: string, location: string, callback: ServiceCallback): void; - get(resourceName: string, location: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; - - - /** - * Gets a list of workbooks by sourceId. - * - * @param {string} sourceId Azure Resource Id that will fetch all linked - * workbooks. - * - * @param {string} category Category of workbook to return. Possible values - * include: 'workbook', 'TSG', 'performance', 'retention' - * - * @param {object} [options] Optional Parameters. - * - * @param {array} [options.tags] Tags presents on each workbook returned. - * - * @param {boolean} [options.canFetchContent] Flag indicating whether or not to - * return the full content for each applicable workbook. If false, only return - * summary content for workbooks. - * - * @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. - */ - listWithHttpOperationResponse(sourceId: string, category: string, options?: { tags? : string[], canFetchContent? : boolean, customHeaders? : { [headerName: string]: string; } }): Promise>; - - /** - * Gets a list of workbooks by sourceId. - * - * @param {string} sourceId Azure Resource Id that will fetch all linked - * workbooks. - * - * @param {string} category Category of workbook to return. Possible values - * include: 'workbook', 'TSG', 'performance', 'retention' - * - * @param {object} [options] Optional Parameters. - * - * @param {array} [options.tags] Tags presents on each workbook returned. - * - * @param {boolean} [options.canFetchContent] Flag indicating whether or not to - * return the full content for each applicable workbook. If false, only return - * summary content for workbooks. - * - * @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 {Array} - 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. - * - * {Array} [result] - The deserialized result object if an error did not occur. - * - * {WebResource} [request] - The HTTP Request object if an error did not occur. - * - * {http.IncomingMessage} [response] - The HTTP Response stream if an error did not occur. - */ - list(sourceId: string, category: string, options?: { tags? : string[], canFetchContent? : boolean, customHeaders? : { [headerName: string]: string; } }): Promise; - list(sourceId: string, category: string, callback: ServiceCallback): void; - list(sourceId: string, category: string, options: { tags? : string[], canFetchContent? : boolean, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } diff --git a/lib/services/applicationinsights/lib/lib/operations/workbookOperations.js b/lib/services/applicationinsights/lib/lib/operations/workbookOperations.js index bc273d8528..1563f8f8b5 100644 --- a/lib/services/applicationinsights/lib/lib/operations/workbookOperations.js +++ b/lib/services/applicationinsights/lib/lib/operations/workbookOperations.js @@ -15,7 +15,7 @@ const msRestAzure = require('ms-rest-azure'); const WebResource = msRest.WebResource; /** - * Delete a workbook. + * Get a single workbook by its resourceName. * * @param {string} resourceGroupName The name of the resource group. * @@ -35,13 +35,14 @@ const WebResource = msRest.WebResource; * * {Error} err - The Error object if an error occurred, null otherwise. * - * {null} [result] - The deserialized result object if an error did not occur. + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link Workbook} 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 _deleteMethod(resourceGroupName, resourceName, location, options, callback) { +function _get(resourceGroupName, resourceName, location, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -90,7 +91,7 @@ function _deleteMethod(resourceGroupName, resourceName, location, options, callb // Create HTTP transport objects let httpRequest = new WebResource(); - httpRequest.method = 'DELETE'; + httpRequest.method = 'GET'; httpRequest.url = requestUrl; httpRequest.headers = {}; // Set Headers @@ -115,7 +116,7 @@ function _deleteMethod(resourceGroupName, resourceName, location, options, callb return callback(err); } let statusCode = response.statusCode; - if (statusCode !== 201 && statusCode !== 204) { + if (statusCode !== 200) { let error = new Error(responseBody); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -144,58 +145,37 @@ function _deleteMethod(resourceGroupName, resourceName, location, options, callb // 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['Workbook']().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); }); } /** - * Create a new workbook. + * Delete a workbook. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} resourceName The name of the Application Insights component * resource. * - * @param {object} workbookProperties Properties that need to be specified to - * create a new workbook. - * - * @param {string} [workbookProperties.kind] The kind of workbook. Choices are - * user and shared. Possible values include: 'user', 'shared' - * - * @param {string} workbookProperties.workbookName The user-defined name of the - * workbook. - * - * @param {string} workbookProperties.serializedData Configuration of this - * particular workbook. Configuration data is a string containing valid JSON - * - * @param {string} [workbookProperties.version] This instance's version of the - * data model. This can change as new features are added that can be marked - * workbook. - * - * @param {string} workbookProperties.workbookId Internally assigned unique id - * of the workbook definition. - * - * @param {string} workbookProperties.sharedTypeKind Enum indicating if this - * workbook definition is owned by a specific user or is shared between all - * users with access to the Application Insights component. Possible values - * include: 'user', 'shared' - * - * @param {string} workbookProperties.category Workbook category, as defined by - * the user at creation time. - * - * @param {array} [workbookProperties.workbookTags] A list of 0 or more tags - * that are associated with this workbook definition - * - * @param {string} workbookProperties.userId Unique user id of the specific - * user that owns this workbook. - * - * @param {string} [workbookProperties.sourceResourceId] Optional resourceId - * for a source resource. - * - * @param {string} workbookProperties.location Resource location - * - * @param {object} [workbookProperties.tags] Resource tags + * @param {string} location The name of location where workbook is stored. * * @param {object} [options] Optional Parameters. * @@ -208,14 +188,13 @@ function _deleteMethod(resourceGroupName, resourceName, location, options, callb * * {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 Workbook} for more information. + * {null} [result] - The deserialized result object if an error did not occur. * * {object} [request] - The HTTP Request object if an error did not occur. * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _createOrUpdate(resourceGroupName, resourceName, workbookProperties, options, callback) { +function _deleteMethod(resourceGroupName, resourceName, location, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -236,12 +215,12 @@ function _createOrUpdate(resourceGroupName, resourceName, workbookProperties, op if (resourceName === null || resourceName === undefined || typeof resourceName.valueOf() !== 'string') { throw new Error('resourceName 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 (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 (workbookProperties === null || workbookProperties === undefined) { - throw new Error('workbookProperties 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.'); } @@ -256,6 +235,7 @@ function _createOrUpdate(resourceGroupName, resourceName, workbookProperties, op requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName)); let queryParameters = []; + queryParameters.push('location=' + encodeURIComponent(location)); queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); if (queryParameters.length > 0) { requestUrl += '?' + queryParameters.join('&'); @@ -263,7 +243,7 @@ function _createOrUpdate(resourceGroupName, resourceName, workbookProperties, op // Create HTTP transport objects let httpRequest = new WebResource(); - httpRequest.method = 'PUT'; + httpRequest.method = 'DELETE'; httpRequest.url = requestUrl; httpRequest.headers = {}; // Set Headers @@ -281,28 +261,14 @@ function _createOrUpdate(resourceGroupName, resourceName, workbookProperties, op } } } - // Serialize Request - let requestContent = null; - let requestModel = null; - try { - if (workbookProperties !== null && workbookProperties !== undefined) { - let requestModelMapper = new client.models['Workbook']().mapper(); - requestModel = client.serialize(requestModelMapper, workbookProperties, 'workbookProperties'); - requestContent = JSON.stringify(requestModel); - } - } catch (error) { - let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + - `payload - ${JSON.stringify(workbookProperties, null, 2)}.`); - return callback(serializationError); - } - httpRequest.body = requestContent; + httpRequest.body = null; // Send Request return client.pipeline(httpRequest, (err, response, responseBody) => { if (err) { return callback(err); } let statusCode = response.statusCode; - if (statusCode !== 200 && statusCode !== 201) { + if (statusCode !== 201 && statusCode !== 204) { let error = new Error(responseBody); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -331,47 +297,13 @@ function _createOrUpdate(resourceGroupName, resourceName, workbookProperties, op // 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['Workbook']().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); - } - } - // Deserialize Response - if (statusCode === 201) { - let parsedResponse = null; - try { - parsedResponse = JSON.parse(responseBody); - result = JSON.parse(responseBody); - if (parsedResponse !== null && parsedResponse !== undefined) { - let resultMapper = new client.models['Workbook']().mapper(); - result = client.deserialize(resultMapper, parsedResponse, 'result'); - } - } catch (error) { - let deserializationError1 = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); - deserializationError1.request = msRest.stripRequest(httpRequest); - deserializationError1.response = msRest.stripResponse(response); - return callback(deserializationError1); - } - } return callback(null, result, httpRequest, response); }); } /** - * Updates a workbook that has already been added. + * Create a new workbook. * * @param {string} resourceGroupName The name of the resource group. * @@ -436,7 +368,7 @@ function _createOrUpdate(resourceGroupName, resourceName, workbookProperties, op * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _update(resourceGroupName, resourceName, workbookProperties, options, callback) { +function _createOrUpdate(resourceGroupName, resourceName, workbookProperties, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -484,7 +416,7 @@ function _update(resourceGroupName, resourceName, workbookProperties, options, c // Create HTTP transport objects let httpRequest = new WebResource(); - httpRequest.method = 'PATCH'; + httpRequest.method = 'PUT'; httpRequest.url = requestUrl; httpRequest.headers = {}; // Set Headers @@ -523,7 +455,7 @@ function _update(resourceGroupName, resourceName, workbookProperties, options, c return callback(err); } let statusCode = response.statusCode; - if (statusCode !== 200) { + if (statusCode !== 200 && statusCode !== 201) { let error = new Error(responseBody); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -569,18 +501,75 @@ function _update(resourceGroupName, resourceName, workbookProperties, options, c return callback(deserializationError); } } + // Deserialize Response + if (statusCode === 201) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['Workbook']().mapper(); + result = client.deserialize(resultMapper, parsedResponse, 'result'); + } + } catch (error) { + let deserializationError1 = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); + deserializationError1.request = msRest.stripRequest(httpRequest); + deserializationError1.response = msRest.stripResponse(response); + return callback(deserializationError1); + } + } return callback(null, result, httpRequest, response); }); } /** - * Get a single workbook by its resourceName. + * Updates a workbook that has already been added. + * + * @param {string} resourceGroupName The name of the resource group. * * @param {string} resourceName The name of the Application Insights component * resource. * - * @param {string} location The name of location where workbook is stored. + * @param {object} workbookProperties Properties that need to be specified to + * create a new workbook. + * + * @param {string} [workbookProperties.kind] The kind of workbook. Choices are + * user and shared. Possible values include: 'user', 'shared' + * + * @param {string} workbookProperties.workbookName The user-defined name of the + * workbook. + * + * @param {string} workbookProperties.serializedData Configuration of this + * particular workbook. Configuration data is a string containing valid JSON + * + * @param {string} [workbookProperties.version] This instance's version of the + * data model. This can change as new features are added that can be marked + * workbook. + * + * @param {string} workbookProperties.workbookId Internally assigned unique id + * of the workbook definition. + * + * @param {string} workbookProperties.sharedTypeKind Enum indicating if this + * workbook definition is owned by a specific user or is shared between all + * users with access to the Application Insights component. Possible values + * include: 'user', 'shared' + * + * @param {string} workbookProperties.category Workbook category, as defined by + * the user at creation time. + * + * @param {array} [workbookProperties.workbookTags] A list of 0 or more tags + * that are associated with this workbook definition + * + * @param {string} workbookProperties.userId Unique user id of the specific + * user that owns this workbook. + * + * @param {string} [workbookProperties.sourceResourceId] Optional resourceId + * for a source resource. + * + * @param {string} workbookProperties.location Resource location + * + * @param {object} [workbookProperties.tags] Resource tags * * @param {object} [options] Optional Parameters. * @@ -600,7 +589,7 @@ function _update(resourceGroupName, resourceName, workbookProperties, options, c * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _get(resourceName, location, options, callback) { +function _update(resourceGroupName, resourceName, workbookProperties, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -615,15 +604,18 @@ function _get(resourceName, location, options, callback) { if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') { throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.'); } + if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') { + throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.'); + } if (resourceName === null || resourceName === undefined || typeof resourceName.valueOf() !== 'string') { throw new Error('resourceName 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 (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 (workbookProperties === null || workbookProperties === undefined) { + throw new Error('workbookProperties 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.'); } @@ -633,11 +625,11 @@ function _get(resourceName, location, options, callback) { // Construct URL let baseUrl = this.client.baseUri; - let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/microsoft.insights/workbooks/{resourceName}'; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroup/{resourceGroupName}/providers/microsoft.insights/workbooks/{resourceName}'; requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName)); let queryParameters = []; - queryParameters.push('location=' + encodeURIComponent(location)); queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); if (queryParameters.length > 0) { requestUrl += '?' + queryParameters.join('&'); @@ -645,7 +637,7 @@ function _get(resourceName, location, options, callback) { // Create HTTP transport objects let httpRequest = new WebResource(); - httpRequest.method = 'GET'; + httpRequest.method = 'PATCH'; httpRequest.url = requestUrl; httpRequest.headers = {}; // Set Headers @@ -663,7 +655,21 @@ function _get(resourceName, location, options, callback) { } } } - httpRequest.body = null; + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (workbookProperties !== null && workbookProperties !== undefined) { + let requestModelMapper = new client.models['Workbook']().mapper(); + requestModel = client.serialize(requestModelMapper, workbookProperties, 'workbookProperties'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(workbookProperties, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; // Send Request return client.pipeline(httpRequest, (err, response, responseBody) => { if (err) { @@ -721,191 +727,6 @@ function _get(resourceName, location, options, callback) { }); } -/** - * Gets a list of workbooks by sourceId. - * - * @param {string} sourceId Azure Resource Id that will fetch all linked - * workbooks. - * - * @param {string} category Category of workbook to return. Possible values - * include: 'workbook', 'TSG', 'performance', 'retention' - * - * @param {object} [options] Optional Parameters. - * - * @param {array} [options.tags] Tags presents on each workbook returned. - * - * @param {boolean} [options.canFetchContent] Flag indicating whether or not to - * return the full content for each applicable workbook. If false, only return - * summary content for workbooks. - * - * @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. - * - * {array} [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 _list(sourceId, category, 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 tags = (options && options.tags !== undefined) ? options.tags : undefined; - let canFetchContent = (options && options.canFetchContent !== undefined) ? options.canFetchContent : undefined; - // 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 (sourceId === null || sourceId === undefined || typeof sourceId.valueOf() !== 'string') { - throw new Error('sourceId cannot be null or undefined and it must be of type string.'); - } - if (category === null || category === undefined || typeof category.valueOf() !== 'string') { - throw new Error('category cannot be null or undefined and it must be of type string.'); - } - if (Array.isArray(tags)) { - for (let i = 0; i < tags.length; i++) { - if (tags[i] !== null && tags[i] !== undefined && typeof tags[i].valueOf() !== 'string') { - throw new Error('tags[i] must be of type string.'); - } - } - } - if (canFetchContent !== null && canFetchContent !== undefined && typeof canFetchContent !== 'boolean') { - throw new Error('canFetchContent must be of type boolean.'); - } - 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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/microsoft.insights/workbooks'; - requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); - let queryParameters = []; - queryParameters.push('sourceId=' + encodeURIComponent(sourceId)); - queryParameters.push('category=' + encodeURIComponent(category)); - if (tags !== null && tags !== undefined) { - queryParameters.push('tags=' + encodeURIComponent(tags.join(','))); - } - if (canFetchContent !== null && canFetchContent !== undefined) { - queryParameters.push('canFetchContent=' + encodeURIComponent(canFetchContent.toString())); - } - 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) { - 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['WorkbookError']().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 = { - required: false, - serializedName: 'parsedResponse', - type: { - name: 'Sequence', - element: { - required: false, - serializedName: 'WorkbookElementType', - type: { - name: 'Composite', - className: 'Workbook' - } - } - } - }; - 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 WorkbookOperations. */ class WorkbookOperations { /** @@ -914,11 +735,102 @@ class WorkbookOperations { */ constructor(client) { this.client = client; + this._get = _get; this._deleteMethod = _deleteMethod; this._createOrUpdate = _createOrUpdate; this._update = _update; - this._get = _get; - this._list = _list; + } + + /** + * Get a single workbook by its resourceName. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} location The name of location where workbook is stored. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @returns {Promise} A promise is returned + * + * @resolve {HttpOperationResponse} - The deserialized result object. + * + * @reject {Error} - The error object. + */ + getWithHttpOperationResponse(resourceGroupName, resourceName, location, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(resourceGroupName, resourceName, location, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Get a single workbook by its resourceName. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} location The name of location where workbook is stored. + * + * @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 {Workbook} - 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 Workbook} 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. + */ + get(resourceGroupName, resourceName, location, 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._get(resourceGroupName, resourceName, location, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._get(resourceGroupName, resourceName, location, options, optionalCallback); + } } /** @@ -1348,195 +1260,6 @@ class WorkbookOperations { } } - /** - * Get a single workbook by its resourceName. - * - * @param {string} resourceName The name of the Application Insights component - * resource. - * - * @param {string} location The name of location where workbook is stored. - * - * @param {object} [options] Optional Parameters. - * - * @param {object} [options.customHeaders] Headers that will be added to the - * request - * - * @returns {Promise} A promise is returned - * - * @resolve {HttpOperationResponse} - The deserialized result object. - * - * @reject {Error} - The error object. - */ - getWithHttpOperationResponse(resourceName, location, options) { - let client = this.client; - let self = this; - return new Promise((resolve, reject) => { - self._get(resourceName, location, options, (err, result, request, response) => { - let httpOperationResponse = new msRest.HttpOperationResponse(request, response); - httpOperationResponse.body = result; - if (err) { reject(err); } - else { resolve(httpOperationResponse); } - return; - }); - }); - } - - /** - * Get a single workbook by its resourceName. - * - * @param {string} resourceName The name of the Application Insights component - * resource. - * - * @param {string} location The name of location where workbook is stored. - * - * @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 {Workbook} - 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 Workbook} 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. - */ - get(resourceName, location, 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._get(resourceName, location, options, (err, result, request, response) => { - if (err) { reject(err); } - else { resolve(result); } - return; - }); - }); - } else { - return self._get(resourceName, location, options, optionalCallback); - } - } - - /** - * Gets a list of workbooks by sourceId. - * - * @param {string} sourceId Azure Resource Id that will fetch all linked - * workbooks. - * - * @param {string} category Category of workbook to return. Possible values - * include: 'workbook', 'TSG', 'performance', 'retention' - * - * @param {object} [options] Optional Parameters. - * - * @param {array} [options.tags] Tags presents on each workbook returned. - * - * @param {boolean} [options.canFetchContent] Flag indicating whether or not to - * return the full content for each applicable workbook. If false, only return - * summary content for workbooks. - * - * @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. - */ - listWithHttpOperationResponse(sourceId, category, options) { - let client = this.client; - let self = this; - return new Promise((resolve, reject) => { - self._list(sourceId, category, 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 workbooks by sourceId. - * - * @param {string} sourceId Azure Resource Id that will fetch all linked - * workbooks. - * - * @param {string} category Category of workbook to return. Possible values - * include: 'workbook', 'TSG', 'performance', 'retention' - * - * @param {object} [options] Optional Parameters. - * - * @param {array} [options.tags] Tags presents on each workbook returned. - * - * @param {boolean} [options.canFetchContent] Flag indicating whether or not to - * return the full content for each applicable workbook. If false, only return - * summary content for workbooks. - * - * @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 {Array} - 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. - * - * {array} [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. - */ - list(sourceId, category, options, optionalCallback) { - let client = this.client; - let self = this; - if (!optionalCallback && typeof options === 'function') { - optionalCallback = options; - options = null; - } - if (!optionalCallback) { - return new Promise((resolve, reject) => { - self._list(sourceId, category, options, (err, result, request, response) => { - if (err) { reject(err); } - else { resolve(result); } - return; - }); - }); - } else { - return self._list(sourceId, category, options, optionalCallback); - } - } - } module.exports = WorkbookOperations;