@ibm-cloud/platform-services
Version:
Node.js client library for IBM Cloud Platform Services
154 lines • 6.83 kB
JavaScript
/**
* (C) Copyright IBM Corp. 2020.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* IBM OpenAPI SDK Code Generator Version: 99-SNAPSHOT-d753183b-20201209-163011
*/
var extend = require("extend");
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
var common_1 = require("../lib/common");
/**
* IBM Cloud Usage Metering is a platform service that enables service providers to submit metrics collected for
* resource instances provisioned by IBM Cloud users. IBM and third-party service providers that are delivering an
* integrated billing service in IBM Cloud are required to submit usage for all active service instances every hour.
* This is important because inability to report usage can lead to loss of revenue collection for IBM, in turn causing
* loss of revenue share for the service providers.
*/
var UsageMeteringV4 = /** @class */ (function (_super) {
__extends(UsageMeteringV4, _super);
/**
* Construct a UsageMeteringV4 object.
*
* @param {Object} options - Options for the service.
* @param {string} [options.serviceUrl] - The base url to use when contacting the service. The base url may differ between IBM Cloud regions.
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
* @param {Authenticator} options.authenticator - The Authenticator object used to authenticate requests to the service
* @constructor
* @returns {UsageMeteringV4}
*/
function UsageMeteringV4(options) {
var _this = this;
options = options || {};
_this = _super.call(this, options) || this;
if (options.serviceUrl) {
_this.setServiceUrl(options.serviceUrl);
}
else {
_this.setServiceUrl(UsageMeteringV4.DEFAULT_SERVICE_URL);
}
return _this;
}
/*************************
* Factory method
************************/
/**
* Constructs an instance of UsageMeteringV4 with passed in options and external configuration.
*
* @param {UserOptions} [options] - The parameters to send to the service.
* @param {string} [options.serviceName] - The name of the service to configure
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service
* @param {string} [options.serviceUrl] - The URL for the service
* @returns {UsageMeteringV4}
*/
UsageMeteringV4.newInstance = function (options) {
options = options || {};
if (!options.serviceName) {
options.serviceName = this.DEFAULT_SERVICE_NAME;
}
if (!options.authenticator) {
options.authenticator = (0, ibm_cloud_sdk_core_1.getAuthenticatorFromEnvironment)(options.serviceName);
}
var service = new UsageMeteringV4(options);
service.configureService(options.serviceName);
if (options.serviceUrl) {
service.setServiceUrl(options.serviceUrl);
}
return service;
};
/*************************
* resourceUsage
************************/
/**
* Report Resource Controller resource usage.
*
* Report usage for resource instances that were provisioned through the resource controller.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.resourceId - The resource for which the usage is submitted.
* @param {ResourceInstanceUsage[]} params.resourceUsage -
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<UsageMeteringV4.Response<UsageMeteringV4.ResponseAccepted>>}
*/
UsageMeteringV4.prototype.reportResourceUsage = function (params) {
var _params = __assign({}, params);
var requiredParams = ['resourceId', 'resourceUsage'];
var missingParams = (0, ibm_cloud_sdk_core_1.getMissingParams)(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
}
var body = _params.resourceUsage;
var path = {
'resource_id': _params.resourceId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(UsageMeteringV4.DEFAULT_SERVICE_NAME, 'v4', 'reportResourceUsage');
var parameters = {
options: {
url: '/v4/metering/resources/{resource_id}/usage',
method: 'POST',
body: body,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
UsageMeteringV4.DEFAULT_SERVICE_URL = 'https://billing.cloud.ibm.com';
UsageMeteringV4.DEFAULT_SERVICE_NAME = 'usage_metering';
return UsageMeteringV4;
}(ibm_cloud_sdk_core_1.BaseService));
module.exports = UsageMeteringV4;
//# sourceMappingURL=v4.js.map
;