diff --git a/lib/services/consumptionManagement/lib/consumptionManagementClient.d.ts b/lib/services/consumptionManagement/lib/consumptionManagementClient.d.ts index 553268a074..76f5489dee 100644 --- a/lib/services/consumptionManagement/lib/consumptionManagementClient.d.ts +++ b/lib/services/consumptionManagement/lib/consumptionManagementClient.d.ts @@ -68,6 +68,7 @@ export default class ConsumptionManagementClient extends AzureServiceClient { tags: operations.Tags; forecasts: operations.Forecasts; operations: operations.Operations; + aggregatedCost: operations.AggregatedCost; } export { ConsumptionManagementClient, models as ConsumptionManagementModels }; diff --git a/lib/services/consumptionManagement/lib/consumptionManagementClient.js b/lib/services/consumptionManagement/lib/consumptionManagementClient.js index 1f8173cdbd..e31772a800 100644 --- a/lib/services/consumptionManagement/lib/consumptionManagementClient.js +++ b/lib/services/consumptionManagement/lib/consumptionManagementClient.js @@ -84,6 +84,7 @@ class ConsumptionManagementClient extends ServiceClient { this.tags = new operations.Tags(this); this.forecasts = new operations.Forecasts(this); this.operations = new operations.Operations(this); + this.aggregatedCost = new operations.AggregatedCost(this); this.models = models; msRest.addSerializationMixin(this); } diff --git a/lib/services/consumptionManagement/lib/models/errorResponse.js b/lib/services/consumptionManagement/lib/models/errorResponse.js index c17058b696..e203854eeb 100644 --- a/lib/services/consumptionManagement/lib/models/errorResponse.js +++ b/lib/services/consumptionManagement/lib/models/errorResponse.js @@ -10,8 +10,6 @@ 'use strict'; -const models = require('./index'); - /** * Error response indicates that the service is not able to process the * incoming request. The reason is provided in the error message. diff --git a/lib/services/consumptionManagement/lib/models/index.d.ts b/lib/services/consumptionManagement/lib/models/index.d.ts index 799a163e63..362dba8ff0 100644 --- a/lib/services/consumptionManagement/lib/models/index.d.ts +++ b/lib/services/consumptionManagement/lib/models/index.d.ts @@ -714,6 +714,30 @@ export interface Forecast extends Resource { readonly confidenceLevels?: ForecastPropertiesConfidenceLevelsItem[]; } +/** + * @class + * Initializes a new instance of the ManagementGroupAggregatedCostResult class. + * @constructor + * A management group aggregated cost resource. + * + * @member {string} [billingPeriodId] The id of the billing period resource + * that the aggregated cost belongs to. + * @member {number} [azureCharges] Azure Charges. + * @member {number} [marketplaceCharges] Marketplace Charges. + * @member {number} [chargesBilledSeparately] Charges Billed Separately. + * @member {string} [currency] The ISO currency in which the meter is charged, + * for example, USD. + * @member {array} [children] Children of a management group + */ +export interface ManagementGroupAggregatedCostResult extends Resource { + readonly billingPeriodId?: string; + readonly azureCharges?: number; + readonly marketplaceCharges?: number; + readonly chargesBilledSeparately?: number; + readonly currency?: string; + children?: ManagementGroupAggregatedCostResult[]; +} + /** * @class * Initializes a new instance of the ErrorDetails class. diff --git a/lib/services/consumptionManagement/lib/models/index.js b/lib/services/consumptionManagement/lib/models/index.js index b9ab71cd44..b60bf0642e 100644 --- a/lib/services/consumptionManagement/lib/models/index.js +++ b/lib/services/consumptionManagement/lib/models/index.js @@ -42,6 +42,7 @@ exports.PriceSheetProperties = require('./priceSheetProperties'); exports.PriceSheetResult = require('./priceSheetResult'); exports.ForecastPropertiesConfidenceLevelsItem = require('./forecastPropertiesConfidenceLevelsItem'); exports.Forecast = require('./forecast'); +exports.ManagementGroupAggregatedCostResult = require('./managementGroupAggregatedCostResult'); exports.ErrorDetails = require('./errorDetails'); exports.ErrorResponse = require('./errorResponse'); exports.OperationDisplay = require('./operationDisplay'); diff --git a/lib/services/consumptionManagement/lib/models/managementGroupAggregatedCostResult.js b/lib/services/consumptionManagement/lib/models/managementGroupAggregatedCostResult.js new file mode 100644 index 0000000000..047690cf34 --- /dev/null +++ b/lib/services/consumptionManagement/lib/models/managementGroupAggregatedCostResult.js @@ -0,0 +1,150 @@ +/* + * 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 management group aggregated cost resource. + * + * @extends models['Resource'] + */ +class ManagementGroupAggregatedCostResult extends models['Resource'] { + /** + * Create a ManagementGroupAggregatedCostResult. + * @member {string} [billingPeriodId] The id of the billing period resource + * that the aggregated cost belongs to. + * @member {number} [azureCharges] Azure Charges. + * @member {number} [marketplaceCharges] Marketplace Charges. + * @member {number} [chargesBilledSeparately] Charges Billed Separately. + * @member {string} [currency] The ISO currency in which the meter is + * charged, for example, USD. + * @member {array} [children] Children of a management group + */ + constructor() { + super(); + } + + /** + * Defines the metadata of ManagementGroupAggregatedCostResult + * + * @returns {object} metadata of ManagementGroupAggregatedCostResult + * + */ + mapper() { + return { + required: false, + serializedName: 'ManagementGroupAggregatedCostResult', + type: { + name: 'Composite', + className: 'ManagementGroupAggregatedCostResult', + 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' + } + }, + tags: { + required: false, + readOnly: true, + serializedName: 'tags', + type: { + name: 'Dictionary', + value: { + required: false, + serializedName: 'StringElementType', + type: { + name: 'String' + } + } + } + }, + billingPeriodId: { + required: false, + readOnly: true, + serializedName: 'properties.billingPeriodId', + type: { + name: 'String' + } + }, + azureCharges: { + required: false, + readOnly: true, + serializedName: 'properties.azureCharges', + type: { + name: 'Number' + } + }, + marketplaceCharges: { + required: false, + readOnly: true, + serializedName: 'properties.marketplaceCharges', + type: { + name: 'Number' + } + }, + chargesBilledSeparately: { + required: false, + readOnly: true, + serializedName: 'properties.chargesBilledSeparately', + type: { + name: 'Number' + } + }, + currency: { + required: false, + readOnly: true, + serializedName: 'properties.currency', + type: { + name: 'String' + } + }, + children: { + required: false, + serializedName: 'properties.children', + type: { + name: 'Sequence', + element: { + required: false, + serializedName: 'ManagementGroupAggregatedCostResultElementType', + type: { + name: 'Composite', + className: 'ManagementGroupAggregatedCostResult' + } + } + } + } + } + } + }; + } +} + +module.exports = ManagementGroupAggregatedCostResult; diff --git a/lib/services/consumptionManagement/lib/models/operation.js b/lib/services/consumptionManagement/lib/models/operation.js index 733b297050..ba6e19b841 100644 --- a/lib/services/consumptionManagement/lib/models/operation.js +++ b/lib/services/consumptionManagement/lib/models/operation.js @@ -10,8 +10,6 @@ 'use strict'; -const models = require('./index'); - /** * A Consumption REST API operation. * diff --git a/lib/services/consumptionManagement/lib/models/priceSheetProperties.js b/lib/services/consumptionManagement/lib/models/priceSheetProperties.js index 7fc321d7ef..0f712f77f7 100644 --- a/lib/services/consumptionManagement/lib/models/priceSheetProperties.js +++ b/lib/services/consumptionManagement/lib/models/priceSheetProperties.js @@ -10,8 +10,6 @@ 'use strict'; -const models = require('./index'); - /** * The properties of the price sheet. * diff --git a/lib/services/consumptionManagement/lib/operations/aggregatedCost.js b/lib/services/consumptionManagement/lib/operations/aggregatedCost.js new file mode 100644 index 0000000000..38a73ea954 --- /dev/null +++ b/lib/services/consumptionManagement/lib/operations/aggregatedCost.js @@ -0,0 +1,487 @@ +/* + * 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; + +/** + * Provides the aggregate cost of a management group and all child management + * groups by current billing period. + * + * @param {string} managementGroupId Azure Management Group 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 ManagementGroupAggregatedCostResult} 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 _getByManagementGroup(managementGroupId, 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 (managementGroupId === null || managementGroupId === undefined || typeof managementGroupId.valueOf() !== 'string') { + throw new Error('managementGroupId cannot be null or undefined and it must be of type string.'); + } + if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') { + throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Consumption/aggregatedcost'; + requestUrl = requestUrl.replace('{managementGroupId}', encodeURIComponent(managementGroupId)); + 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['ManagementGroupAggregatedCostResult']().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); + }); +} + +/** + * Provides the aggregate cost of a management group and all child management + * groups by specified billing period + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @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 ManagementGroupAggregatedCostResult} 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 _getForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, 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 (managementGroupId === null || managementGroupId === undefined || typeof managementGroupId.valueOf() !== 'string') { + throw new Error('managementGroupId cannot be null or undefined and it must be of type string.'); + } + if (billingPeriodName === null || billingPeriodName === undefined || typeof billingPeriodName.valueOf() !== 'string') { + throw new Error('billingPeriodName cannot be null or undefined and it must be of type string.'); + } + if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') { + throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.'); + } + if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') { + throw new Error('this.client.acceptLanguage must be of type string.'); + } + } catch (error) { + return callback(error); + } + + // Construct URL + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/Microsoft.Consumption/aggregatedcost'; + requestUrl = requestUrl.replace('{managementGroupId}', encodeURIComponent(managementGroupId)); + requestUrl = requestUrl.replace('{billingPeriodName}', encodeURIComponent(billingPeriodName)); + 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['ManagementGroupAggregatedCostResult']().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 AggregatedCost. */ +class AggregatedCost { + /** + * Create a AggregatedCost. + * @param {ConsumptionManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._getByManagementGroup = _getByManagementGroup; + this._getForBillingPeriodByManagementGroup = _getForBillingPeriodByManagementGroup; + } + + /** + * Provides the aggregate cost of a management group and all child management + * groups by current billing period. + * + * @param {string} managementGroupId Azure Management Group 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. + */ + getByManagementGroupWithHttpOperationResponse(managementGroupId, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getByManagementGroup(managementGroupId, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Provides the aggregate cost of a management group and all child management + * groups by current billing period. + * + * @param {string} managementGroupId Azure Management Group 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 {ManagementGroupAggregatedCostResult} - 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 ManagementGroupAggregatedCostResult} 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. + */ + getByManagementGroup(managementGroupId, 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._getByManagementGroup(managementGroupId, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getByManagementGroup(managementGroupId, options, optionalCallback); + } + } + + /** + * Provides the aggregate cost of a management group and all child management + * groups by specified billing period + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @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. + */ + getForBillingPeriodByManagementGroupWithHttpOperationResponse(managementGroupId, billingPeriodName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._getForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Provides the aggregate cost of a management group and all child management + * groups by specified billing period + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @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 {ManagementGroupAggregatedCostResult} - 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 ManagementGroupAggregatedCostResult} 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. + */ + getForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, 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._getForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._getForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, options, optionalCallback); + } + } + +} + +module.exports = AggregatedCost; diff --git a/lib/services/consumptionManagement/lib/operations/index.d.ts b/lib/services/consumptionManagement/lib/operations/index.d.ts index 7f218b2ea9..26f9723dc7 100644 --- a/lib/services/consumptionManagement/lib/operations/index.d.ts +++ b/lib/services/consumptionManagement/lib/operations/index.d.ts @@ -919,6 +919,234 @@ export interface UsageDetails { listForBillingPeriodByEnrollmentAccount(enrollmentAccountId: string, billingPeriodName: string, options: { expand? : string, filter? : string, skiptoken? : string, top? : number, queryOptions? : models.QueryOptions, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName, properties/instanceId or + * tags. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does + * not currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * + * @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. + */ + listByManagementGroupWithHttpOperationResponse(managementGroupId: string, options?: { expand? : string, filter? : string, skiptoken? : string, top? : number, queryOptions? : models.QueryOptions, customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName, properties/instanceId or + * tags. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does + * not currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * + * @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 {UsageDetailsListResult} - 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. + * + * {UsageDetailsListResult} [result] - The deserialized result object if an error did not occur. + * See {@link UsageDetailsListResult} 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. + */ + listByManagementGroup(managementGroupId: string, options?: { expand? : string, filter? : string, skiptoken? : string, top? : number, queryOptions? : models.QueryOptions, customHeaders? : { [headerName: string]: string; } }): Promise; + listByManagementGroup(managementGroupId: string, callback: ServiceCallback): void; + listByManagementGroup(managementGroupId: string, options: { expand? : string, filter? : string, skiptoken? : string, top? : number, queryOptions? : models.QueryOptions, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName or properties/instanceId. + * The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not + * currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * + * @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. + */ + listForBillingPeriodByManagementGroupWithHttpOperationResponse(managementGroupId: string, billingPeriodName: string, options?: { expand? : string, filter? : string, skiptoken? : string, top? : number, queryOptions? : models.QueryOptions, customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName or properties/instanceId. + * The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not + * currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * + * @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 {UsageDetailsListResult} - 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. + * + * {UsageDetailsListResult} [result] - The deserialized result object if an error did not occur. + * See {@link UsageDetailsListResult} 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. + */ + listForBillingPeriodByManagementGroup(managementGroupId: string, billingPeriodName: string, options?: { expand? : string, filter? : string, skiptoken? : string, top? : number, queryOptions? : models.QueryOptions, customHeaders? : { [headerName: string]: string; } }): Promise; + listForBillingPeriodByManagementGroup(managementGroupId: string, billingPeriodName: string, callback: ServiceCallback): void; + listForBillingPeriodByManagementGroup(managementGroupId: string, billingPeriodName: string, options: { expand? : string, filter? : string, skiptoken? : string, top? : number, queryOptions? : models.QueryOptions, customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + /** * Lists the usage details for a scope by current billing period. Usage details * are available via this API only for May 1, 2014 or later. @@ -1407,6 +1635,130 @@ export interface UsageDetails { listForBillingPeriodByEnrollmentAccountNext(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; listForBillingPeriodByEnrollmentAccountNext(nextPageLink: string, callback: ServiceCallback): void; listForBillingPeriodByEnrollmentAccountNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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. + */ + listByManagementGroupNextWithHttpOperationResponse(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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 {UsageDetailsListResult} - 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. + * + * {UsageDetailsListResult} [result] - The deserialized result object if an error did not occur. + * See {@link UsageDetailsListResult} 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. + */ + listByManagementGroupNext(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + listByManagementGroupNext(nextPageLink: string, callback: ServiceCallback): void; + listByManagementGroupNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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. + */ + listForBillingPeriodByManagementGroupNextWithHttpOperationResponse(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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 {UsageDetailsListResult} - 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. + * + * {UsageDetailsListResult} [result] - The deserialized result object if an error did not occur. + * See {@link UsageDetailsListResult} 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. + */ + listForBillingPeriodByManagementGroupNext(nextPageLink: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + listForBillingPeriodByManagementGroupNext(nextPageLink: string, callback: ServiceCallback): void; + listForBillingPeriodByManagementGroupNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } /** @@ -4711,3 +5063,132 @@ export interface Operations { listNext(nextPageLink: string, callback: ServiceCallback): void; listNext(nextPageLink: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; } + +/** + * @class + * AggregatedCost + * __NOTE__: An instance of this class is automatically created for an + * instance of the ConsumptionManagementClient. + */ +export interface AggregatedCost { + + + /** + * Provides the aggregate cost of a management group and all child management + * groups by current billing period. + * + * @param {string} managementGroupId Azure Management Group 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. + */ + getByManagementGroupWithHttpOperationResponse(managementGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Provides the aggregate cost of a management group and all child management + * groups by current billing period. + * + * @param {string} managementGroupId Azure Management Group 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 {ManagementGroupAggregatedCostResult} - 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. + * + * {ManagementGroupAggregatedCostResult} [result] - The deserialized result object if an error did not occur. + * See {@link ManagementGroupAggregatedCostResult} 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. + */ + getByManagementGroup(managementGroupId: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getByManagementGroup(managementGroupId: string, callback: ServiceCallback): void; + getByManagementGroup(managementGroupId: string, options: { customHeaders? : { [headerName: string]: string; } }, callback: ServiceCallback): void; + + + /** + * Provides the aggregate cost of a management group and all child management + * groups by specified billing period + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @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. + */ + getForBillingPeriodByManagementGroupWithHttpOperationResponse(managementGroupId: string, billingPeriodName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise>; + + /** + * Provides the aggregate cost of a management group and all child management + * groups by specified billing period + * + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @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 {ManagementGroupAggregatedCostResult} - 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. + * + * {ManagementGroupAggregatedCostResult} [result] - The deserialized result object if an error did not occur. + * See {@link ManagementGroupAggregatedCostResult} 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. + */ + getForBillingPeriodByManagementGroup(managementGroupId: string, billingPeriodName: string, options?: { customHeaders? : { [headerName: string]: string; } }): Promise; + getForBillingPeriodByManagementGroup(managementGroupId: string, billingPeriodName: string, callback: ServiceCallback): void; + getForBillingPeriodByManagementGroup(managementGroupId: string, billingPeriodName: 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 092ae808a1..3efc4d203f 100644 --- a/lib/services/consumptionManagement/lib/operations/index.js +++ b/lib/services/consumptionManagement/lib/operations/index.js @@ -26,3 +26,4 @@ exports.CostTags = require('./costTags'); exports.Tags = require('./tags'); exports.Forecasts = require('./forecasts'); exports.Operations = require('./operations'); +exports.AggregatedCost = require('./aggregatedCost'); diff --git a/lib/services/consumptionManagement/lib/operations/usageDetails.js b/lib/services/consumptionManagement/lib/operations/usageDetails.js index ee8056bbad..d8a93fa4fe 100644 --- a/lib/services/consumptionManagement/lib/operations/usageDetails.js +++ b/lib/services/consumptionManagement/lib/operations/usageDetails.js @@ -1784,14 +1784,40 @@ function _listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPe } /** - * Lists the usage details for a scope by current billing period. Usage details - * are available via this API only for May 1, 2014 or later. + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. * - * @param {string} nextPageLink The NextLink from the previous successful call - * to List operation. + * @param {string} managementGroupId Azure Management Group ID. * * @param {object} [options] Optional Parameters. * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName, properties/instanceId or + * tags. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does + * not currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * * @param {object} [options.customHeaders] Headers that will be added to the * request * @@ -1809,7 +1835,7 @@ function _listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPe * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _listNext(nextPageLink, options, callback) { +function _listByManagementGroup(managementGroupId, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -1819,10 +1845,40 @@ function _listNext(nextPageLink, options, callback) { if (!callback) { throw new Error('callback cannot be null.'); } + let expand = (options && options.expand !== undefined) ? options.expand : undefined; + let filter = (options && options.filter !== undefined) ? options.filter : undefined; + let skiptoken = (options && options.skiptoken !== undefined) ? options.skiptoken : undefined; + let top = (options && options.top !== undefined) ? options.top : undefined; + let queryOptions = (options && options.queryOptions !== undefined) ? options.queryOptions : undefined; // Validate try { - if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { - throw new Error('nextPageLink cannot be null or undefined and it must be of type string.'); + if (managementGroupId === null || managementGroupId === undefined || typeof managementGroupId.valueOf() !== 'string') { + throw new Error('managementGroupId cannot be null or undefined and it must be of type string.'); + } + if (expand !== null && expand !== undefined && typeof expand.valueOf() !== 'string') { + throw new Error('expand must be of type string.'); + } + if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') { + throw new Error('filter must be of type string.'); + } + if (skiptoken !== null && skiptoken !== undefined && typeof skiptoken.valueOf() !== 'string') { + throw new Error('skiptoken must be of type string.'); + } + if (top !== null && top !== undefined && typeof top !== 'number') { + throw new Error('top must be of type number.'); + } + if (top !== null && top !== undefined) { + if (top > 1000) + { + throw new Error('"top" should satisfy the constraint - "InclusiveMaximum": 1000'); + } + if (top < 1) + { + throw new Error('"top" should satisfy the constraint - "InclusiveMinimum": 1'); + } + } + 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.'); @@ -1830,10 +1886,43 @@ function _listNext(nextPageLink, options, callback) { } catch (error) { return callback(error); } + let apply; + try { + if (queryOptions !== null && queryOptions !== undefined) + { + apply = queryOptions.apply; + if (apply !== null && apply !== undefined && typeof apply.valueOf() !== 'string') { + throw new Error('apply must be of type string.'); + } + } + } catch (error) { + return callback(error); + } // Construct URL - let requestUrl = '{nextLink}'; - requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Consumption/usageDetails'; + requestUrl = requestUrl.replace('{managementGroupId}', encodeURIComponent(managementGroupId)); + let queryParameters = []; + if (expand !== null && expand !== undefined) { + queryParameters.push('$expand=' + encodeURIComponent(expand)); + } + if (filter !== null && filter !== undefined) { + queryParameters.push('$filter=' + encodeURIComponent(filter)); + } + if (skiptoken !== null && skiptoken !== undefined) { + queryParameters.push('$skiptoken=' + encodeURIComponent(skiptoken)); + } + if (top !== null && top !== undefined) { + queryParameters.push('$top=' + encodeURIComponent(top.toString())); + } + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (apply !== null && apply !== undefined) { + queryParameters.push('$apply=' + encodeURIComponent(apply)); + } + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } // Create HTTP transport objects let httpRequest = new WebResource(); @@ -1914,14 +2003,42 @@ function _listNext(nextPageLink, options, callback) { } /** - * Lists the usage details for a scope by billing period. Usage details are + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are * available via this API only for May 1, 2014 or later. * - * @param {string} nextPageLink The NextLink from the previous successful call - * to List operation. + * @param {string} managementGroupId Azure Management Group ID. + * + * @param {string} billingPeriodName Billing Period Name. * * @param {object} [options] Optional Parameters. * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName or properties/instanceId. + * The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not + * currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * * @param {object} [options.customHeaders] Headers that will be added to the * request * @@ -1939,7 +2056,7 @@ function _listNext(nextPageLink, options, callback) { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _listByBillingPeriodNext(nextPageLink, options, callback) { +function _listForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -1949,10 +2066,43 @@ function _listByBillingPeriodNext(nextPageLink, options, callback) { if (!callback) { throw new Error('callback cannot be null.'); } + let expand = (options && options.expand !== undefined) ? options.expand : undefined; + let filter = (options && options.filter !== undefined) ? options.filter : undefined; + let skiptoken = (options && options.skiptoken !== undefined) ? options.skiptoken : undefined; + let top = (options && options.top !== undefined) ? options.top : undefined; + let queryOptions = (options && options.queryOptions !== undefined) ? options.queryOptions : undefined; // Validate try { - if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { - throw new Error('nextPageLink cannot be null or undefined and it must be of type string.'); + if (managementGroupId === null || managementGroupId === undefined || typeof managementGroupId.valueOf() !== 'string') { + throw new Error('managementGroupId cannot be null or undefined and it must be of type string.'); + } + if (billingPeriodName === null || billingPeriodName === undefined || typeof billingPeriodName.valueOf() !== 'string') { + throw new Error('billingPeriodName cannot be null or undefined and it must be of type string.'); + } + if (expand !== null && expand !== undefined && typeof expand.valueOf() !== 'string') { + throw new Error('expand must be of type string.'); + } + if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') { + throw new Error('filter must be of type string.'); + } + if (skiptoken !== null && skiptoken !== undefined && typeof skiptoken.valueOf() !== 'string') { + throw new Error('skiptoken must be of type string.'); + } + if (top !== null && top !== undefined && typeof top !== 'number') { + throw new Error('top must be of type number.'); + } + if (top !== null && top !== undefined) { + if (top > 1000) + { + throw new Error('"top" should satisfy the constraint - "InclusiveMaximum": 1000'); + } + if (top < 1) + { + throw new Error('"top" should satisfy the constraint - "InclusiveMinimum": 1'); + } + } + 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.'); @@ -1960,10 +2110,44 @@ function _listByBillingPeriodNext(nextPageLink, options, callback) { } catch (error) { return callback(error); } + let apply; + try { + if (queryOptions !== null && queryOptions !== undefined) + { + apply = queryOptions.apply; + if (apply !== null && apply !== undefined && typeof apply.valueOf() !== 'string') { + throw new Error('apply must be of type string.'); + } + } + } catch (error) { + return callback(error); + } // Construct URL - let requestUrl = '{nextLink}'; - requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + let baseUrl = this.client.baseUri; + let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/usageDetails'; + requestUrl = requestUrl.replace('{managementGroupId}', encodeURIComponent(managementGroupId)); + requestUrl = requestUrl.replace('{billingPeriodName}', encodeURIComponent(billingPeriodName)); + let queryParameters = []; + if (expand !== null && expand !== undefined) { + queryParameters.push('$expand=' + encodeURIComponent(expand)); + } + if (filter !== null && filter !== undefined) { + queryParameters.push('$filter=' + encodeURIComponent(filter)); + } + if (skiptoken !== null && skiptoken !== undefined) { + queryParameters.push('$skiptoken=' + encodeURIComponent(skiptoken)); + } + if (top !== null && top !== undefined) { + queryParameters.push('$top=' + encodeURIComponent(top.toString())); + } + queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion)); + if (apply !== null && apply !== undefined) { + queryParameters.push('$apply=' + encodeURIComponent(apply)); + } + if (queryParameters.length > 0) { + requestUrl += '?' + queryParameters.join('&'); + } // Create HTTP transport objects let httpRequest = new WebResource(); @@ -2044,9 +2228,8 @@ function _listByBillingPeriodNext(nextPageLink, options, callback) { } /** - * Lists the usage details by billingAccountId for a scope by current billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage details for a scope by current billing period. Usage details + * are available via this API only for May 1, 2014 or later. * * @param {string} nextPageLink The NextLink from the previous successful call * to List operation. @@ -2070,7 +2253,7 @@ function _listByBillingPeriodNext(nextPageLink, options, callback) { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _listByBillingAccountNext(nextPageLink, options, callback) { +function _listNext(nextPageLink, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -2175,9 +2358,8 @@ function _listByBillingAccountNext(nextPageLink, options, callback) { } /** - * Lists the usage details based on billingAccountId for a scope by billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage details for a scope by billing period. Usage details are + * available via this API only for May 1, 2014 or later. * * @param {string} nextPageLink The NextLink from the previous successful call * to List operation. @@ -2201,7 +2383,7 @@ function _listByBillingAccountNext(nextPageLink, options, callback) { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _listForBillingPeriodByBillingAccountNext(nextPageLink, options, callback) { +function _listByBillingPeriodNext(nextPageLink, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -2306,7 +2488,7 @@ function _listForBillingPeriodByBillingAccountNext(nextPageLink, options, callba } /** - * Lists the usage details by departmentId for a scope by current billing + * Lists the usage details by billingAccountId for a scope by current billing * period. Usage details are available via this API only for May 1, 2014 or * later. * @@ -2332,7 +2514,7 @@ function _listForBillingPeriodByBillingAccountNext(nextPageLink, options, callba * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _listByDepartmentNext(nextPageLink, options, callback) { +function _listByBillingAccountNext(nextPageLink, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -2437,8 +2619,9 @@ function _listByDepartmentNext(nextPageLink, options, callback) { } /** - * Lists the usage details based on departmentId for a scope by billing period. - * Usage details are available via this API only for May 1, 2014 or later. + * Lists the usage details based on billingAccountId for a scope by billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. * * @param {string} nextPageLink The NextLink from the previous successful call * to List operation. @@ -2462,7 +2645,7 @@ function _listByDepartmentNext(nextPageLink, options, callback) { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _listForBillingPeriodByDepartmentNext(nextPageLink, options, callback) { +function _listForBillingPeriodByBillingAccountNext(nextPageLink, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -2567,9 +2750,9 @@ function _listForBillingPeriodByDepartmentNext(nextPageLink, options, callback) } /** - * Lists the usage details by enrollmentAccountId for a scope by current - * billing period. Usage details are available via this API only for May 1, - * 2014 or later. + * Lists the usage details by departmentId for a scope by current billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. * * @param {string} nextPageLink The NextLink from the previous successful call * to List operation. @@ -2593,7 +2776,7 @@ function _listForBillingPeriodByDepartmentNext(nextPageLink, options, callback) * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _listByEnrollmentAccountNext(nextPageLink, options, callback) { +function _listByDepartmentNext(nextPageLink, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -2698,9 +2881,8 @@ function _listByEnrollmentAccountNext(nextPageLink, options, callback) { } /** - * Lists the usage details based on enrollmentAccountId for a scope by billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage details based on departmentId for a scope by billing period. + * Usage details are available via this API only for May 1, 2014 or later. * * @param {string} nextPageLink The NextLink from the previous successful call * to List operation. @@ -2724,7 +2906,7 @@ function _listByEnrollmentAccountNext(nextPageLink, options, callback) { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ -function _listForBillingPeriodByEnrollmentAccountNext(nextPageLink, options, callback) { +function _listForBillingPeriodByDepartmentNext(nextPageLink, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { @@ -2828,22 +3010,548 @@ function _listForBillingPeriodByEnrollmentAccountNext(nextPageLink, options, cal }); } -/** Class representing a UsageDetails. */ -class UsageDetails { - /** - * Create a UsageDetails. - * @param {ConsumptionManagementClient} client Reference to the service client. - */ - constructor(client) { - this.client = client; - this._list = _list; - this._listByBillingPeriod = _listByBillingPeriod; - this._listByBillingAccount = _listByBillingAccount; - this._listForBillingPeriodByBillingAccount = _listForBillingPeriodByBillingAccount; - this._listByDepartment = _listByDepartment; - this._listForBillingPeriodByDepartment = _listForBillingPeriodByDepartment; +/** + * Lists the usage details by enrollmentAccountId for a scope by current + * billing period. Usage details are available via this API only for May 1, + * 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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 UsageDetailsListResult} 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 _listByEnrollmentAccountNext(nextPageLink, 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 (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { + throw new Error('nextPageLink 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 requestUrl = '{nextLink}'; + requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + + // 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['UsageDetailsListResult']().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); + }); +} + +/** + * Lists the usage details based on enrollmentAccountId for a scope by billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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 UsageDetailsListResult} 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 _listForBillingPeriodByEnrollmentAccountNext(nextPageLink, 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 (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { + throw new Error('nextPageLink 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 requestUrl = '{nextLink}'; + requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + + // 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['UsageDetailsListResult']().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); + }); +} + +/** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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 UsageDetailsListResult} 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 _listByManagementGroupNext(nextPageLink, 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 (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { + throw new Error('nextPageLink 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 requestUrl = '{nextLink}'; + requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + + // 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['UsageDetailsListResult']().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); + }); +} + +/** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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 UsageDetailsListResult} 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 _listForBillingPeriodByManagementGroupNext(nextPageLink, 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 (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') { + throw new Error('nextPageLink 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 requestUrl = '{nextLink}'; + requestUrl = requestUrl.replace('{nextLink}', nextPageLink); + + // 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['UsageDetailsListResult']().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 UsageDetails. */ +class UsageDetails { + /** + * Create a UsageDetails. + * @param {ConsumptionManagementClient} client Reference to the service client. + */ + constructor(client) { + this.client = client; + this._list = _list; + this._listByBillingPeriod = _listByBillingPeriod; + this._listByBillingAccount = _listByBillingAccount; + this._listForBillingPeriodByBillingAccount = _listForBillingPeriodByBillingAccount; + this._listByDepartment = _listByDepartment; + this._listForBillingPeriodByDepartment = _listForBillingPeriodByDepartment; this._listByEnrollmentAccount = _listByEnrollmentAccount; this._listForBillingPeriodByEnrollmentAccount = _listForBillingPeriodByEnrollmentAccount; + this._listByManagementGroup = _listByManagementGroup; + this._listForBillingPeriodByManagementGroup = _listForBillingPeriodByManagementGroup; this._listNext = _listNext; this._listByBillingPeriodNext = _listByBillingPeriodNext; this._listByBillingAccountNext = _listByBillingAccountNext; @@ -2852,11 +3560,286 @@ class UsageDetails { this._listForBillingPeriodByDepartmentNext = _listForBillingPeriodByDepartmentNext; this._listByEnrollmentAccountNext = _listByEnrollmentAccountNext; this._listForBillingPeriodByEnrollmentAccountNext = _listForBillingPeriodByEnrollmentAccountNext; + this._listByManagementGroupNext = _listByManagementGroupNext; + this._listForBillingPeriodByManagementGroupNext = _listForBillingPeriodByManagementGroupNext; + } + + /** + * Lists the usage details for a scope by current billing period. Usage details + * are available via this API only for May 1, 2014 or later. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName, properties/instanceId or + * tags. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does + * not currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * + * @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(options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._list(options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists the usage details for a scope by current billing period. Usage details + * are available via this API only for May 1, 2014 or later. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName, properties/instanceId or + * tags. The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does + * not currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * + * @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 {UsageDetailsListResult} - 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 UsageDetailsListResult} 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. + */ + list(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(options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._list(options, optionalCallback); + } } /** - * Lists the usage details for a scope by current billing period. Usage details - * are available via this API only for May 1, 2014 or later. + * Lists the usage details for a scope by billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName or properties/instanceId. + * The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not + * currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * + * @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. + */ + listByBillingPeriodWithHttpOperationResponse(billingPeriodName, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listByBillingPeriod(billingPeriodName, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists the usage details for a scope by billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} billingPeriodName Billing Period Name. + * + * @param {object} [options] Optional Parameters. + * + * @param {string} [options.expand] May be used to expand the + * properties/additionalProperties or properties/meterDetails within a list of + * usage details. By default, these fields are not included when listing usage + * details. + * + * @param {string} [options.filter] May be used to filter usageDetails by + * properties/usageEnd (Utc time), properties/usageStart (Utc time), + * properties/resourceGroup, properties/instanceName or properties/instanceId. + * The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not + * currently support 'ne', 'or', or 'not'. Tag filter is a key value pair + * string where key and value is separated by a colon (:). + * + * @param {string} [options.skiptoken] Skiptoken is only used if a previous + * operation returned a partial result. If a previous response contains a + * nextLink element, the value of the nextLink element will include a skiptoken + * parameter that specifies a starting point to use for subsequent calls. + * + * @param {number} [options.top] May be used to limit the number of results to + * the most recent N usageDetails. + * + * @param {object} [options.queryOptions] Additional parameters for the + * operation + * + * @param {string} [options.queryOptions.apply] OData apply expression to + * aggregate usageDetails by tags or (tags and properties/usageStart) + * + * @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 {UsageDetailsListResult} - 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 UsageDetailsListResult} 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. + */ + listByBillingPeriod(billingPeriodName, 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._listByBillingPeriod(billingPeriodName, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listByBillingPeriod(billingPeriodName, options, optionalCallback); + } + } + + /** + * Lists the usage details by billingAccountId for a scope by current billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. + * + * @param {string} billingAccountId BillingAccount ID * * @param {object} [options] Optional Parameters. * @@ -2895,11 +3878,11 @@ class UsageDetails { * * @reject {Error} - The error object. */ - listWithHttpOperationResponse(options) { + listByBillingAccountWithHttpOperationResponse(billingAccountId, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._list(options, (err, result, request, response) => { + self._listByBillingAccount(billingAccountId, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -2910,8 +3893,11 @@ class UsageDetails { } /** - * Lists the usage details for a scope by current billing period. Usage details - * are available via this API only for May 1, 2014 or later. + * Lists the usage details by billingAccountId for a scope by current billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. + * + * @param {string} billingAccountId BillingAccount ID * * @param {object} [options] Optional Parameters. * @@ -2967,7 +3953,7 @@ class UsageDetails { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - list(options, optionalCallback) { + listByBillingAccount(billingAccountId, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -2976,20 +3962,23 @@ class UsageDetails { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._list(options, (err, result, request, response) => { + self._listByBillingAccount(billingAccountId, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._list(options, optionalCallback); + return self._listByBillingAccount(billingAccountId, options, optionalCallback); } } /** - * Lists the usage details for a scope by billing period. Usage details are - * available via this API only for May 1, 2014 or later. + * Lists the usage details based on billingAccountId for a scope by billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. + * + * @param {string} billingAccountId BillingAccount ID * * @param {string} billingPeriodName Billing Period Name. * @@ -3030,11 +4019,11 @@ class UsageDetails { * * @reject {Error} - The error object. */ - listByBillingPeriodWithHttpOperationResponse(billingPeriodName, options) { + listForBillingPeriodByBillingAccountWithHttpOperationResponse(billingAccountId, billingPeriodName, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listByBillingPeriod(billingPeriodName, options, (err, result, request, response) => { + self._listForBillingPeriodByBillingAccount(billingAccountId, billingPeriodName, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3045,8 +4034,11 @@ class UsageDetails { } /** - * Lists the usage details for a scope by billing period. Usage details are - * available via this API only for May 1, 2014 or later. + * Lists the usage details based on billingAccountId for a scope by billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. + * + * @param {string} billingAccountId BillingAccount ID * * @param {string} billingPeriodName Billing Period Name. * @@ -3104,7 +4096,7 @@ class UsageDetails { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listByBillingPeriod(billingPeriodName, options, optionalCallback) { + listForBillingPeriodByBillingAccount(billingAccountId, billingPeriodName, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3113,23 +4105,23 @@ class UsageDetails { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listByBillingPeriod(billingPeriodName, options, (err, result, request, response) => { + self._listForBillingPeriodByBillingAccount(billingAccountId, billingPeriodName, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listByBillingPeriod(billingPeriodName, options, optionalCallback); + return self._listForBillingPeriodByBillingAccount(billingAccountId, billingPeriodName, options, optionalCallback); } } /** - * Lists the usage details by billingAccountId for a scope by current billing + * Lists the usage details by departmentId for a scope by current billing * period. Usage details are available via this API only for May 1, 2014 or * later. * - * @param {string} billingAccountId BillingAccount ID + * @param {string} departmentId Department ID * * @param {object} [options] Optional Parameters. * @@ -3168,11 +4160,11 @@ class UsageDetails { * * @reject {Error} - The error object. */ - listByBillingAccountWithHttpOperationResponse(billingAccountId, options) { + listByDepartmentWithHttpOperationResponse(departmentId, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listByBillingAccount(billingAccountId, options, (err, result, request, response) => { + self._listByDepartment(departmentId, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3183,11 +4175,11 @@ class UsageDetails { } /** - * Lists the usage details by billingAccountId for a scope by current billing + * Lists the usage details by departmentId for a scope by current billing * period. Usage details are available via this API only for May 1, 2014 or * later. * - * @param {string} billingAccountId BillingAccount ID + * @param {string} departmentId Department ID * * @param {object} [options] Optional Parameters. * @@ -3243,7 +4235,7 @@ class UsageDetails { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listByBillingAccount(billingAccountId, options, optionalCallback) { + listByDepartment(departmentId, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3252,23 +4244,22 @@ class UsageDetails { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listByBillingAccount(billingAccountId, options, (err, result, request, response) => { + self._listByDepartment(departmentId, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listByBillingAccount(billingAccountId, options, optionalCallback); + return self._listByDepartment(departmentId, options, optionalCallback); } } /** - * Lists the usage details based on billingAccountId for a scope by billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage details based on departmentId for a scope by billing period. + * Usage details are available via this API only for May 1, 2014 or later. * - * @param {string} billingAccountId BillingAccount ID + * @param {string} departmentId Department ID * * @param {string} billingPeriodName Billing Period Name. * @@ -3309,11 +4300,11 @@ class UsageDetails { * * @reject {Error} - The error object. */ - listForBillingPeriodByBillingAccountWithHttpOperationResponse(billingAccountId, billingPeriodName, options) { + listForBillingPeriodByDepartmentWithHttpOperationResponse(departmentId, billingPeriodName, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listForBillingPeriodByBillingAccount(billingAccountId, billingPeriodName, options, (err, result, request, response) => { + self._listForBillingPeriodByDepartment(departmentId, billingPeriodName, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3324,11 +4315,10 @@ class UsageDetails { } /** - * Lists the usage details based on billingAccountId for a scope by billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage details based on departmentId for a scope by billing period. + * Usage details are available via this API only for May 1, 2014 or later. * - * @param {string} billingAccountId BillingAccount ID + * @param {string} departmentId Department ID * * @param {string} billingPeriodName Billing Period Name. * @@ -3386,7 +4376,7 @@ class UsageDetails { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listForBillingPeriodByBillingAccount(billingAccountId, billingPeriodName, options, optionalCallback) { + listForBillingPeriodByDepartment(departmentId, billingPeriodName, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3395,23 +4385,23 @@ class UsageDetails { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listForBillingPeriodByBillingAccount(billingAccountId, billingPeriodName, options, (err, result, request, response) => { + self._listForBillingPeriodByDepartment(departmentId, billingPeriodName, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listForBillingPeriodByBillingAccount(billingAccountId, billingPeriodName, options, optionalCallback); + return self._listForBillingPeriodByDepartment(departmentId, billingPeriodName, options, optionalCallback); } } /** - * Lists the usage details by departmentId for a scope by current billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage details by enrollmentAccountId for a scope by current + * billing period. Usage details are available via this API only for May 1, + * 2014 or later. * - * @param {string} departmentId Department ID + * @param {string} enrollmentAccountId EnrollmentAccount ID * * @param {object} [options] Optional Parameters. * @@ -3450,11 +4440,11 @@ class UsageDetails { * * @reject {Error} - The error object. */ - listByDepartmentWithHttpOperationResponse(departmentId, options) { + listByEnrollmentAccountWithHttpOperationResponse(enrollmentAccountId, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listByDepartment(departmentId, options, (err, result, request, response) => { + self._listByEnrollmentAccount(enrollmentAccountId, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3465,11 +4455,11 @@ class UsageDetails { } /** - * Lists the usage details by departmentId for a scope by current billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage details by enrollmentAccountId for a scope by current + * billing period. Usage details are available via this API only for May 1, + * 2014 or later. * - * @param {string} departmentId Department ID + * @param {string} enrollmentAccountId EnrollmentAccount ID * * @param {object} [options] Optional Parameters. * @@ -3525,7 +4515,7 @@ class UsageDetails { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listByDepartment(departmentId, options, optionalCallback) { + listByEnrollmentAccount(enrollmentAccountId, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3534,22 +4524,23 @@ class UsageDetails { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listByDepartment(departmentId, options, (err, result, request, response) => { + self._listByEnrollmentAccount(enrollmentAccountId, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listByDepartment(departmentId, options, optionalCallback); + return self._listByEnrollmentAccount(enrollmentAccountId, options, optionalCallback); } } /** - * Lists the usage details based on departmentId for a scope by billing period. - * Usage details are available via this API only for May 1, 2014 or later. + * Lists the usage details based on enrollmentAccountId for a scope by billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. * - * @param {string} departmentId Department ID + * @param {string} enrollmentAccountId EnrollmentAccount ID * * @param {string} billingPeriodName Billing Period Name. * @@ -3590,11 +4581,11 @@ class UsageDetails { * * @reject {Error} - The error object. */ - listForBillingPeriodByDepartmentWithHttpOperationResponse(departmentId, billingPeriodName, options) { + listForBillingPeriodByEnrollmentAccountWithHttpOperationResponse(enrollmentAccountId, billingPeriodName, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listForBillingPeriodByDepartment(departmentId, billingPeriodName, options, (err, result, request, response) => { + self._listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPeriodName, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3605,10 +4596,11 @@ class UsageDetails { } /** - * Lists the usage details based on departmentId for a scope by billing period. - * Usage details are available via this API only for May 1, 2014 or later. + * Lists the usage details based on enrollmentAccountId for a scope by billing + * period. Usage details are available via this API only for May 1, 2014 or + * later. * - * @param {string} departmentId Department ID + * @param {string} enrollmentAccountId EnrollmentAccount ID * * @param {string} billingPeriodName Billing Period Name. * @@ -3666,7 +4658,7 @@ class UsageDetails { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listForBillingPeriodByDepartment(departmentId, billingPeriodName, options, optionalCallback) { + listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPeriodName, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3675,23 +4667,23 @@ class UsageDetails { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listForBillingPeriodByDepartment(departmentId, billingPeriodName, options, (err, result, request, response) => { + self._listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPeriodName, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listForBillingPeriodByDepartment(departmentId, billingPeriodName, options, optionalCallback); + return self._listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPeriodName, options, optionalCallback); } } /** - * Lists the usage details by enrollmentAccountId for a scope by current - * billing period. Usage details are available via this API only for May 1, - * 2014 or later. + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. * - * @param {string} enrollmentAccountId EnrollmentAccount ID + * @param {string} managementGroupId Azure Management Group ID. * * @param {object} [options] Optional Parameters. * @@ -3730,11 +4722,11 @@ class UsageDetails { * * @reject {Error} - The error object. */ - listByEnrollmentAccountWithHttpOperationResponse(enrollmentAccountId, options) { + listByManagementGroupWithHttpOperationResponse(managementGroupId, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listByEnrollmentAccount(enrollmentAccountId, options, (err, result, request, response) => { + self._listByManagementGroup(managementGroupId, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3745,11 +4737,11 @@ class UsageDetails { } /** - * Lists the usage details by enrollmentAccountId for a scope by current - * billing period. Usage details are available via this API only for May 1, - * 2014 or later. + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. * - * @param {string} enrollmentAccountId EnrollmentAccount ID + * @param {string} managementGroupId Azure Management Group ID. * * @param {object} [options] Optional Parameters. * @@ -3805,7 +4797,7 @@ class UsageDetails { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listByEnrollmentAccount(enrollmentAccountId, options, optionalCallback) { + listByManagementGroup(managementGroupId, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3814,23 +4806,23 @@ class UsageDetails { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listByEnrollmentAccount(enrollmentAccountId, options, (err, result, request, response) => { + self._listByManagementGroup(managementGroupId, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listByEnrollmentAccount(enrollmentAccountId, options, optionalCallback); + return self._listByManagementGroup(managementGroupId, options, optionalCallback); } } /** - * Lists the usage details based on enrollmentAccountId for a scope by billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. * - * @param {string} enrollmentAccountId EnrollmentAccount ID + * @param {string} managementGroupId Azure Management Group ID. * * @param {string} billingPeriodName Billing Period Name. * @@ -3871,11 +4863,11 @@ class UsageDetails { * * @reject {Error} - The error object. */ - listForBillingPeriodByEnrollmentAccountWithHttpOperationResponse(enrollmentAccountId, billingPeriodName, options) { + listForBillingPeriodByManagementGroupWithHttpOperationResponse(managementGroupId, billingPeriodName, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { - self._listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPeriodName, options, (err, result, request, response) => { + self._listForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } @@ -3886,11 +4878,11 @@ class UsageDetails { } /** - * Lists the usage details based on enrollmentAccountId for a scope by billing - * period. Usage details are available via this API only for May 1, 2014 or - * later. + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. * - * @param {string} enrollmentAccountId EnrollmentAccount ID + * @param {string} managementGroupId Azure Management Group ID. * * @param {string} billingPeriodName Billing Period Name. * @@ -3948,7 +4940,7 @@ class UsageDetails { * * {stream} [response] - The HTTP Response stream if an error did not occur. */ - listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPeriodName, options, optionalCallback) { + listForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { @@ -3957,14 +4949,14 @@ class UsageDetails { } if (!optionalCallback) { return new Promise((resolve, reject) => { - self._listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPeriodName, options, (err, result, request, response) => { + self._listForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { - return self._listForBillingPeriodByEnrollmentAccount(enrollmentAccountId, billingPeriodName, options, optionalCallback); + return self._listForBillingPeriodByManagementGroup(managementGroupId, billingPeriodName, options, optionalCallback); } } @@ -4674,6 +5666,184 @@ class UsageDetails { } } + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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. + */ + listByManagementGroupNextWithHttpOperationResponse(nextPageLink, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listByManagementGroupNext(nextPageLink, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by current billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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 {UsageDetailsListResult} - 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 UsageDetailsListResult} 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. + */ + listByManagementGroupNext(nextPageLink, 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._listByManagementGroupNext(nextPageLink, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listByManagementGroupNext(nextPageLink, options, optionalCallback); + } + } + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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. + */ + listForBillingPeriodByManagementGroupNextWithHttpOperationResponse(nextPageLink, options) { + let client = this.client; + let self = this; + return new Promise((resolve, reject) => { + self._listForBillingPeriodByManagementGroupNext(nextPageLink, options, (err, result, request, response) => { + let httpOperationResponse = new msRest.HttpOperationResponse(request, response); + httpOperationResponse.body = result; + if (err) { reject(err); } + else { resolve(httpOperationResponse); } + return; + }); + }); + } + + /** + * Lists the usage detail records for all subscriptions belonging to a + * management group scope by specified billing period. Usage details are + * available via this API only for May 1, 2014 or later. + * + * @param {string} nextPageLink The NextLink from the previous successful call + * to List operation. + * + * @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 {UsageDetailsListResult} - 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 UsageDetailsListResult} 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. + */ + listForBillingPeriodByManagementGroupNext(nextPageLink, 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._listForBillingPeriodByManagementGroupNext(nextPageLink, options, (err, result, request, response) => { + if (err) { reject(err); } + else { resolve(result); } + return; + }); + }); + } else { + return self._listForBillingPeriodByManagementGroupNext(nextPageLink, options, optionalCallback); + } + } + } module.exports = UsageDetails; diff --git a/lib/services/consumptionManagement/package-lock.json b/lib/services/consumptionManagement/package-lock.json index dfd0ebe305..20ab62ed01 100644 --- a/lib/services/consumptionManagement/package-lock.json +++ b/lib/services/consumptionManagement/package-lock.json @@ -1,6 +1,6 @@ { "name": "azure-arm-consumption", - "version": "5.0.0", + "version": "5.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/lib/services/consumptionManagement/package.json b/lib/services/consumptionManagement/package.json index d567c98a89..01b2153fcd 100644 --- a/lib/services/consumptionManagement/package.json +++ b/lib/services/consumptionManagement/package.json @@ -2,7 +2,7 @@ "name": "azure-arm-consumption", "author": "Microsoft Corporation", "description": "ConsumptionManagementClient Library with typescript type definitions for node", - "version": "5.0.0", + "version": "5.1.0", "dependencies": { "ms-rest": "^2.3.3", "ms-rest-azure": "^2.5.5" @@ -14,7 +14,7 @@ "license": "MIT", "main": "./lib/consumptionManagementClient.js", "types": "./lib/consumptionManagementClient.d.ts", - "homepage": "https://github.com/azure/azure-sdk-for-node/lib/services/consumptionManagement", + "homepage": "https://github.com/azure/azure-sdk-for-node/tree/master/lib/services/consumptionManagement", "repository": { "type": "git", "url": "https://github.com/azure/azure-sdk-for-node.git"