From 2792fc6af692c91bfd054b5fe894ed27ae789640 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Wed, 18 Apr 2018 18:04:25 +0000 Subject: [PATCH] Generated from 12a39625cc68eb8eb32d3f864fbc025629864998 Resolved the merge conflicts with readme.md --- .../applicationInsightsManagementClient.d.ts | 1 + .../applicationInsightsManagementClient.js | 1 + ...plicationInsightsComponentAnalyticsItem.js | 132 ++ ...nsightsComponentAnalyticsItemProperties.js | 54 + .../lib/models/componentPurgeBodyFilters.js | 18 +- .../applicationinsights/lib/models/index.d.ts | 61 +- .../applicationinsights/lib/models/index.js | 2 + .../lib/operations/analyticsItem.js | 1280 +++++++++++++++++ .../lib/operations/components.js | 249 ++-- .../lib/operations/index.d.ts | 661 ++++++--- .../lib/operations/index.js | 1 + .../lib/operations/workbookOperations.js | 707 +++------ 12 files changed, 2362 insertions(+), 805 deletions(-) create mode 100644 lib/services/applicationinsights/lib/models/applicationInsightsComponentAnalyticsItem.js create mode 100644 lib/services/applicationinsights/lib/models/applicationInsightsComponentAnalyticsItemProperties.js create mode 100644 lib/services/applicationinsights/lib/operations/analyticsItem.js diff --git a/lib/services/applicationinsights/lib/applicationInsightsManagementClient.d.ts b/lib/services/applicationinsights/lib/applicationInsightsManagementClient.d.ts index 4b16ffe9a7..5503502dc0 100644 --- a/lib/services/applicationinsights/lib/applicationInsightsManagementClient.d.ts +++ b/lib/services/applicationinsights/lib/applicationInsightsManagementClient.d.ts @@ -71,6 +71,7 @@ export default class ApplicationInsightsManagementClient extends AzureServiceCli favorite: operations.Favorite; webTestLocations: operations.WebTestLocations; webTests: operations.WebTests; + analyticsItem: operations.AnalyticsItem; workbooksOperations: operations.WorkbooksOperations; workbookOperations: operations.WorkbookOperations; } diff --git a/lib/services/applicationinsights/lib/applicationInsightsManagementClient.js b/lib/services/applicationinsights/lib/applicationInsightsManagementClient.js index 56f8314e01..c4599eeba5 100644 --- a/lib/services/applicationinsights/lib/applicationInsightsManagementClient.js +++ b/lib/services/applicationinsights/lib/applicationInsightsManagementClient.js @@ -87,6 +87,7 @@ class ApplicationInsightsManagementClient extends ServiceClient { this.favorite = new operations.Favorite(this); this.webTestLocations = new operations.WebTestLocations(this); this.webTests = new operations.WebTests(this); + this.analyticsItem = new operations.AnalyticsItem(this); this.workbooksOperations = new operations.WorkbooksOperations(this); this.workbookOperations = new operations.WorkbookOperations(this); this.models = models; diff --git a/lib/services/applicationinsights/lib/models/applicationInsightsComponentAnalyticsItem.js b/lib/services/applicationinsights/lib/models/applicationInsightsComponentAnalyticsItem.js new file mode 100644 index 0000000000..8722f17c8a --- /dev/null +++ b/lib/services/applicationinsights/lib/models/applicationInsightsComponentAnalyticsItem.js @@ -0,0 +1,132 @@ +/* + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is + * regenerated. + */ + +'use strict'; + +const models = require('./index'); + +/** + * Properties that define an Analytics item that is associated to an + * Application Insights component. + * + */ +class ApplicationInsightsComponentAnalyticsItem { + /** + * Create a ApplicationInsightsComponentAnalyticsItem. + * @member {string} [id] Internally assigned unique id of the item + * definition. + * @member {string} [name] The user-defined name of the item. + * @member {string} [content] The content of this item + * @member {string} [version] This instance's version of the data model. This + * can change as new features are added. + * @member {string} [scope] Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'shared', 'user' + * @member {string} [type] Enum indicating the type of the Analytics item. + * Possible values include: 'query', 'function', 'folder', 'recent' + * @member {string} [timeCreated] Date and time in UTC when this item was + * created. + * @member {string} [timeModified] Date and time in UTC of the last + * modification that was made to this item. + * @member {object} [properties] + * @member {string} [properties.functionAlias] A function alias, used when + * the type of the item is Function + */ + constructor() { + } + + /** + * Defines the metadata of ApplicationInsightsComponentAnalyticsItem + * + * @returns {object} metadata of ApplicationInsightsComponentAnalyticsItem + * + */ + mapper() { + return { + required: false, + serializedName: 'ApplicationInsightsComponentAnalyticsItem', + type: { + name: 'Composite', + className: 'ApplicationInsightsComponentAnalyticsItem', + modelProperties: { + id: { + required: false, + serializedName: 'Id', + type: { + name: 'String' + } + }, + name: { + required: false, + serializedName: 'Name', + type: { + name: 'String' + } + }, + content: { + required: false, + serializedName: 'Content', + type: { + name: 'String' + } + }, + version: { + required: false, + readOnly: true, + serializedName: 'Version', + type: { + name: 'String' + } + }, + scope: { + required: false, + serializedName: 'Scope', + type: { + name: 'String' + } + }, + type: { + required: false, + serializedName: 'Type', + type: { + name: 'String' + } + }, + timeCreated: { + required: false, + readOnly: true, + serializedName: 'TimeCreated', + type: { + name: 'String' + } + }, + timeModified: { + required: false, + readOnly: true, + serializedName: 'TimeModified', + type: { + name: 'String' + } + }, + properties: { + required: false, + serializedName: 'Properties', + type: { + name: 'Composite', + className: 'ApplicationInsightsComponentAnalyticsItemProperties' + } + } + } + } + }; + } +} + +module.exports = ApplicationInsightsComponentAnalyticsItem; diff --git a/lib/services/applicationinsights/lib/models/applicationInsightsComponentAnalyticsItemProperties.js b/lib/services/applicationinsights/lib/models/applicationInsightsComponentAnalyticsItemProperties.js new file mode 100644 index 0000000000..181fcfbb94 --- /dev/null +++ b/lib/services/applicationinsights/lib/models/applicationInsightsComponentAnalyticsItemProperties.js @@ -0,0 +1,54 @@ +/* + * 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'; + +/** + * A set of properties that can be defined in the context of a specific item + * type. Each type may have its own properties. + * + */ +class ApplicationInsightsComponentAnalyticsItemProperties { + /** + * Create a ApplicationInsightsComponentAnalyticsItemProperties. + * @member {string} [functionAlias] A function alias, used when the type of + * the item is Function + */ + constructor() { + } + + /** + * Defines the metadata of ApplicationInsightsComponentAnalyticsItemProperties + * + * @returns {object} metadata of ApplicationInsightsComponentAnalyticsItemProperties + * + */ + mapper() { + return { + required: false, + serializedName: 'ApplicationInsightsComponentAnalyticsItemProperties', + type: { + name: 'Composite', + className: 'ApplicationInsightsComponentAnalyticsItemProperties', + modelProperties: { + functionAlias: { + required: false, + serializedName: 'functionAlias', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = ApplicationInsightsComponentAnalyticsItemProperties; diff --git a/lib/services/applicationinsights/lib/models/componentPurgeBodyFilters.js b/lib/services/applicationinsights/lib/models/componentPurgeBodyFilters.js index 832ecedb3f..d691a0b4ca 100644 --- a/lib/services/applicationinsights/lib/models/componentPurgeBodyFilters.js +++ b/lib/services/applicationinsights/lib/models/componentPurgeBodyFilters.js @@ -19,8 +19,11 @@ class ComponentPurgeBodyFilters { * Create a ComponentPurgeBodyFilters. * @member {string} [column] The column of the table over which the given * query should run - * @member {string} [filter] A query to to run over the provided table and - * column to purge the corresponding data. + * @member {string} [operator] A query operator to evaluate over the provided + * column and value(s). + * @member {object} [value] the value for the operator to function over. This + * can be a number (e.g., > 100), a string (timestamp >= '2017-09-01') or + * array of values. */ constructor() { } @@ -46,12 +49,19 @@ class ComponentPurgeBodyFilters { name: 'String' } }, - filter: { + operator: { required: false, - serializedName: 'filter', + serializedName: 'operator', type: { name: 'String' } + }, + value: { + required: false, + serializedName: 'value', + type: { + name: 'Object' + } } } } diff --git a/lib/services/applicationinsights/lib/models/index.d.ts b/lib/services/applicationinsights/lib/models/index.d.ts index f6b6a75f1f..6c20629a56 100644 --- a/lib/services/applicationinsights/lib/models/index.d.ts +++ b/lib/services/applicationinsights/lib/models/index.d.ts @@ -629,12 +629,16 @@ export interface ApplicationInsightsComponent extends Resource { * * @member {string} [column] The column of the table over which the given query * should run - * @member {string} [filter] A query to to run over the provided table and - * column to purge the corresponding data. + * @member {string} [operator] A query operator to evaluate over the provided + * column and value(s). + * @member {object} [value] the value for the operator to function over. This + * can be a number (e.g., > 100), a string (timestamp >= '2017-09-01') or array + * of values. */ export interface ComponentPurgeBodyFilters { column?: string; - filter?: string; + operator?: string; + value?: any; } /** @@ -876,6 +880,57 @@ export interface WebTest extends Resource { readonly provisioningState?: string; } +/** + * @class + * Initializes a new instance of the ApplicationInsightsComponentAnalyticsItemProperties class. + * @constructor + * A set of properties that can be defined in the context of a specific item + * type. Each type may have its own properties. + * + * @member {string} [functionAlias] A function alias, used when the type of the + * item is Function + */ +export interface ApplicationInsightsComponentAnalyticsItemProperties { + functionAlias?: string; +} + +/** + * @class + * Initializes a new instance of the ApplicationInsightsComponentAnalyticsItem class. + * @constructor + * Properties that define an Analytics item that is associated to an + * Application Insights component. + * + * @member {string} [id] Internally assigned unique id of the item definition. + * @member {string} [name] The user-defined name of the item. + * @member {string} [content] The content of this item + * @member {string} [version] This instance's version of the data model. This + * can change as new features are added. + * @member {string} [scope] Enum indicating if this item definition is owned by + * a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'shared', 'user' + * @member {string} [type] Enum indicating the type of the Analytics item. + * Possible values include: 'query', 'function', 'folder', 'recent' + * @member {string} [timeCreated] Date and time in UTC when this item was + * created. + * @member {string} [timeModified] Date and time in UTC of the last + * modification that was made to this item. + * @member {object} [properties] + * @member {string} [properties.functionAlias] A function alias, used when the + * type of the item is Function + */ +export interface ApplicationInsightsComponentAnalyticsItem { + id?: string; + name?: string; + content?: string; + readonly version?: string; + scope?: string; + type?: string; + readonly timeCreated?: string; + readonly timeModified?: string; + properties?: ApplicationInsightsComponentAnalyticsItemProperties; +} + /** * @class * Initializes a new instance of the Workbook class. diff --git a/lib/services/applicationinsights/lib/models/index.js b/lib/services/applicationinsights/lib/models/index.js index 42328e863f..61b83d139e 100644 --- a/lib/services/applicationinsights/lib/models/index.js +++ b/lib/services/applicationinsights/lib/models/index.js @@ -52,6 +52,8 @@ exports.ApplicationInsightsComponentWebTestLocation = require('./applicationInsi exports.WebTestGeolocation = require('./webTestGeolocation'); exports.WebTestPropertiesConfiguration = require('./webTestPropertiesConfiguration'); exports.WebTest = require('./webTest'); +exports.ApplicationInsightsComponentAnalyticsItemProperties = require('./applicationInsightsComponentAnalyticsItemProperties'); +exports.ApplicationInsightsComponentAnalyticsItem = require('./applicationInsightsComponentAnalyticsItem'); exports.Workbook = require('./workbook'); exports.Workbooks = require('./workbooks'); exports.LinkProperties = require('./linkProperties'); diff --git a/lib/services/applicationinsights/lib/operations/analyticsItem.js b/lib/services/applicationinsights/lib/operations/analyticsItem.js new file mode 100644 index 0000000000..80cf422ac2 --- /dev/null +++ b/lib/services/applicationinsights/lib/operations/analyticsItem.js @@ -0,0 +1,1280 @@ +/* + * 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; + +/** + * Gets a list of Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.scope] Enum indicating if this item definition is + * owned by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'shared', 'user' + * + * @param {string} [options.type] Enum indicating the type of the Analytics + * item. Possible values include: 'none', 'query', 'function', 'folder', + * 'recent' + * + * @param {boolean} [options.includeContent] Flag indicating whether or not to + * return the content of each applicable item. If false, only return the item + * information. + * + * @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(resourceGroupName, resourceName, scopePath, 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 scope = (options && options.scope !== undefined) ? options.scope : 'shared'; + let type = (options && options.type !== undefined) ? options.type : 'none'; + let includeContent = (options && options.includeContent !== undefined) ? options.includeContent : 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 (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 (scopePath === null || scopePath === undefined || typeof scopePath.valueOf() !== 'string') { + throw new Error('scopePath 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 (scope !== null && scope !== undefined && typeof scope.valueOf() !== 'string') { + throw new Error('scope must be of type string.'); + } + if (type !== null && type !== undefined && typeof type.valueOf() !== 'string') { + throw new Error('type must be of type string.'); + } + if (includeContent !== null && includeContent !== undefined && typeof includeContent !== 'boolean') { + throw new Error('includeContent must be of type boolean.'); + } + 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}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/{scopePath}'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName)); + requestUrl = requestUrl.replace('{scopePath}', encodeURIComponent(scopePath)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (scope !== null && scope !== undefined) { + queryParameters.push('scope=' + encodeURIComponent(scope)); + } + if (type !== null && type !== undefined) { + queryParameters.push('type=' + encodeURIComponent(type)); + } + if (includeContent !== null && includeContent !== undefined) { + queryParameters.push('includeContent=' + encodeURIComponent(includeContent.toString())); + } + 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 = { + required: false, + serializedName: 'parsedResponse', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'ApplicationInsightsComponentAnalyticsItemElementType', + type: { + name: 'Composite', + className: 'ApplicationInsightsComponentAnalyticsItem' + } + } + } + }; + 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); + }); +} + +/** + * Gets a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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 ApplicationInsightsComponentAnalyticsItem} + * 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 _get(resourceGroupName, resourceName, scopePath, 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 id = (options && options.id !== undefined) ? options.id : undefined; + let name = (options && options.name !== undefined) ? options.name : 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 (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 (scopePath === null || scopePath === undefined || typeof scopePath.valueOf() !== 'string') { + throw new Error('scopePath 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 (id !== null && id !== undefined && typeof id.valueOf() !== 'string') { + throw new Error('id must be of type string.'); + } + if (name !== null && name !== undefined && typeof name.valueOf() !== 'string') { + throw new Error('name 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}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/{scopePath}/item'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName)); + requestUrl = requestUrl.replace('{scopePath}', encodeURIComponent(scopePath)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (id !== null && id !== undefined) { + queryParameters.push('id=' + encodeURIComponent(id)); + } + if (name !== null && name !== undefined) { + queryParameters.push('name=' + encodeURIComponent(name)); + } + 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['ApplicationInsightsComponentAnalyticsItem']().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); + }); +} + +/** + * Adds or Updates a specific Analytics Item within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} itemProperties Properties that need to be specified to + * create a new item and add it to an Application Insights component. + * + * @param {string} [itemProperties.id] Internally assigned unique id of the + * item definition. + * + * @param {string} [itemProperties.name] The user-defined name of the item. + * + * @param {string} [itemProperties.content] The content of this item + * + * @param {string} [itemProperties.scope] Enum indicating if this item + * definition is owned by a specific user or is shared between all users with + * access to the Application Insights component. Possible values include: + * 'shared', 'user' + * + * @param {string} [itemProperties.type] Enum indicating the type of the + * Analytics item. Possible values include: 'query', 'function', 'folder', + * 'recent' + * + * @param {object} [itemProperties.properties] + * + * @param {string} [itemProperties.properties.functionAlias] A function alias, + * used when the type of the item is Function + * + * @param {object} [options] Optional Parameters. + * + * @param {boolean} [options.overrideItem] Flag indicating whether or not to + * force save an item. This allows overriding an item if it already exists. + * + * @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 ApplicationInsightsComponentAnalyticsItem} + * 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 _put(resourceGroupName, resourceName, scopePath, itemProperties, 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 overrideItem = (options && options.overrideItem !== undefined) ? options.overrideItem : 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 (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 (scopePath === null || scopePath === undefined || typeof scopePath.valueOf() !== 'string') { + throw new Error('scopePath 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 (overrideItem !== null && overrideItem !== undefined && typeof overrideItem !== 'boolean') { + throw new Error('overrideItem must be of type boolean.'); + } + if (itemProperties === null || itemProperties === undefined) { + throw new Error('itemProperties cannot be null or undefined.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/{scopePath}/item'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName)); + requestUrl = requestUrl.replace('{scopePath}', encodeURIComponent(scopePath)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (overrideItem !== null && overrideItem !== undefined) { + queryParameters.push('overrideItem=' + encodeURIComponent(overrideItem.toString())); + } + 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 (itemProperties !== null && itemProperties !== undefined) { + let requestModelMapper = new client.models['ApplicationInsightsComponentAnalyticsItem']().mapper(); + requestModel = client.serialize(requestModelMapper, itemProperties, 'itemProperties'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(itemProperties, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error; + if (parsedErrorResponse.code) error.code = parsedErrorResponse.code; + if (parsedErrorResponse.message) error.message = parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['CloudError']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['ApplicationInsightsComponentAnalyticsItem']().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 a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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 _deleteMethod(resourceGroupName, resourceName, scopePath, 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 id = (options && options.id !== undefined) ? options.id : undefined; + let name = (options && options.name !== undefined) ? options.name : 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 (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 (scopePath === null || scopePath === undefined || typeof scopePath.valueOf() !== 'string') { + throw new Error('scopePath 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 (id !== null && id !== undefined && typeof id.valueOf() !== 'string') { + throw new Error('id must be of type string.'); + } + if (name !== null && name !== undefined && typeof name.valueOf() !== 'string') { + throw new Error('name 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}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/components/{resourceName}/{scopePath}/item'; + requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); + requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); + requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName)); + requestUrl = requestUrl.replace('{scopePath}', encodeURIComponent(scopePath)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (id !== null && id !== undefined) { + queryParameters.push('id=' + encodeURIComponent(id)); + } + if (name !== null && name !== undefined) { + queryParameters.push('name=' + encodeURIComponent(name)); + } + 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); + }); +} + +/** Class representing a AnalyticsItem. */ +class AnalyticsItem { + /** + * Create a AnalyticsItem. + * @param {ApplicationInsightsManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._list = _list; + this._get = _get; + this._put = _put; + this._deleteMethod = _deleteMethod; + } + + /** + * Gets a list of Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.scope] Enum indicating if this item definition is + * owned by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'shared', 'user' + * + * @param {string} [options.type] Enum indicating the type of the Analytics + * item. Possible values include: 'none', 'query', 'function', 'folder', + * 'recent' + * + * @param {boolean} [options.includeContent] Flag indicating whether or not to + * return the content of each applicable item. If false, only return the item + * information. + * + * @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(resourceGroupName, resourceName, scopePath, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._list(resourceGroupName, resourceName, scopePath, 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 Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.scope] Enum indicating if this item definition is + * owned by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'shared', 'user' + * + * @param {string} [options.type] Enum indicating the type of the Analytics + * item. Possible values include: 'none', 'query', 'function', 'folder', + * 'recent' + * + * @param {boolean} [options.includeContent] Flag indicating whether or not to + * return the content of each applicable item. If false, only return the item + * information. + * + * @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(resourceGroupName, resourceName, scopePath, 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(resourceGroupName, resourceName, scopePath, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._list(resourceGroupName, resourceName, scopePath, options, optionalCallback); + } + } + + /** + * Gets a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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, scopePath, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(resourceGroupName, resourceName, scopePath, 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 specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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 {ApplicationInsightsComponentAnalyticsItem} - 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 ApplicationInsightsComponentAnalyticsItem} + * 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, scopePath, 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, scopePath, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._get(resourceGroupName, resourceName, scopePath, options, optionalCallback); + } + } + + /** + * Adds or Updates a specific Analytics Item within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} itemProperties Properties that need to be specified to + * create a new item and add it to an Application Insights component. + * + * @param {string} [itemProperties.id] Internally assigned unique id of the + * item definition. + * + * @param {string} [itemProperties.name] The user-defined name of the item. + * + * @param {string} [itemProperties.content] The content of this item + * + * @param {string} [itemProperties.scope] Enum indicating if this item + * definition is owned by a specific user or is shared between all users with + * access to the Application Insights component. Possible values include: + * 'shared', 'user' + * + * @param {string} [itemProperties.type] Enum indicating the type of the + * Analytics item. Possible values include: 'query', 'function', 'folder', + * 'recent' + * + * @param {object} [itemProperties.properties] + * + * @param {string} [itemProperties.properties.functionAlias] A function alias, + * used when the type of the item is Function + * + * @param {object} [options] Optional Parameters. + * + * @param {boolean} [options.overrideItem] Flag indicating whether or not to + * force save an item. This allows overriding an item if it already exists. + * + * @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. + */ + putWithHttpOperationResponse(resourceGroupName, resourceName, scopePath, itemProperties, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._put(resourceGroupName, resourceName, scopePath, itemProperties, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Adds or Updates a specific Analytics Item within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} itemProperties Properties that need to be specified to + * create a new item and add it to an Application Insights component. + * + * @param {string} [itemProperties.id] Internally assigned unique id of the + * item definition. + * + * @param {string} [itemProperties.name] The user-defined name of the item. + * + * @param {string} [itemProperties.content] The content of this item + * + * @param {string} [itemProperties.scope] Enum indicating if this item + * definition is owned by a specific user or is shared between all users with + * access to the Application Insights component. Possible values include: + * 'shared', 'user' + * + * @param {string} [itemProperties.type] Enum indicating the type of the + * Analytics item. Possible values include: 'query', 'function', 'folder', + * 'recent' + * + * @param {object} [itemProperties.properties] + * + * @param {string} [itemProperties.properties.functionAlias] A function alias, + * used when the type of the item is Function + * + * @param {object} [options] Optional Parameters. + * + * @param {boolean} [options.overrideItem] Flag indicating whether or not to + * force save an item. This allows overriding an item if it already exists. + * + * @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 {ApplicationInsightsComponentAnalyticsItem} - 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 ApplicationInsightsComponentAnalyticsItem} + * 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. + */ + put(resourceGroupName, resourceName, scopePath, itemProperties, 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._put(resourceGroupName, resourceName, scopePath, itemProperties, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._put(resourceGroupName, resourceName, scopePath, itemProperties, options, optionalCallback); + } + } + + /** + * Deletes a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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. + */ + deleteMethodWithHttpOperationResponse(resourceGroupName, resourceName, scopePath, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._deleteMethod(resourceGroupName, resourceName, scopePath, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Deletes a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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 {null} - 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. + * + * {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. + */ + deleteMethod(resourceGroupName, resourceName, scopePath, 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._deleteMethod(resourceGroupName, resourceName, scopePath, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._deleteMethod(resourceGroupName, resourceName, scopePath, options, optionalCallback); + } + } + +} + +module.exports = AnalyticsItem; diff --git a/lib/services/applicationinsights/lib/operations/components.js b/lib/services/applicationinsights/lib/operations/components.js index 104b7fdedb..04ae765c1a 100644 --- a/lib/services/applicationinsights/lib/operations/components.js +++ b/lib/services/applicationinsights/lib/operations/components.js @@ -931,6 +931,7 @@ function _updateTags(resourceGroupName, resourceName, componentTags, options, ca }); } + /** * Purges data in an Application Insights component by a set of user-defined * filters. @@ -960,8 +961,6 @@ function _updateTags(resourceGroupName, resourceName, componentTags, options, ca * {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 ComponentPurgeResponse} for more - * information. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -974,122 +973,43 @@ function _purge(resourceGroupName, resourceName, body, options, callback) { callback = options; options = null; } + if (!callback) { throw new Error('callback cannot be null.'); } - // Validate - try { - 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 (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 (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 (body === null || body === undefined) { - throw new Error('body cannot be null or undefined.'); - } - if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { - throw new Error('this.client.acceptLanguage must be of type string.'); - } - } catch (error) { - return callback(error); - } - // Construct URL - let baseUrl = this.client.baseUri; - let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/purge'; - requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); - requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); - requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName)); - let queryParameters = []; - queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); - if (queryParameters.length > 0) { - requestUrl += '?' + queryParameters.join('&'); - } + // Send request + this.beginPurge(resourceGroupName, resourceName, body, options, (err, parsedResult, httpRequest, response) => { + if (err) return callback(err); - // Create HTTP transport objects - let httpRequest = new WebResource(); - httpRequest.method = 'POST'; - httpRequest.url = requestUrl; - httpRequest.headers = {}; - // Set Headers - httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; - if (this.client.generateClientRequestId) { - httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); - } - if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { - httpRequest.headers['accept-language'] = this.client.acceptLanguage; - } - if(options) { - for(let headerName in options['customHeaders']) { - if (options['customHeaders'].hasOwnProperty(headerName)) { - httpRequest.headers[headerName] = options['customHeaders'][headerName]; - } - } - } - // Serialize Request - let requestContent = null; - let requestModel = null; - try { - if (body !== null && body !== undefined) { - let requestModelMapper = new client.models['ComponentPurgeBody']().mapper(); - requestModel = client.serialize(requestModelMapper, body, 'body'); - requestContent = JSON.stringify(requestModel); - } - } catch (error) { - let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + - `payload - ${JSON.stringify(body, 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 !== 202) { - let error = new Error(responseBody); - error.statusCode = response.statusCode; - error.request = msRest.stripRequest(httpRequest); - error.response = msRest.stripResponse(response); + let initialResult = new msRest.HttpOperationResponse(); + initialResult.request = httpRequest; + initialResult.response = response; + initialResult.body = response.body; + client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => { + if (err) return callback(err); + + // Create Result + let result = null; + + httpRequest = pollingResult.request; + response = pollingResult.response; + let responseBody = pollingResult.body; 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 === 202) { + + // Deserialize Response let parsedResponse = null; try { parsedResponse = JSON.parse(responseBody); result = JSON.parse(responseBody); if (parsedResponse !== null && parsedResponse !== undefined) { - let resultMapper = new client.models['ComponentPurgeResponse']().mapper(); + let resultMapper = { + required: false, + serializedName: 'parsedResponse', + type: { + name: 'Object' + } + }; result = client.deserialize(resultMapper, parsedResponse, 'result'); } } catch (error) { @@ -1098,23 +1018,28 @@ function _purge(resourceGroupName, resourceName, body, options, callback) { deserializationError.response = msRest.stripResponse(response); return callback(deserializationError); } - } - return callback(null, result, httpRequest, response); + return callback(null, result, httpRequest, response); + }); }); } /** - * Gets the status of a previously submitted purge using the id returned from - * the original purge request. + * Purges data in an Application Insights component by a set of user-defined + * filters. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} resourceName The name of the Application Insights component * resource. * - * @param {string} purgeId In a purge status request, this is the Id of the - * operation the status of which is returned. + * @param {object} body Describes the body of a request to purge data in a + * single table of an Application Insights component + * + * @param {string} body.table Table from which to purge data. + * + * @param {array} body.filters The set of columns and filters (queries) to run + * over them to purge the resulting data. * * @param {object} [options] Optional Parameters. * @@ -1128,14 +1053,12 @@ function _purge(resourceGroupName, resourceName, body, options, callback) { * {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 ComponentPurgeStatusResponse} 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 _getPurgeStatus(resourceGroupName, resourceName, purgeId, options, callback) { +function _beginPurge(resourceGroupName, resourceName, body, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -1159,8 +1082,8 @@ function _getPurgeStatus(resourceGroupName, resourceName, purgeId, options, call 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 (purgeId === null || purgeId === undefined || typeof purgeId.valueOf() !== 'string') { - throw new Error('purgeId cannot be null or undefined and it must be of type string.'); + if (body === null || body === undefined) { + throw new Error('body 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.'); @@ -1171,11 +1094,10 @@ function _getPurgeStatus(resourceGroupName, resourceName, purgeId, options, call // Construct URL let baseUrl = this.client.baseUri; - let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/operations/{purgeId}'; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/components/{resourceName}/purge'; requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName)); requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId)); requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName)); - requestUrl = requestUrl.replace('{purgeId}', encodeURIComponent(purgeId)); let queryParameters = []; queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); if (queryParameters.length > 0) { @@ -1184,7 +1106,7 @@ function _getPurgeStatus(resourceGroupName, resourceName, purgeId, options, call // Create HTTP transport objects let httpRequest = new WebResource(); - httpRequest.method = 'GET'; + httpRequest.method = 'POST'; httpRequest.url = requestUrl; httpRequest.headers = {}; // Set Headers @@ -1202,14 +1124,28 @@ function _getPurgeStatus(resourceGroupName, resourceName, purgeId, options, call } } } - httpRequest.body = null; + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (body !== null && body !== undefined) { + let requestModelMapper = new client.models['ComponentPurgeBody']().mapper(); + requestModel = client.serialize(requestModelMapper, body, 'body'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(body, 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) { + if (statusCode !== 200 && statusCode !== 202) { let error = new Error(responseBody); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); @@ -1254,6 +1190,23 @@ function _getPurgeStatus(resourceGroupName, resourceName, purgeId, options, call return callback(deserializationError); } } + // Deserialize Response + if (statusCode === 202) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['ComponentPurgeResponse']().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); }); @@ -1530,7 +1483,7 @@ class Components { this._createOrUpdate = _createOrUpdate; this._updateTags = _updateTags; this._purge = _purge; - this._getPurgeStatus = _getPurgeStatus; + this._beginPurge = _beginPurge; this._listNext = _listNext; this._listByResourceGroupNext = _listByResourceGroupNext; } @@ -2155,7 +2108,7 @@ class Components { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error} - The error object. */ @@ -2202,7 +2155,7 @@ class Components { * * {Promise} A promise is returned * - * @resolve {ComponentPurgeResponse} - The deserialized result object. + * @resolve {Object} - The deserialized result object. * * @reject {Error} - The error object. * @@ -2211,8 +2164,6 @@ class Components { * {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 ComponentPurgeResponse} for more - * information. * * {object} [request] - The HTTP Request object if an error did not occur. * @@ -2239,16 +2190,21 @@ class Components { } /** - * Gets the status of a previously submitted purge using the id returned from - * the original purge request. + * Purges data in an Application Insights component by a set of user-defined + * filters. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} resourceName The name of the Application Insights component * resource. * - * @param {string} purgeId In a purge status request, this is the Id of the - * operation the status of which is returned. + * @param {object} body Describes the body of a request to purge data in a + * single table of an Application Insights component + * + * @param {string} body.table Table from which to purge data. + * + * @param {array} body.filters The set of columns and filters (queries) to run + * over them to purge the resulting data. * * @param {object} [options] Optional Parameters. * @@ -2257,15 +2213,15 @@ class Components { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error} - The error object. */ - getPurgeStatusWithHttpOperationResponse(resourceGroupName, resourceName, purgeId, options) { + beginPurgeWithHttpOperationResponse(resourceGroupName, resourceName, body, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._getPurgeStatus(resourceGroupName, resourceName, purgeId, options, (err, result, request, response) => { + self._beginPurge(resourceGroupName, resourceName, body, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -2276,16 +2232,21 @@ class Components { } /** - * Gets the status of a previously submitted purge using the id returned from - * the original purge request. + * Purges data in an Application Insights component by a set of user-defined + * filters. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} resourceName The name of the Application Insights component * resource. * - * @param {string} purgeId In a purge status request, this is the Id of the - * operation the status of which is returned. + * @param {object} body Describes the body of a request to purge data in a + * single table of an Application Insights component + * + * @param {string} body.table Table from which to purge data. + * + * @param {array} body.filters The set of columns and filters (queries) to run + * over them to purge the resulting data. * * @param {object} [options] Optional Parameters. * @@ -2299,7 +2260,7 @@ class Components { * * {Promise} A promise is returned * - * @resolve {ComponentPurgeStatusResponse} - The deserialized result object. + * @resolve {Object} - The deserialized result object. * * @reject {Error} - The error object. * @@ -2308,14 +2269,12 @@ class Components { * {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 ComponentPurgeStatusResponse} 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. */ - getPurgeStatus(resourceGroupName, resourceName, purgeId, options, optionalCallback) { + beginPurge(resourceGroupName, resourceName, body, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -2324,14 +2283,14 @@ class Components { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._getPurgeStatus(resourceGroupName, resourceName, purgeId, options, (err, result, request, response) => { + self._beginPurge(resourceGroupName, resourceName, body, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._getPurgeStatus(resourceGroupName, resourceName, purgeId, options, optionalCallback); + return self._beginPurge(resourceGroupName, resourceName, body, options, optionalCallback); } } diff --git a/lib/services/applicationinsights/lib/operations/index.d.ts b/lib/services/applicationinsights/lib/operations/index.d.ts index 29d0386ff3..5c39016762 100644 --- a/lib/services/applicationinsights/lib/operations/index.d.ts +++ b/lib/services/applicationinsights/lib/operations/index.d.ts @@ -2366,11 +2366,11 @@ export interface Components { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - purgeWithHttpOperationResponse(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + purgeWithHttpOperationResponse(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** * Purges data in an Application Insights component by a set of user-defined @@ -2401,7 +2401,7 @@ export interface Components { * * {Promise} A promise is returned. * - * @resolve {ComponentPurgeResponse} - The deserialized result object. + * @resolve {Object} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -2409,30 +2409,33 @@ export interface Components { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {ComponentPurgeResponse} [result] - The deserialized result object if an error did not occur. - * See {@link ComponentPurgeResponse} for more - * information. + * {Object} [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. */ - purge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - purge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, callback: ServiceCallback): void; - purge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + purge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + purge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, callback: ServiceCallback): void; + purge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** - * Gets the status of a previously submitted purge using the id returned from - * the original purge request. + * Purges data in an Application Insights component by a set of user-defined + * filters. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} resourceName The name of the Application Insights component * resource. * - * @param {string} purgeId In a purge status request, this is the Id of the - * operation the status of which is returned. + * @param {object} body Describes the body of a request to purge data in a + * single table of an Application Insights component + * + * @param {string} body.table Table from which to purge data. + * + * @param {array} body.filters The set of columns and filters (queries) to run + * over them to purge the resulting data. * * @param {object} [options] Optional Parameters. * @@ -2441,23 +2444,28 @@ export interface Components { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - getPurgeStatusWithHttpOperationResponse(resourceGroupName: string, resourceName: string, purgeId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + beginPurgeWithHttpOperationResponse(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** - * Gets the status of a previously submitted purge using the id returned from - * the original purge request. + * Purges data in an Application Insights component by a set of user-defined + * filters. * * @param {string} resourceGroupName The name of the resource group. * * @param {string} resourceName The name of the Application Insights component * resource. * - * @param {string} purgeId In a purge status request, this is the Id of the - * operation the status of which is returned. + * @param {object} body Describes the body of a request to purge data in a + * single table of an Application Insights component + * + * @param {string} body.table Table from which to purge data. + * + * @param {array} body.filters The set of columns and filters (queries) to run + * over them to purge the resulting data. * * @param {object} [options] Optional Parameters. * @@ -2471,7 +2479,7 @@ export interface Components { * * {Promise} A promise is returned. * - * @resolve {ComponentPurgeStatusResponse} - The deserialized result object. + * @resolve {Object} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -2479,17 +2487,15 @@ export interface Components { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {ComponentPurgeStatusResponse} [result] - The deserialized result object if an error did not occur. - * See {@link ComponentPurgeStatusResponse} for more - * information. + * {Object} [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. */ - getPurgeStatus(resourceGroupName: string, resourceName: string, purgeId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - getPurgeStatus(resourceGroupName: string, resourceName: string, purgeId: string, callback: ServiceCallback): void; - getPurgeStatus(resourceGroupName: string, resourceName: string, purgeId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + beginPurge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + beginPurge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, callback: ServiceCallback): void; + beginPurge(resourceGroupName: string, resourceName: string, body: models.ComponentPurgeBody, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** @@ -4061,6 +4067,409 @@ export interface WebTests { listNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } +/** + * @class + * AnalyticsItem + * __NOTE__: An instance of this class is automatically created for an + * instance of the ApplicationInsightsManagementClient. + */ +export interface AnalyticsItem { + + + /** + * Gets a list of Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.scope] Enum indicating if this item definition is + * owned by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'shared', 'user' + * + * @param {string} [options.type] Enum indicating the type of the Analytics + * item. Possible values include: 'none', 'query', 'function', 'folder', + * 'recent' + * + * @param {boolean} [options.includeContent] Flag indicating whether or not to + * return the content of each applicable item. If false, only return the item + * information. + * + * @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(resourceGroupName: string, resourceName: string, scopePath: string, options?: { scope? : string, type? : string, includeContent? : boolean, customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Gets a list of Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.scope] Enum indicating if this item definition is + * owned by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'shared', 'user' + * + * @param {string} [options.type] Enum indicating the type of the Analytics + * item. Possible values include: 'none', 'query', 'function', 'folder', + * 'recent' + * + * @param {boolean} [options.includeContent] Flag indicating whether or not to + * return the content of each applicable item. If false, only return the item + * information. + * + * @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(resourceGroupName: string, resourceName: string, scopePath: string, options?: { scope? : string, type? : string, includeContent? : boolean, customHeaders? : { [headerName: string]: string; } }): Promise; + list(resourceGroupName: string, resourceName: string, scopePath: string, callback: ServiceCallback): void; + list(resourceGroupName: string, resourceName: string, scopePath: string, options: { scope? : string, type? : string, includeContent? : boolean, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Gets a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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, scopePath: string, options?: { id? : string, name? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Gets a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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 {ApplicationInsightsComponentAnalyticsItem} - 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. + * + * {ApplicationInsightsComponentAnalyticsItem} [result] - The deserialized result object if an error did not occur. + * See {@link ApplicationInsightsComponentAnalyticsItem} + * 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, scopePath: string, options?: { id? : string, name? : string, customHeaders? : { [headerName: string]: string; } }): Promise; + get(resourceGroupName: string, resourceName: string, scopePath: string, callback: ServiceCallback): void; + get(resourceGroupName: string, resourceName: string, scopePath: string, options: { id? : string, name? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Adds or Updates a specific Analytics Item within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} itemProperties Properties that need to be specified to + * create a new item and add it to an Application Insights component. + * + * @param {string} [itemProperties.id] Internally assigned unique id of the + * item definition. + * + * @param {string} [itemProperties.name] The user-defined name of the item. + * + * @param {string} [itemProperties.content] The content of this item + * + * @param {string} [itemProperties.scope] Enum indicating if this item + * definition is owned by a specific user or is shared between all users with + * access to the Application Insights component. Possible values include: + * 'shared', 'user' + * + * @param {string} [itemProperties.type] Enum indicating the type of the + * Analytics item. Possible values include: 'query', 'function', 'folder', + * 'recent' + * + * @param {object} [itemProperties.properties] + * + * @param {string} [itemProperties.properties.functionAlias] A function alias, + * used when the type of the item is Function + * + * @param {object} [options] Optional Parameters. + * + * @param {boolean} [options.overrideItem] Flag indicating whether or not to + * force save an item. This allows overriding an item if it already exists. + * + * @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. + */ + putWithHttpOperationResponse(resourceGroupName: string, resourceName: string, scopePath: string, itemProperties: models.ApplicationInsightsComponentAnalyticsItem, options?: { overrideItem? : boolean, customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Adds or Updates a specific Analytics Item within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} itemProperties Properties that need to be specified to + * create a new item and add it to an Application Insights component. + * + * @param {string} [itemProperties.id] Internally assigned unique id of the + * item definition. + * + * @param {string} [itemProperties.name] The user-defined name of the item. + * + * @param {string} [itemProperties.content] The content of this item + * + * @param {string} [itemProperties.scope] Enum indicating if this item + * definition is owned by a specific user or is shared between all users with + * access to the Application Insights component. Possible values include: + * 'shared', 'user' + * + * @param {string} [itemProperties.type] Enum indicating the type of the + * Analytics item. Possible values include: 'query', 'function', 'folder', + * 'recent' + * + * @param {object} [itemProperties.properties] + * + * @param {string} [itemProperties.properties.functionAlias] A function alias, + * used when the type of the item is Function + * + * @param {object} [options] Optional Parameters. + * + * @param {boolean} [options.overrideItem] Flag indicating whether or not to + * force save an item. This allows overriding an item if it already exists. + * + * @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 {ApplicationInsightsComponentAnalyticsItem} - 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. + * + * {ApplicationInsightsComponentAnalyticsItem} [result] - The deserialized result object if an error did not occur. + * See {@link ApplicationInsightsComponentAnalyticsItem} + * 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. + */ + put(resourceGroupName: string, resourceName: string, scopePath: string, itemProperties: models.ApplicationInsightsComponentAnalyticsItem, options?: { overrideItem? : boolean, customHeaders? : { [headerName: string]: string; } }): Promise; + put(resourceGroupName: string, resourceName: string, scopePath: string, itemProperties: models.ApplicationInsightsComponentAnalyticsItem, callback: ServiceCallback): void; + put(resourceGroupName: string, resourceName: string, scopePath: string, itemProperties: models.ApplicationInsightsComponentAnalyticsItem, options: { overrideItem? : boolean, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Deletes a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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. + */ + deleteMethodWithHttpOperationResponse(resourceGroupName: string, resourceName: string, scopePath: string, options?: { id? : string, name? : string, customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Deletes a specific Analytics Items defined within an Application Insights + * component. + * + * @param {string} resourceGroupName The name of the resource group. + * + * @param {string} resourceName The name of the Application Insights component + * resource. + * + * @param {string} scopePath Enum indicating if this item definition is owned + * by a specific user or is shared between all users with access to the + * Application Insights component. Possible values include: 'analyticsItems', + * 'myanalyticsItems' + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.id] The Id of a specific item defined in the + * Application Insights component + * + * @param {string} [options.name] The name of a specific item defined in the + * Application Insights component + * + * @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 {null} - 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. + * + * {null} [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. + */ + deleteMethod(resourceGroupName: string, resourceName: string, scopePath: string, options?: { id? : string, name? : string, customHeaders? : { [headerName: string]: string; } }): Promise; + deleteMethod(resourceGroupName: string, resourceName: string, scopePath: string, callback: ServiceCallback): void; + deleteMethod(resourceGroupName: string, resourceName: string, scopePath: string, options: { id? : string, name? : string, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} + /** * @class * WorkbooksOperations @@ -4156,6 +4565,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 +4974,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/operations/index.js b/lib/services/applicationinsights/lib/operations/index.js index 51825288b4..e3a91e4d8e 100644 --- a/lib/services/applicationinsights/lib/operations/index.js +++ b/lib/services/applicationinsights/lib/operations/index.js @@ -29,5 +29,6 @@ exports.Favorites = require('./favorites'); exports.Favorite = require('./favorite'); exports.WebTestLocations = require('./webTestLocations'); exports.WebTests = require('./webTests'); +exports.AnalyticsItem = require('./analyticsItem'); exports.WorkbooksOperations = require('./workbooksOperations'); exports.WorkbookOperations = require('./workbookOperations'); diff --git a/lib/services/applicationinsights/lib/operations/workbookOperations.js b/lib/services/applicationinsights/lib/operations/workbookOperations.js index bc273d8528..1563f8f8b5 100644 --- a/lib/services/applicationinsights/lib/operations/workbookOperations.js +++ b/lib/services/applicationinsights/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;