UNPKG

n8n-nodes-tenable-community

Version:

n8n node for the Tenable One platform

62 lines (61 loc) 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TenablePlatformClient = void 0; /** * @file Client for interacting with the core Tenable Platform API. * This client manages platform-level resources like users, groups, permissions, * scanners, and tags that are shared across multiple Tenable products. */ const n8n_workflow_1 = require("n8n-workflow"); /** * @class TenablePlatformClient * @description Implements the client for the Tenable Platform API. */ class TenablePlatformClient { /** * Creates an instance of the TenablePlatformClient. * @param {IExecuteFunctions} executeFunctions The n8n execute functions object. */ constructor(executeFunctions) { this.executeFunctions = executeFunctions; } /** * 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} If the API call fails. */ async sendRequest(options) { var _a, _b, _c; const credentials = await this.executeFunctions.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.executeFunctions.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.executeFunctions.getNode(), { message: `Tenable API Error: ${errorMessage}` }); } throw new n8n_workflow_1.NodeApiError(this.executeFunctions.getNode(), { message: error.message }); } } // ================================================================= // ACCESS CONTROL - IP ALLOW LIST // ================================================================= /** * Retrieves the list of allowed IP addresses. * @returns {Promise<unknown>} The list of IP rules. */ async listAllowedIpAddresses() { return this.sendRequest({ method: 'GET', url: 'access-control/ip-allow-list' }); } /** * Updates the list of allowed IP addresses. * @param {object} options The request options. * @param {object} options.body The new list of IP rules. * @returns {Promise<unknown>} The result of the update operation. */ async updateAllowedIpAddresses(options) { return this.sendRequest({ method: 'PUT', url: 'access-control/ip-allow-list', body: options.body }); } } exports.TenablePlatformClient = TenablePlatformClient;