n8n-nodes-tenable-community
Version:
n8n node for the Tenable One platform
84 lines (83 loc) • 4.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TenableAPAClient = void 0;
/**
* @file Client for interacting with the Tenable Attack Path Analysis (APA) API.
* Handles authentication and provides methods for all APA-related operations.
*/
const n8n_workflow_1 = require("n8n-workflow");
/**
* @class TenableAPAClient
* @description Implements the client for the Tenable Attack Path Analysis (APA) API.
*/
class TenableAPAClient {
/**
* Creates an instance of the TenableAPAClient.
* @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 attack paths.
* @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 attack paths.
*/
async listAttackPaths(options = {}) {
return this.sendRequest({ method: 'GET', url: 'apa/api/discover/v1/vectors', qs: options.qs });
}
/**
* Retrieves the details of a specific attack path.
* @param {object} params The parameters for the request.
* @param {string} params.pathId The ID of the attack path.
* @returns {Promise<unknown>} A promise that resolves to the attack path details.
*/
async getPathDetails(params) {
return this.sendRequest({ method: 'GET', url: `apa/api/discover/v1/vectors/${params.pathId}` });
}
/**
* Retrieves a list of critical assets.
* @param {object} [options] Optional parameters.
* @param {IDataObject} [options.qs] Optional query parameters for filtering and pagination.
* @returns {Promise<ITenableAsset[]>} A promise that resolves to the list of critical assets.
*/
async listCriticalAssets(options = {}) {
const response = await this.sendRequest({ method: 'GET', url: 'apa/api/discover/v1/critical-assets', qs: options.qs });
return response;
}
/**
* Retrieves a list of findings.
* @param {object} [options] Optional parameters.
* @param {IDataObject} [options.qs] Optional query parameters for filtering and pagination.
* @returns {Promise<ITenableFinding[]>} A promise that resolves to the list of findings.
*/
async listFindings(options = {}) {
const response = await this.sendRequest({ method: 'GET', url: 'apa/findings-api/v1/findings', qs: options.qs });
return response;
}
}
exports.TenableAPAClient = TenableAPAClient;