n8n-nodes-tenable-community
Version:
n8n node for the Tenable One platform
104 lines (103 loc) • 5.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TenablePCIClient = void 0;
/**
* @file Client for interacting with the Tenable PCI ASV API.
* Handles authentication and provides methods for all PCI ASV-related operations.
*/
const n8n_workflow_1 = require("n8n-workflow");
/**
* @class TenablePCIClient
* @description Implements the client for the Tenable PCI ASV (Payment Card Industry Approved Scanning Vendor) API.
*/
class TenablePCIClient {
/**
* Creates an instance of the TenablePCIClient.
* @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 PCI scans.
* @param {object} [options] Optional parameters.
* @param {IDataObject} [options.qs] Optional query parameters for filtering and pagination.
* @returns {Promise<ITenableScan[]>} A promise that resolves to the list of PCI scans.
*/
async listScans(options = {}) {
const response = await this.sendRequest({ method: 'GET', url: 'pci-asv/scans/list', qs: options.qs });
return response;
}
/**
* Creates a new PCI scan.
* @param {object} options The options for the request.
* @param {IDataObject} options.body The scan definition.
* @returns {Promise<ITenableScan>} A promise that resolves to the newly created scan details.
*/
async createScan(options) {
const response = await this.sendRequest({ method: 'POST', url: 'pci-asv/scans', body: options.body });
return response;
}
/**
* Launches a PCI scan.
* @param {object} params The parameters for the request.
* @param {string} params.scanId The ID of the scan to launch.
* @returns {Promise<ITenableScan>} A promise that resolves to the launch confirmation details.
*/
async launchScan(params) {
const response = await this.sendRequest({ method: 'POST', url: `pci-asv/scans/${params.scanId}/launch` });
return response;
}
/**
* Retrieves a list of attestations.
* @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 attestations.
*/
async listAttestations(options = {}) {
return this.sendRequest({ method: 'GET', url: 'pci-asv/attestations/list', qs: options.qs });
}
/**
* Retrieves the details of a specific attestation.
* @param {object} params The parameters for the request.
* @param {string} params.attestationId The ID of the attestation.
* @returns {Promise<unknown>} A promise that resolves to the attestation details.
*/
async getAttestationDetails(params) {
return this.sendRequest({ method: 'GET', url: `pci-asv/attestations/details/${params.attestationId}` });
}
/**
* Retrieves a list of disputes for a given attestation.
* @param {object} params The parameters for the request.
* @param {string} params.attestationId The ID of the attestation.
* @param {IDataObject} [params.qs] Optional query parameters for filtering and pagination.
* @returns {Promise<unknown>} A promise that resolves to the list of disputes.
*/
async listAttestationDisputes(params) {
return this.sendRequest({ method: 'GET', url: `pci-asv/attestations/details/${params.attestationId}/disputes`, qs: params.qs });
}
}
exports.TenablePCIClient = TenablePCIClient;