UNPKG

n8n-nodes-tenable-community

Version:

n8n node for the Tenable One platform

84 lines (83 loc) 4.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TenableIEClient = void 0; /** * @file Client for interacting with the Tenable Identity Exposure (IE) API. * Handles authentication and provides methods for all IE-related operations. */ const n8n_workflow_1 = require("n8n-workflow"); /** * @class TenableIEClient * @description Implements the client for the Tenable Identity Exposure (IE) API. */ class TenableIEClient { /** * Creates an instance of the TenableIEClient. * @param {ITriggerFunctions | IExecuteFunctions} context The n8n context object for credentials and helpers. */ constructor(context) { this.context = context; } /** * A private helper method to send authenticated requests to the Tenable API. * @private * @param {IHttpRequestOptions} options - The request options. * @returns {Promise<unknown>} A promise that resolves to the API response. * @throws {NodeApiError} Wraps API errors in a standard n8n error. */ async sendRequest(options) { var _a, _b, _c; const credentials = await this.context.getCredentials('tenableOneApi'); const requestOptions = Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { 'X-ApiKeys': `accessKey=${credentials.accessKey};secretKey=${credentials.secretKey}` }), json: true, url: `https://cloud.tenable.com/${options.url}`, timeout: 60000 }); try { return await this.context.helpers.httpRequest(requestOptions); } catch (error) { if (error instanceof n8n_workflow_1.NodeApiError) { const errorDetails = error.cause ? (_a = error.cause.response) === null || _a === void 0 ? void 0 : _a.body : { message: error.message }; const errorMessage = ((_c = (_b = errorDetails === null || errorDetails === void 0 ? void 0 : errorDetails.errors) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.message) || (errorDetails === null || errorDetails === void 0 ? void 0 : errorDetails.message) || 'No additional error details provided.'; throw new n8n_workflow_1.NodeApiError(this.context.getNode(), { message: `Tenable API Error: ${errorMessage}` }); } throw new n8n_workflow_1.NodeApiError(this.context.getNode(), { message: error.message }); } } /** * Retrieves a list of indicators of exposure for a given profile. * @param {object} params The parameters for the request. * @param {string} params.profileId The ID of the profile. * @param {IDataObject} [params.qs] Optional query parameters for filtering and pagination. * @returns {Promise<ITenableFinding[]>} A promise that resolves to the list of indicators of exposure. */ async listIndicatorsOfExposure(params) { const response = await this.sendRequest({ method: 'GET', url: `api/profiles/${params.profileId}/deviances`, qs: params.qs }); return response; } /** * Retrieves the details of a specific profile. * @param {object} params The parameters for the request. * @param {string} params.profileId The ID of the profile. * @returns {Promise<unknown>} A promise that resolves to the profile details. */ async getProfileDetails(params) { return this.sendRequest({ method: 'GET', url: `api/profiles/${params.profileId}` }); } /** * Queries the topology of a given profile. * @param {object} params The parameters for the request. * @param {string} params.profileId The ID of the profile. * @returns {Promise<unknown>} A promise that resolves to the topology data. */ async queryTopology(params) { return this.sendRequest({ method: 'GET', url: `api/profiles/${params.profileId}/topology` }); } /** * Retrieves a list of directories (domains). * @param {object} [options] Optional parameters. * @param {IDataObject} [options.qs] Optional query parameters for filtering and pagination. * @returns {Promise<unknown>} A promise that resolves to the list of domains. */ async listDomains(options = {}) { return this.sendRequest({ method: 'GET', url: 'api/directories', qs: options.qs }); } } exports.TenableIEClient = TenableIEClient;