UNPKG

n8n-nodes-tenable-community

Version:

n8n node for the Tenable One platform

57 lines (56 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.attackSurfaceManagementApiRequest = attackSurfaceManagementApiRequest; async function attackSurfaceManagementApiRequest(resource, operation, body = {}, qs = {}) { const credentials = await this.getCredentials('tenableApi'); const baseUrl = credentials.baseUrl || 'https://asm.cloud.tenable.com/v1'; let endpoint = ''; let method = 'GET'; if (resource === 'assets') { if (operation === 'list') { method = 'POST'; endpoint = '/assets'; } else if (operation === 'get') { method = 'GET'; endpoint = `/asset/${qs.id}`; } else if (operation === 'history') { method = 'GET'; endpoint = `/asset/${qs.id}/history`; } else if (operation === 'archive' || operation === 'unarchive') { method = 'POST'; endpoint = '/asset/hide'; body.hidden = operation === 'archive'; } } else if (resource === 'export') { method = 'POST'; if (operation === 'download') { endpoint = '/export/download'; } else { endpoint = `/assets/export/${operation.replace('assets', '').toLowerCase()}`; } } const options = { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'X-ApiKeys': `accessKey=${credentials.accessKey};secretKey=${credentials.secretKey}`, }, method, qs, body, url: `${baseUrl}${endpoint}`, json: true, }; if (Object.keys(body).length === 0) { delete options.body; } if (Object.keys(qs).length === 0) { delete options.qs; } return this.helpers.httpRequest(options); }