@ibm-cloud/platform-services
Version:
Node.js client library for IBM Cloud Platform Services
392 lines • 18.9 kB
JavaScript
/**
* (C) Copyright IBM Corp. 2021.
*
* 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: 3.41.0-f1ef0102-20211018-193503
*/
var extend = require("extend");
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
var common_1 = require("../lib/common");
/**
* Manage lifecycle of your Cloud resource groups using Resource Manager APIs.
*
* API Version: 2.0
*/
var ResourceManagerV2 = /** @class */ (function (_super) {
__extends(ResourceManagerV2, _super);
/**
* Construct a ResourceManagerV2 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 {ResourceManagerV2}
*/
function ResourceManagerV2(options) {
var _this = this;
options = options || {};
_this = _super.call(this, options) || this;
if (options.serviceUrl) {
_this.setServiceUrl(options.serviceUrl);
}
else {
_this.setServiceUrl(ResourceManagerV2.DEFAULT_SERVICE_URL);
}
return _this;
}
/*************************
* Factory method
************************/
/**
* Constructs an instance of ResourceManagerV2 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 {ResourceManagerV2}
*/
ResourceManagerV2.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 ResourceManagerV2(options);
service.configureService(options.serviceName);
if (options.serviceUrl) {
service.setServiceUrl(options.serviceUrl);
}
return service;
};
/*************************
* resourceGroup
************************/
/**
* Get a list of all resource groups.
*
* Call this method to retrieve information about all resource groups and associated quotas in an account. The `id`
* returned in the response can be used to [create a resource instance
* later](https://cloud.ibm.com/apidocs/resource-controller/resource-controller?code=java#create-resource-instance).
* The response can be filtered based on queryParams such as `account_id`, `name`, `default`, and more to narrow your
* search.Users need to be assigned IAM policies with the Viewer role or higher on the targeted resource groups.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.accountId] - The ID of the account that contains the resource groups that you want to get.
* @param {string} [params.date] - The date in the format of YYYY-MM which returns resource groups. Deleted resource
* groups will be excluded before this month.
* @param {string} [params.name] - The name of the resource group.
* @param {boolean} [params._default] - Boolean value to specify whether or not to list default resource groups.
* @param {boolean} [params.includeDeleted] - Boolean value to specify whether or not to list default resource groups.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<ResourceManagerV2.Response<ResourceManagerV2.ResourceGroupList>>}
*/
ResourceManagerV2.prototype.listResourceGroups = function (params) {
var _params = __assign({}, params);
var query = {
'account_id': _params.accountId,
'date': _params.date,
'name': _params.name,
'default': _params._default,
'include_deleted': _params.includeDeleted,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'listResourceGroups');
var parameters = {
options: {
url: '/v2/resource_groups',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Create a resource group.
*
* Create a resource group in an account to organize your account resources in customizable groupings so that you can
* quickly assign users access to more than one resource at a time. To learn what makes a good resource group
* strategy, see [Best practices for organizing
* resources](https://cloud.ibm.com/docs/account?topic=account-account_setup). A default resource group is created
* when an account is created. If you have a Lite account or 30-day trial, you cannot create extra resource groups,
* but you can rename your default resource group. If you have a Pay-As-You-Go or Subscription account, you can create
* multiple resource groups. You must be assigned an IAM policy with the Administrator role on All Account Management
* services to create extra resource groups.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.name] - The new name of the resource group.
* @param {string} [params.accountId] - The account id of the resource group.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<ResourceManagerV2.Response<ResourceManagerV2.ResCreateResourceGroup>>}
*/
ResourceManagerV2.prototype.createResourceGroup = function (params) {
var _params = __assign({}, params);
var body = {
'name': _params.name,
'account_id': _params.accountId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'createResourceGroup');
var parameters = {
options: {
url: '/v2/resource_groups',
method: 'POST',
body: body,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get a resource group.
*
* Retrieve a resource group by alias ID. Call this method to get details about a particular resource group, like the
* name of the resource group, associated quotas, whether the state is active, the resource group ID and the CRN. The
* `id` returned in the response can be used to [create a resource instance
* later](https://cloud.ibm.com/apidocs/resource-controller/resource-controller?code=java#create-resource-instance).
* Users need to be assigned an IAM policy with the Viewer role or higher on the targeted resource group.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.id - The short or long ID of the alias.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<ResourceManagerV2.Response<ResourceManagerV2.ResourceGroup>>}
*/
ResourceManagerV2.prototype.getResourceGroup = function (params) {
var _params = __assign({}, params);
var requiredParams = ['id'];
var missingParams = (0, ibm_cloud_sdk_core_1.getMissingParams)(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
}
var path = {
'id': _params.id,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'getResourceGroup');
var parameters = {
options: {
url: '/v2/resource_groups/{id}',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update a resource group.
*
* Update a resource group by the alias ID. Call this method to update information about an existing resource group.
* You can rename a resource group and activate or suspend a particular resource group. To update a resource group,
* users need to be assigned with IAM policies with the Editor role or higher.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.id - The short or long ID of the alias.
* @param {string} [params.name] - The new name of the resource group.
* @param {string} [params.state] - The state of the resource group.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<ResourceManagerV2.Response<ResourceManagerV2.ResourceGroup>>}
*/
ResourceManagerV2.prototype.updateResourceGroup = function (params) {
var _params = __assign({}, params);
var requiredParams = ['id'];
var missingParams = (0, ibm_cloud_sdk_core_1.getMissingParams)(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
}
var body = {
'name': _params.name,
'state': _params.state,
};
var path = {
'id': _params.id,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'updateResourceGroup');
var parameters = {
options: {
url: '/v2/resource_groups/{id}',
method: 'PATCH',
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);
};
/**
* Delete a resource group.
*
* Delete a resource group by the alias ID. You can delete a resource group only if the targeted resource group does
* not contain any resources or if it is not a default resource group. When a user creates an account, a default
* resource group is created in the account. If you want to delete a resource group that contains resources, first
* [delete the resource
* instances](https://cloud.ibm.com/apidocs/resource-controller/resource-controller?code=java#delete-resource-instance).
* Then, delete the resource group when all resource instances in the group are deleted. Users need to be assigned an
* IAM policy with the Editor role or higher on the targeted resource group.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.id - The short or long ID of the alias.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<ResourceManagerV2.Response<ResourceManagerV2.Empty>>}
*/
ResourceManagerV2.prototype.deleteResourceGroup = function (params) {
var _params = __assign({}, params);
var requiredParams = ['id'];
var missingParams = (0, ibm_cloud_sdk_core_1.getMissingParams)(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
}
var path = {
'id': _params.id,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteResourceGroup');
var parameters = {
options: {
url: '/v2/resource_groups/{id}',
method: 'DELETE',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* quotaDefinition
************************/
/**
* List quota definitions.
*
* Get a list of all quota definitions. Quotas for a resource group limit the number of apps, instances, and memory
* allowed for that specific resource group. Each resource group that you have on your account has a specific set of
* quotas. Standard quotas are for resource groups that are created by users with a Lite account, and Pay-As-You-Go
* quotas are for resource groups that are created with a Pay-As-You-Go account. This method provides list of all
* available quota definitions. No specific IAM policy needed.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<ResourceManagerV2.Response<ResourceManagerV2.QuotaDefinitionList>>}
*/
ResourceManagerV2.prototype.listQuotaDefinitions = function (params) {
var _params = __assign({}, params);
var sdkHeaders = (0, common_1.getSdkHeaders)(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'listQuotaDefinitions');
var parameters = {
options: {
url: '/v2/quota_definitions',
method: 'GET',
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get a quota definition.
*
* Call this method to retrieve information about a particular quota by passing the quota ID. The response can be used
* to identify the quota type, Standard or Paid. Information about available resources, such as number of apps, number
* of service instances, and memory, are returned in the response. Quotas for a resource group limit the number of
* apps, instances, and memory allowed for that specific resource group. Each resource group that you have on your
* account has a specific set of quotas. Standard quotas are for resource groups that are created by users with a Lite
* account, and Pay-As-You-Go quotas are for resource groups that are created with a Pay-As-You-Go account. No
* specific IAM policy needed.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.id - The id of the quota.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<ResourceManagerV2.Response<ResourceManagerV2.QuotaDefinition>>}
*/
ResourceManagerV2.prototype.getQuotaDefinition = function (params) {
var _params = __assign({}, params);
var requiredParams = ['id'];
var missingParams = (0, ibm_cloud_sdk_core_1.getMissingParams)(_params, requiredParams);
if (missingParams) {
return Promise.reject(missingParams);
}
var path = {
'id': _params.id,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(ResourceManagerV2.DEFAULT_SERVICE_NAME, 'v2', 'getQuotaDefinition');
var parameters = {
options: {
url: '/v2/quota_definitions/{id}',
method: 'GET',
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
ResourceManagerV2.DEFAULT_SERVICE_URL = 'https://resource-controller.cloud.ibm.com';
ResourceManagerV2.DEFAULT_SERVICE_NAME = 'resource_manager';
return ResourceManagerV2;
}(ibm_cloud_sdk_core_1.BaseService));
module.exports = ResourceManagerV2;
//# sourceMappingURL=v2.js.map
;