@ibm-cloud/platform-services
Version:
Node.js client library for IBM Cloud Platform Services
278 lines • 15.9 kB
JavaScript
/**
* (C) Copyright IBM Corp. 2025.
*
* 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.100.0-2ad7a784-20250212-162551
*/
var extend = require("extend");
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
var common_1 = require("../lib/common");
/**
* Search for resources with the global and shared resource properties repository that is integrated in the IBM Cloud
* platform. The search repository stores and searches cloud resources attributes, which categorize or classify
* resources. A resource is a physical or logical component that can be created or reserved for an application or
* service instance. They are owned by resource providers, such as IBM Kubernetes Service, or resource controller in IBM
* Cloud. Resources are uniquely identified by a Cloud Resource Name (CRN) or by an IMS ID. The properties of a resource
* include tags and system properties. Both properties are defined in an IBM Cloud billing account, and span across many
* regions.
*
* API Version: 2.0.1
*/
var GlobalSearchV2 = /** @class */ (function (_super) {
__extends(GlobalSearchV2, _super);
/**
* Construct a GlobalSearchV2 object.
*
* @param {Object} options - Options for the service.
* @param {string} [options.serviceUrl] - The base URL for the service
* @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 {GlobalSearchV2}
*/
function GlobalSearchV2(options) {
var _this = this;
options = options || {};
_this = _super.call(this, options) || this;
if (options.serviceUrl) {
_this.setServiceUrl(options.serviceUrl);
}
else {
_this.setServiceUrl(GlobalSearchV2.DEFAULT_SERVICE_URL);
}
return _this;
}
/*************************
* Factory method
************************/
/**
* Constructs an instance of GlobalSearchV2 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 base URL for the service
* @returns {GlobalSearchV2}
*/
GlobalSearchV2.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 GlobalSearchV2(options);
service.configureService(options.serviceName);
if (options.serviceUrl) {
service.setServiceUrl(options.serviceUrl);
}
return service;
};
/*************************
* search
************************/
/**
* Find instances of resources (v3).
*
* Find IAM-enabled resources or storage and network resources that run on classic infrastructure in a specific
* account ID.
*
* You must use `/v3/resources/search` when you need to fetch more than `10000` resource items. On the first call, the
* operation returns a live cursor on the data that you must use on all the subsequent calls to get the next batch of
* results until you get the empty result set.
*
* To filter results, you can apply query strings following the *Lucene* query syntax.
*
* By default, the fields that are returned for every resource are **crn**, **name**,
* **family**, **type**, and **account_id**. You can specify the subset of the fields you want in your request using
* the `fields` request body attribute. Set `"fields": ["*"]` to discover the complete set of fields which are
* available to request.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.query] - The Lucene-formatted query string. Default to '*' if not set.
* @param {string[]} [params.fields] - The list of the fields returned by the search. By default, the returned fields
* are the `account_id`, `name`, `type`, `family`, and `crn`. For all queries, `crn` is always returned. You may set
* `"fields": ["*"]` to discover the set of fields available to request.
* @param {string} [params.searchCursor] - An opaque cursor that is returned on each call and that must be set on the
* subsequent call to get the next batch of items. You can stop paging when the search returns less items than the
* specified `limit` or when the `search_cursor` is not present in the response. NOTE: when setting this parameter,
* any other properties present in the body will be ignored.
* @param {string} [params.xRequestId] - An alphanumeric string that is used to trace the request. The value may
* include ASCII alphanumerics and any of following segment separators: space ( ), comma (,), hyphen, (-), and
* underscore (_) and may have a length up to 1024 bytes. The value is considered invalid and must be ignored if that
* value includes any other character or is longer than 1024 bytes or is fewer than 8 characters. If not specified or
* invalid, it is automatically replaced by a random (version 4) UUID.
* @param {string} [params.xCorrelationId] - An alphanumeric string that is used to trace the request as a part of a
* larger context: the same value is used for downstream requests and retries of those requests. The value may include
* ASCII alphanumerics and any of following segment separators: space ( ), comma (,), hyphen, (-), and underscore (_)
* and may have a length up to 1024 bytes. The value is considered invalid and must be ignored if that value includes
* any other character or is longer than 1024 bytes or is fewer than 8 characters. If not specified or invalid, it is
* automatically replaced by a random (version 4) UUID.
* @param {string} [params.accountId] - The account ID to filter resources.
* @param {number} [params.limit] - The maximum number of hits to return. Defaults to 10.
* @param {number} [params.timeout] - A search timeout in milliseconds, bounding the search request to run within the
* specified time value and bail with the hits accumulated up to that point when expired. Defaults to the system
* defined timeout.
* @param {string[]} [params.sort] - Comma separated properties names that are used for sorting.
* @param {string} [params.isDeleted] - Determines if deleted documents should be included in result set or not.
* Possible values are false (default), true or any. If false, only existing documents are returned; if true, only
* deleted documents are returned; If any, both existing and deleted documents are returned. (_for administrators
* only_).
* @param {string} [params.isReclaimed] - Determines if reclaimed documents should be included in result set or not.
* Possible values are false (default), true or any. If false, only not reclaimed documents are returned; if true,
* only reclaimed documents are returned; If any, both reclaimed and not reclaimed documents are returned.
* @param {string} [params.impersonateUser] - The user on whose behalf the search must be performed. Only a GhoST
* admin can impersonate a user, so be sure you set a GhoST admin IAM token in the Authorization header if you set
* this parameter. (_for administrators only_).
* @param {string} [params.canTag] - Determines if the result set must return the resources that the user can tag or
* the resources that the user can view (only a GhoST admin can use this parameter). If false (default), only
* resources user can view are returned; if true, only resources that user has permissions for tagging are returned
* (_for administrators only_).
* @param {string} [params.isProjectResource] - Determines if documents belonging to Project family should be included
* in result set or not. Possible values are false (default), true or any. If false, documents belonging to all
* families except Project are returned; if true, only documents belonging to Project family are returned; if any,
* documents of any family are returned. Only authorized ServiceIds can use this query parameter.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<GlobalSearchV2.Response<GlobalSearchV2.ScanResult>>}
*/
GlobalSearchV2.prototype.search = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = [
'query',
'fields',
'searchCursor',
'xRequestId',
'xCorrelationId',
'accountId',
'limit',
'timeout',
'sort',
'isDeleted',
'isReclaimed',
'impersonateUser',
'canTag',
'isProjectResource',
'headers',
];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'query': _params.query,
'fields': _params.fields,
'search_cursor': _params.searchCursor,
};
var query = {
'account_id': _params.accountId,
'limit': _params.limit,
'timeout': _params.timeout,
'sort': _params.sort,
'is_deleted': _params.isDeleted,
'is_reclaimed': _params.isReclaimed,
'impersonate_user': _params.impersonateUser,
'can_tag': _params.canTag,
'is_project_resource': _params.isProjectResource,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(GlobalSearchV2.DEFAULT_SERVICE_NAME, 'v2', 'search');
var parameters = {
options: {
url: '/v3/resources/search',
method: 'POST',
body: body,
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, this.baseOptions.headers, {
'Accept': 'application/json',
'Content-Type': 'application/json',
'x-request-id': _params.xRequestId,
'x-correlation-id': _params.xCorrelationId,
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
GlobalSearchV2.DEFAULT_SERVICE_URL = 'https://api.global-search-tagging.cloud.ibm.com';
GlobalSearchV2.DEFAULT_SERVICE_NAME = 'global_search';
return GlobalSearchV2;
}(ibm_cloud_sdk_core_1.BaseService));
/*************************
* interfaces
************************/
(function (GlobalSearchV2) {
/** Constants for the `search` operation. */
var SearchConstants;
(function (SearchConstants) {
/** Determines if deleted documents should be included in result set or not. Possible values are false (default), true or any. If false, only existing documents are returned; if true, only deleted documents are returned; If any, both existing and deleted documents are returned. (_for administrators only_). */
var IsDeleted;
(function (IsDeleted) {
IsDeleted["TRUE"] = "true";
IsDeleted["FALSE"] = "false";
IsDeleted["ANY"] = "any";
})(IsDeleted = SearchConstants.IsDeleted || (SearchConstants.IsDeleted = {}));
/** Determines if reclaimed documents should be included in result set or not. Possible values are false (default), true or any. If false, only not reclaimed documents are returned; if true, only reclaimed documents are returned; If any, both reclaimed and not reclaimed documents are returned. */
var IsReclaimed;
(function (IsReclaimed) {
IsReclaimed["TRUE"] = "true";
IsReclaimed["FALSE"] = "false";
IsReclaimed["ANY"] = "any";
})(IsReclaimed = SearchConstants.IsReclaimed || (SearchConstants.IsReclaimed = {}));
/** Determines if the result set must return the resources that the user can tag or the resources that the user can view (only a GhoST admin can use this parameter). If false (default), only resources user can view are returned; if true, only resources that user has permissions for tagging are returned (_for administrators only_). */
var CanTag;
(function (CanTag) {
CanTag["TRUE"] = "true";
CanTag["FALSE"] = "false";
})(CanTag = SearchConstants.CanTag || (SearchConstants.CanTag = {}));
/** Determines if documents belonging to Project family should be included in result set or not. Possible values are false (default), true or any. If false, documents belonging to all families except Project are returned; if true, only documents belonging to Project family are returned; if any, documents of any family are returned. Only authorized ServiceIds can use this query parameter. */
var IsProjectResource;
(function (IsProjectResource) {
IsProjectResource["TRUE"] = "true";
IsProjectResource["FALSE"] = "false";
IsProjectResource["ANY"] = "any";
})(IsProjectResource = SearchConstants.IsProjectResource || (SearchConstants.IsProjectResource = {}));
})(SearchConstants = GlobalSearchV2.SearchConstants || (GlobalSearchV2.SearchConstants = {}));
})(GlobalSearchV2 || (GlobalSearchV2 = {}));
module.exports = GlobalSearchV2;
//# sourceMappingURL=v2.js.map
;