diff --git a/lib/services/consumptionManagement/LICENSE.txt b/lib/services/consumptionManagement/LICENSE.txt index 0313a903d7..5431ba98b9 100644 --- a/lib/services/consumptionManagement/LICENSE.txt +++ b/lib/services/consumptionManagement/LICENSE.txt @@ -1,21 +1,21 @@ -The MIT License (MIT) - -Copyright (c) 2017 Microsoft - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +The MIT License (MIT) + +Copyright (c) 2018 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/services/consumptionManagement/README.md b/lib/services/consumptionManagement/README.md index 1e8c9863ee..fa6d0fd678 100644 --- a/lib/services/consumptionManagement/README.md +++ b/lib/services/consumptionManagement/README.md @@ -1,38 +1,45 @@ -# Microsoft Azure SDK for Node.js - ConsumptionManagement - -This project provides a Node.js package for accessing the Azure PAS. Right now it supports: -- **Node.js version: 6.x.x or higher** - -## How to Install - -```bash -npm install azure-arm-consumption -``` - -## How to Use - -### Authentication, client creation and listing usageDetails as an example - - ```javascript - var msRestAzure = require('ms-rest-azure'); - var ConsumptionManagementClient = require("azure-arm-consumption"); - - // Interactive Login - // It provides a url and code that needs to be copied and pasted in a browser and authenticated over there. If successful, - // the user will get a DeviceTokenCredentials object. - msRestAzure.interactiveLogin(function(err, credentials) { - let client = new ConsumptionManagementClient(credentials, 'your-subscription-id'); - client.usageDetails.list().then((usageDetails) => { - console.log('List of usageDetails:'); - console.dir(usageDetails, {depth: null, colors: true}); - }); - }).catch((err) => { - console.log('An error ocurred'); - console.dir(err, {depth: null, colors: true}); - }); -}); -``` - -## Related projects - -- [Microsoft Azure SDK for Node.js](https://github.com/Azure/azure-sdk-for-node) +--- +uid: azure-arm-consumption +summary: *content + +--- +# Microsoft Azure SDK for Node.js - ConsumptionManagementClient +This project provides a Node.js package for accessing Azure. Right now it supports: +- **Node.js version 6.x.x or higher** + +## Features + + +## How to Install + +```bash +npm install azure-arm-consumption +``` + +## How to use + +### Authentication, client creation and list usageDetails as an example. + +```javascript +const msRestAzure = require("ms-rest-azure"); +const ConsumptionManagementClient = require("azure-arm-consumption"); +msRestAzure.interactiveLogin().then((creds) => { + const subscriptionId = ""; + const client = new ConsumptionManagementClient(creds, subscriptionId); + const expand = "testexpand"; + const filter = "testfilter"; + const skiptoken = "testskiptoken"; + const top = 1; + const apply = "testapply"; + return client.usageDetails.list(expand, filter, skiptoken, top, apply).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.log('An error occurred:'); + console.dir(err, {depth: null, colors: true}); +}); + +## Related projects + +- [Microsoft Azure SDK for Node.js](https://github.com/Azure/azure-sdk-for-node) diff --git a/lib/services/consumptionManagement/lib/consumptionManagementClient.d.ts b/lib/services/consumptionManagement/lib/consumptionManagementClient.d.ts index 507a6fc1b0..872911c5e1 100644 --- a/lib/services/consumptionManagement/lib/consumptionManagementClient.d.ts +++ b/lib/services/consumptionManagement/lib/consumptionManagementClient.d.ts @@ -64,7 +64,8 @@ export default class ConsumptionManagementClient extends AzureServiceClient { budgets: operations.Budgets; operations: operations.Operations; priceSheet: operations.PriceSheet; - costAllocationTagsOperations: operations.CostAllocationTagsOperations; + costTagsOperations: operations.CostTagsOperations; + tagsOperations: operations.TagsOperations; } export { ConsumptionManagementClient, models as ConsumptionManagementModels }; diff --git a/lib/services/consumptionManagement/lib/consumptionManagementClient.js b/lib/services/consumptionManagement/lib/consumptionManagementClient.js index 7174ea58fc..98c1b22386 100644 --- a/lib/services/consumptionManagement/lib/consumptionManagementClient.js +++ b/lib/services/consumptionManagement/lib/consumptionManagementClient.js @@ -80,7 +80,8 @@ class ConsumptionManagementClient extends ServiceClient { this.budgets = new operations.Budgets(this); this.operations = new operations.Operations(this); this.priceSheet = new operations.PriceSheet(this); - this.costAllocationTagsOperations = new operations.CostAllocationTagsOperations(this); + this.costTagsOperations = new operations.CostTagsOperations(this); + this.tagsOperations = new operations.TagsOperations(this); this.models = models; msRest.addSerializationMixin(this); } diff --git a/lib/services/consumptionManagement/lib/models/costTag.js b/lib/services/consumptionManagement/lib/models/costTag.js new file mode 100644 index 0000000000..29a8e275c7 --- /dev/null +++ b/lib/services/consumptionManagement/lib/models/costTag.js @@ -0,0 +1,52 @@ +/* + * 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'; + +/** + * The cost tag. + * + */ +class CostTag { + /** + * Create a CostTag. + * @member {string} [key] Cost tag key. + */ + constructor() { + } + + /** + * Defines the metadata of CostTag + * + * @returns {object} metadata of CostTag + * + */ + mapper() { + return { + required: false, + serializedName: 'CostTag', + type: { + name: 'Composite', + className: 'CostTag', + modelProperties: { + key: { + required: false, + serializedName: 'key', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = CostTag; diff --git a/lib/services/consumptionManagement/lib/models/costTags.js b/lib/services/consumptionManagement/lib/models/costTags.js new file mode 100644 index 0000000000..7b3f162b79 --- /dev/null +++ b/lib/services/consumptionManagement/lib/models/costTags.js @@ -0,0 +1,95 @@ +/* + * 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'); + +/** + * A cost tag resource. + * + * @extends models['ProxyResource'] + */ +class CostTags extends models['ProxyResource'] { + /** + * Create a CostTags. + * @member {array} [costTags] Cost tags. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of CostTags + * + * @returns {object} metadata of CostTags + * + */ + mapper() { + return { + required: false, + serializedName: 'CostTags', + type: { + name: 'Composite', + className: 'CostTags', + modelProperties: { + id: { + required: false, + readOnly: true, + serializedName: 'id', + type: { + name: 'String' + } + }, + name: { + required: false, + readOnly: true, + serializedName: 'name', + type: { + name: 'String' + } + }, + type: { + required: false, + readOnly: true, + serializedName: 'type', + type: { + name: 'String' + } + }, + eTag: { + required: false, + serializedName: 'eTag', + type: { + name: 'String' + } + }, + costTags: { + required: false, + serializedName: 'properties.costTags', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'CostTagElementType', + type: { + name: 'Composite', + className: 'CostTag' + } + } + } + } + } + } + }; + } +} + +module.exports = CostTags; diff --git a/lib/services/consumptionManagement/lib/models/index.d.ts b/lib/services/consumptionManagement/lib/models/index.d.ts index 06dd4174d6..e98fac3993 100644 --- a/lib/services/consumptionManagement/lib/models/index.d.ts +++ b/lib/services/consumptionManagement/lib/models/index.d.ts @@ -335,6 +335,50 @@ export interface ReservationRecommendations { readonly scope?: string; } +/** + * @class + * Initializes a new instance of the Tag class. + * @constructor + * The tag resource. + * + * @member {string} [key] Tag key. + */ +export interface Tag { + key?: string; +} + +/** + * @class + * Initializes a new instance of the ProxyResource class. + * @constructor + * The Resource model definition. + * + * @member {string} [id] Resource Id. + * @member {string} [name] Resource name. + * @member {string} [type] Resource type. + * @member {string} [eTag] eTag of the resource. To handle concurrent update + * scenarion, this field will be used to determine whether the user is updating + * the latest version or not. + */ +export interface ProxyResource extends BaseResource { + readonly id?: string; + readonly name?: string; + readonly type?: string; + eTag?: string; +} + +/** + * @class + * Initializes a new instance of the Tags class. + * @constructor + * A resource listing all tags. + * + * @member {array} [tags] A list of Tag. + */ +export interface Tags extends ProxyResource { + tags?: Tag[]; +} + /** * @class * Initializes a new instance of the BudgetTimePeriod class. @@ -413,26 +457,6 @@ export interface Notification { contactGroups?: string[]; } -/** - * @class - * Initializes a new instance of the ProxyResource class. - * @constructor - * The Resource model definition. - * - * @member {string} [id] Resource Id. - * @member {string} [name] Resource name. - * @member {string} [type] Resource type. - * @member {string} [eTag] eTag of the resource. To handle concurrent update - * scenarion, this field will be used to determine whether the user is updating - * the latest version or not. - */ -export interface ProxyResource extends BaseResource { - readonly id?: string; - readonly name?: string; - readonly type?: string; - eTag?: string; -} - /** * @class * Initializes a new instance of the Budget class. @@ -482,26 +506,26 @@ export interface Budget extends ProxyResource { /** * @class - * Initializes a new instance of the CostAllocationTag class. + * Initializes a new instance of the CostTag class. * @constructor - * The cost allocation tag. + * The cost tag. * - * @member {string} [key] Cost allocation tag key. + * @member {string} [key] Cost tag key. */ -export interface CostAllocationTag { +export interface CostTag { key?: string; } /** * @class - * Initializes a new instance of the CostAllocationTags class. + * Initializes a new instance of the CostTags class. * @constructor - * A cost allocation tag resource. + * A cost tag resource. * - * @member {array} [costAllocationTags] Cost allocation tags. + * @member {array} [costTags] Cost tags. */ -export interface CostAllocationTags extends ProxyResource { - costAllocationTags?: CostAllocationTag[]; +export interface CostTags extends ProxyResource { + costTags?: CostTag[]; } /** diff --git a/lib/services/consumptionManagement/lib/models/index.js b/lib/services/consumptionManagement/lib/models/index.js index 35476b9bf0..4ec0f1ec43 100644 --- a/lib/services/consumptionManagement/lib/models/index.js +++ b/lib/services/consumptionManagement/lib/models/index.js @@ -25,14 +25,16 @@ exports.Marketplace = require('./marketplace'); exports.ReservationSummaries = require('./reservationSummaries'); exports.ReservationDetails = require('./reservationDetails'); exports.ReservationRecommendations = require('./reservationRecommendations'); +exports.Tag = require('./tag'); +exports.ProxyResource = require('./proxyResource'); +exports.Tags = require('./tags'); exports.BudgetTimePeriod = require('./budgetTimePeriod'); exports.Filters = require('./filters'); exports.CurrentSpend = require('./currentSpend'); exports.Notification = require('./notification'); -exports.ProxyResource = require('./proxyResource'); exports.Budget = require('./budget'); -exports.CostAllocationTag = require('./costAllocationTag'); -exports.CostAllocationTags = require('./costAllocationTags'); +exports.CostTag = require('./costTag'); +exports.CostTags = require('./costTags'); exports.ErrorDetails = require('./errorDetails'); exports.ErrorResponse = require('./errorResponse'); exports.OperationDisplay = require('./operationDisplay'); diff --git a/lib/services/consumptionManagement/lib/models/tag.js b/lib/services/consumptionManagement/lib/models/tag.js new file mode 100644 index 0000000000..2424fd6383 --- /dev/null +++ b/lib/services/consumptionManagement/lib/models/tag.js @@ -0,0 +1,52 @@ +/* + * 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'; + +/** + * The tag resource. + * + */ +class Tag { + /** + * Create a Tag. + * @member {string} [key] Tag key. + */ + constructor() { + } + + /** + * Defines the metadata of Tag + * + * @returns {object} metadata of Tag + * + */ + mapper() { + return { + required: false, + serializedName: 'Tag', + type: { + name: 'Composite', + className: 'Tag', + modelProperties: { + key: { + required: false, + serializedName: 'key', + type: { + name: 'String' + } + } + } + } + }; + } +} + +module.exports = Tag; diff --git a/lib/services/consumptionManagement/lib/models/tags.js b/lib/services/consumptionManagement/lib/models/tags.js new file mode 100644 index 0000000000..c7a6c39a59 --- /dev/null +++ b/lib/services/consumptionManagement/lib/models/tags.js @@ -0,0 +1,95 @@ +/* + * 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'); + +/** + * A resource listing all tags. + * + * @extends models['ProxyResource'] + */ +class Tags extends models['ProxyResource'] { + /** + * Create a Tags. + * @member {array} [tags] A list of Tag. + */ + constructor() { + super(); + } + + /** + * Defines the metadata of Tags + * + * @returns {object} metadata of Tags + * + */ + mapper() { + return { + required: false, + serializedName: 'Tags', + type: { + name: 'Composite', + className: 'Tags', + modelProperties: { + id: { + required: false, + readOnly: true, + serializedName: 'id', + type: { + name: 'String' + } + }, + name: { + required: false, + readOnly: true, + serializedName: 'name', + type: { + name: 'String' + } + }, + type: { + required: false, + readOnly: true, + serializedName: 'type', + type: { + name: 'String' + } + }, + eTag: { + required: false, + serializedName: 'eTag', + type: { + name: 'String' + } + }, + tags: { + required: false, + serializedName: 'properties.tags', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'TagElementType', + type: { + name: 'Composite', + className: 'Tag' + } + } + } + } + } + } + }; + } +} + +module.exports = Tags; diff --git a/lib/services/consumptionManagement/lib/operations/costTagsOperations.js b/lib/services/consumptionManagement/lib/operations/costTagsOperations.js new file mode 100644 index 0000000000..0f611d849a --- /dev/null +++ b/lib/services/consumptionManagement/lib/operations/costTagsOperations.js @@ -0,0 +1,537 @@ +/* + * 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; + +/** + * Get cost tags for a billing account. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link CostTags} 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(billingAccountId, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (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 (billingAccountId === null || billingAccountId === undefined || typeof billingAccountId.valueOf() !== 'string') { + throw new Error('billingAccountId 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('/') ? '' : '/') + 'providers/Microsoft.CostManagement/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/costTags'; + requestUrl = requestUrl.replace('{billingAccountId}', encodeURIComponent(billingAccountId)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['CostTags']().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); + }); +} + +/** + * The operation to create or update cost tags assiciated with a billing + * account. Update operation requires latest eTag to be set in the request + * mandatorily. You may obtain the latest eTag by performing a get operation. + * Create operation does not require eTag. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @param {object} parameters Parameters supplied to the Create cost tags + * operation. + * + * @param {array} [parameters.costTags] Cost tags. + * + * @param {string} [parameters.eTag] eTag of the resource. To handle concurrent + * update scenarion, this field will be used to determine whether the user is + * updating the latest version or not. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link CostTags} 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 _createOrUpdate(billingAccountId, parameters, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (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 (billingAccountId === null || billingAccountId === undefined || typeof billingAccountId.valueOf() !== 'string') { + throw new Error('billingAccountId cannot be null or undefined and it must be of type string.'); + } + if (parameters === null || parameters === undefined) { + throw new Error('parameters cannot be null or undefined.'); + } + if (this.client.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('/') ? '' : '/') + 'providers/Microsoft.CostManagement/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/costTags'; + requestUrl = requestUrl.replace('{billingAccountId}', encodeURIComponent(billingAccountId)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'PUT'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + // Serialize Request + let requestContent = null; + let requestModel = null; + try { + if (parameters !== null && parameters !== undefined) { + let requestModelMapper = new client.models['CostTags']().mapper(); + requestModel = client.serialize(requestModelMapper, parameters, 'parameters'); + requestContent = JSON.stringify(requestModel); + } + } catch (error) { + let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + + `payload - ${JSON.stringify(parameters, null, 2)}.`); + return callback(serializationError); + } + httpRequest.body = requestContent; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200 && statusCode !== 201) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['CostTags']().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['CostTags']().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); + }); +} + +/** Class representing a CostTagsOperations. */ +class CostTagsOperations { + /** + * Create a CostTagsOperations. + * @param {ConsumptionManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._get = _get; + this._createOrUpdate = _createOrUpdate; + } + + /** + * Get cost tags for a billing account. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @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(billingAccountId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(billingAccountId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Get cost tags for a billing account. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @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 {CostTags} - 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 CostTags} 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(billingAccountId, 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(billingAccountId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._get(billingAccountId, options, optionalCallback); + } + } + + /** + * The operation to create or update cost tags assiciated with a billing + * account. Update operation requires latest eTag to be set in the request + * mandatorily. You may obtain the latest eTag by performing a get operation. + * Create operation does not require eTag. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @param {object} parameters Parameters supplied to the Create cost tags + * operation. + * + * @param {array} [parameters.costTags] Cost tags. + * + * @param {string} [parameters.eTag] eTag of the resource. To handle concurrent + * update scenarion, this field will be used to determine whether the user is + * updating the latest version or not. + * + * @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. + */ + createOrUpdateWithHttpOperationResponse(billingAccountId, parameters, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._createOrUpdate(billingAccountId, parameters, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * The operation to create or update cost tags assiciated with a billing + * account. Update operation requires latest eTag to be set in the request + * mandatorily. You may obtain the latest eTag by performing a get operation. + * Create operation does not require eTag. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @param {object} parameters Parameters supplied to the Create cost tags + * operation. + * + * @param {array} [parameters.costTags] Cost tags. + * + * @param {string} [parameters.eTag] eTag of the resource. To handle concurrent + * update scenarion, this field will be used to determine whether the user is + * updating the latest version or not. + * + * @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 {CostTags} - 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 CostTags} 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. + */ + createOrUpdate(billingAccountId, parameters, 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._createOrUpdate(billingAccountId, parameters, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._createOrUpdate(billingAccountId, parameters, options, optionalCallback); + } + } + +} + +module.exports = CostTagsOperations; diff --git a/lib/services/consumptionManagement/lib/operations/index.d.ts b/lib/services/consumptionManagement/lib/operations/index.d.ts index 6835239a43..b10afb5c8f 100644 --- a/lib/services/consumptionManagement/lib/operations/index.d.ts +++ b/lib/services/consumptionManagement/lib/operations/index.d.ts @@ -2350,15 +2350,15 @@ export interface PriceSheet { /** * @class - * CostAllocationTagsOperations + * CostTagsOperations * __NOTE__: An instance of this class is automatically created for an * instance of the ConsumptionManagementClient. */ -export interface CostAllocationTagsOperations { +export interface CostTagsOperations { /** - * Get cost allocation tags for a billing account. + * Get cost tags for a billing account. * * @param {string} billingAccountId Azure Billing Account ID. * @@ -2369,14 +2369,14 @@ export interface CostAllocationTagsOperations { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - getWithHttpOperationResponse(billingAccountId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + getWithHttpOperationResponse(billingAccountId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** - * Get cost allocation tags for a billing account. + * Get cost tags for a billing account. * * @param {string} billingAccountId Azure Billing Account ID. * @@ -2392,7 +2392,7 @@ export interface CostAllocationTagsOperations { * * {Promise} A promise is returned. * - * @resolve {CostAllocationTags} - The deserialized result object. + * @resolve {CostTags} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -2400,30 +2400,30 @@ export interface CostAllocationTagsOperations { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {CostAllocationTags} [result] - The deserialized result object if an error did not occur. - * See {@link CostAllocationTags} for more information. + * {CostTags} [result] - The deserialized result object if an error did not occur. + * See {@link CostTags} 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(billingAccountId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - get(billingAccountId: string, callback: ServiceCallback): void; - get(billingAccountId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + get(billingAccountId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + get(billingAccountId: string, callback: ServiceCallback): void; + get(billingAccountId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; /** - * The operation to create or update cost allocation tags assiciated with a - * billing account. Update operation requires latest eTag to be set in the - * request mandatorily. You may obtain the latest eTag by performing a get - * operation. Create operation does not require eTag. + * The operation to create or update cost tags assiciated with a billing + * account. Update operation requires latest eTag to be set in the request + * mandatorily. You may obtain the latest eTag by performing a get operation. + * Create operation does not require eTag. * * @param {string} billingAccountId Azure Billing Account ID. * - * @param {object} parameters Parameters supplied to the Create cost allocation - * tags operation. + * @param {object} parameters Parameters supplied to the Create cost tags + * operation. * - * @param {array} [parameters.costAllocationTags] Cost allocation tags. + * @param {array} [parameters.costTags] Cost tags. * * @param {string} [parameters.eTag] eTag of the resource. To handle concurrent * update scenarion, this field will be used to determine whether the user is @@ -2436,24 +2436,24 @@ export interface CostAllocationTagsOperations { * * @returns {Promise} A promise is returned * - * @resolve {HttpOperationResponse} - The deserialized result object. + * @resolve {HttpOperationResponse} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. */ - createOrUpdateWithHttpOperationResponse(billingAccountId: string, parameters: models.CostAllocationTags, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + createOrUpdateWithHttpOperationResponse(billingAccountId: string, parameters: models.CostTags, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; /** - * The operation to create or update cost allocation tags assiciated with a - * billing account. Update operation requires latest eTag to be set in the - * request mandatorily. You may obtain the latest eTag by performing a get - * operation. Create operation does not require eTag. + * The operation to create or update cost tags assiciated with a billing + * account. Update operation requires latest eTag to be set in the request + * mandatorily. You may obtain the latest eTag by performing a get operation. + * Create operation does not require eTag. * * @param {string} billingAccountId Azure Billing Account ID. * - * @param {object} parameters Parameters supplied to the Create cost allocation - * tags operation. + * @param {object} parameters Parameters supplied to the Create cost tags + * operation. * - * @param {array} [parameters.costAllocationTags] Cost allocation tags. + * @param {array} [parameters.costTags] Cost tags. * * @param {string} [parameters.eTag] eTag of the resource. To handle concurrent * update scenarion, this field will be used to determine whether the user is @@ -2471,7 +2471,71 @@ export interface CostAllocationTagsOperations { * * {Promise} A promise is returned. * - * @resolve {CostAllocationTags} - The deserialized result object. + * @resolve {CostTags} - 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. + * + * {CostTags} [result] - The deserialized result object if an error did not occur. + * See {@link CostTags} 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. + */ + createOrUpdate(billingAccountId: string, parameters: models.CostTags, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + createOrUpdate(billingAccountId: string, parameters: models.CostTags, callback: ServiceCallback): void; + createOrUpdate(billingAccountId: string, parameters: models.CostTags, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; +} + +/** + * @class + * TagsOperations + * __NOTE__: An instance of this class is automatically created for an + * instance of the ConsumptionManagementClient. + */ +export interface TagsOperations { + + + /** + * Get all available tag keys for a billing account. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @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(billingAccountId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Get all available tag keys for a billing account. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @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 {Tags} - The deserialized result object. * * @reject {Error|ServiceError} - The error object. * @@ -2479,14 +2543,14 @@ export interface CostAllocationTagsOperations { * * {Error|ServiceError} err - The Error object if an error occurred, null otherwise. * - * {CostAllocationTags} [result] - The deserialized result object if an error did not occur. - * See {@link CostAllocationTags} for more information. + * {Tags} [result] - The deserialized result object if an error did not occur. + * See {@link Tags} 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. */ - createOrUpdate(billingAccountId: string, parameters: models.CostAllocationTags, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; - createOrUpdate(billingAccountId: string, parameters: models.CostAllocationTags, callback: ServiceCallback): void; - createOrUpdate(billingAccountId: string, parameters: models.CostAllocationTags, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + get(billingAccountId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + get(billingAccountId: string, callback: ServiceCallback): void; + get(billingAccountId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } diff --git a/lib/services/consumptionManagement/lib/operations/index.js b/lib/services/consumptionManagement/lib/operations/index.js index 252d834305..02121b8f57 100644 --- a/lib/services/consumptionManagement/lib/operations/index.js +++ b/lib/services/consumptionManagement/lib/operations/index.js @@ -22,4 +22,5 @@ exports.ReservationRecommendationsOperations = require('./reservationRecommendat exports.Budgets = require('./budgets'); exports.Operations = require('./operations'); exports.PriceSheet = require('./priceSheet'); -exports.CostAllocationTagsOperations = require('./costAllocationTagsOperations'); +exports.CostTagsOperations = require('./costTagsOperations'); +exports.TagsOperations = require('./tagsOperations'); diff --git a/lib/services/consumptionManagement/lib/operations/tagsOperations.js b/lib/services/consumptionManagement/lib/operations/tagsOperations.js new file mode 100644 index 0000000000..5b50ec1792 --- /dev/null +++ b/lib/services/consumptionManagement/lib/operations/tagsOperations.js @@ -0,0 +1,248 @@ +/* + * 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; + +/** + * Get all available tag keys for a billing account. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {object} [options.customHeaders] Headers that will be added to the + * request + * + * @param {function} callback - The callback. + * + * @returns {function} callback(err, result, request, response) + * + * {Error} err - The Error object if an error occurred, null otherwise. + * + * {object} [result] - The deserialized result object if an error did not occur. + * See {@link Tags} 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(billingAccountId, options, callback) { + /* jshint validthis: true */ + let client = this.client; + if(!callback && typeof options === 'function') { + callback = options; + options = null; + } + if (!callback) { + throw new Error('callback cannot be null.'); + } + // Validate + try { + if (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 (billingAccountId === null || billingAccountId === undefined || typeof billingAccountId.valueOf() !== 'string') { + throw new Error('billingAccountId 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('/') ? '' : '/') + 'providers/Microsoft.CostManagement/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/tags'; + requestUrl = requestUrl.replace('{billingAccountId}', encodeURIComponent(billingAccountId)); + let queryParameters = []; + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } + + // Create HTTP transport objects + let httpRequest = new WebResource(); + httpRequest.method = 'GET'; + httpRequest.url = requestUrl; + httpRequest.headers = {}; + // Set Headers + httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; + if (this.client.generateClientRequestId) { + httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid(); + } + if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) { + httpRequest.headers['accept-language'] = this.client.acceptLanguage; + } + if(options) { + for(let headerName in options['customHeaders']) { + if (options['customHeaders'].hasOwnProperty(headerName)) { + httpRequest.headers[headerName] = options['customHeaders'][headerName]; + } + } + } + httpRequest.body = null; + // Send Request + return client.pipeline(httpRequest, (err, response, responseBody) => { + if (err) { + return callback(err); + } + let statusCode = response.statusCode; + if (statusCode !== 200) { + let error = new Error(responseBody); + error.statusCode = response.statusCode; + error.request = msRest.stripRequest(httpRequest); + error.response = msRest.stripResponse(response); + if (responseBody === '') responseBody = null; + let parsedErrorResponse; + try { + parsedErrorResponse = JSON.parse(responseBody); + if (parsedErrorResponse) { + let internalError = null; + if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; + error.code = internalError ? internalError.code : parsedErrorResponse.code; + error.message = internalError ? internalError.message : parsedErrorResponse.message; + } + if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { + let resultMapper = new client.models['ErrorResponse']().mapper(); + error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); + } + } catch (defaultError) { + error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + + `- "${responseBody}" for the default response.`; + return callback(error); + } + return callback(error); + } + // Create Result + let result = null; + if (responseBody === '') responseBody = null; + // Deserialize Response + if (statusCode === 200) { + let parsedResponse = null; + try { + parsedResponse = JSON.parse(responseBody); + result = JSON.parse(responseBody); + if (parsedResponse !== null && parsedResponse !== undefined) { + let resultMapper = new client.models['Tags']().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); + }); +} + +/** Class representing a TagsOperations. */ +class TagsOperations { + /** + * Create a TagsOperations. + * @param {ConsumptionManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._get = _get; + } + + /** + * Get all available tag keys for a billing account. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @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(billingAccountId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._get(billingAccountId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Get all available tag keys for a billing account. + * + * @param {string} billingAccountId Azure Billing Account ID. + * + * @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 {Tags} - 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 Tags} 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(billingAccountId, 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(billingAccountId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._get(billingAccountId, options, optionalCallback); + } + } + +} + +module.exports = TagsOperations; diff --git a/lib/services/consumptionManagement/package.json b/lib/services/consumptionManagement/package.json index e1e34fa462..ec4c66f026 100644 --- a/lib/services/consumptionManagement/package.json +++ b/lib/services/consumptionManagement/package.json @@ -1,35 +1,22 @@ { "name": "azure-arm-consumption", "author": "Microsoft Corporation", - "contributors": [ - "Zavery, Amar " - ], + "description": "ConsumptionManagementClient Library with typescript type definitions for node", "version": "3.1.0", - "description": "Microsoft Azure Consumption Management Client Library for node", - "tags": [ - "azure", - "sdk" - ], - "keywords": [ - "node", - "azure" - ], - "main": "./lib/consumptionManagementClient.js", - "types": "./lib/consumptionManagementClient.d.ts", - "license": "MIT", "dependencies": { - "ms-rest": "^2.3.0", - "ms-rest-azure": "^2.5.2" + "ms-rest": "^2.3.2", + "ms-rest-azure": "^2.5.5" }, - "homepage": "http://github.com/Azure/azure-sdk-for-node", + "keywords": [ "node", "azure" ], + "license": "MIT", + "main": "./lib/consumptionManagementClient.js", + "types": "./lib/consumptionManagementClient.d.ts", + "homepage": "http://github.com/azure/azure-sdk-for-node", "repository": { "type": "git", - "url": "git@github.com:Azure/azure-sdk-for-node.git" + "url": "https://github.com/azure/azure-sdk-for-node.git" }, "bugs": { "url": "http://github.com/Azure/azure-sdk-for-node/issues" - }, - "scripts": { - "test": "npm -s run-script jshint" } }