n8n-nodes-tenable-community
Version:
n8n node for the Tenable One platform
47 lines (46 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tenableOneApiRequest = tenableOneApiRequest;
async function tenableOneApiRequest(resource, operation, body = {}, qs = {}) {
const credentials = await this.getCredentials('tenableApi');
const baseUrl = 'https://cloud.tenable.com';
let endpoint = '';
let method = 'GET';
if (resource === 'exposureView') {
if (operation === 'searchCards') {
endpoint = '/api/v1/t1/exposure-view/cards';
}
else if (operation === 'getCardDetails') {
endpoint = `/api/v1/t1/exposure-view/cards/${qs.card_id}`;
}
}
else if (resource === 'inventory') {
if (operation === 'searchAssets') {
method = 'POST';
endpoint = '/api/v1/t1/inventory/assets/search';
}
else if (operation === 'searchSoftware') {
method = 'POST';
endpoint = '/api/v1/t1/inventory/software/search';
}
}
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);
}