n8n-nodes-tenable-community
Version:
n8n node for the Tenable One platform
72 lines (71 loc) • 2.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.msspApiRequest = msspApiRequest;
async function msspApiRequest(resource, operation, body = {}, qs = {}) {
const credentials = await this.getCredentials('tenableApi');
const baseUrl = 'https://cloud.tenable.com';
let endpoint = '';
let method = 'GET';
if (resource === 'accounts') {
if (operation === 'createEvalV1') {
method = 'POST';
endpoint = '/mssp/accounts/eval';
}
else if (operation === 'createEvalV2') {
method = 'POST';
endpoint = '/mssp/accounts/v2/eval';
}
else if (operation === 'createQuote') {
method = 'POST';
endpoint = '/mssp/accounts/quote';
}
else if (operation === 'list') {
endpoint = '/mssp/accounts';
}
else if (operation === 'get') {
endpoint = `/mssp/accounts/${qs.account_uuid}`;
}
else if (operation === 'listDomains') {
endpoint = `/mssp/accounts/${qs.account_uuid}/domains`;
}
}
else if (resource === 'accountGroups') {
if (operation === 'create') {
method = 'POST';
endpoint = '/mssp/accountGroup';
}
else if (operation === 'list') {
endpoint = '/mssp/accountGroup';
}
else if (operation === 'get') {
endpoint = `/mssp/accountGroup/${qs.account_group_uuid}`;
}
else if (operation === 'update') {
method = 'PUT';
endpoint = `/mssp/accountGroup/${qs.account_group_uuid}`;
}
else if (operation === 'delete') {
method = 'DELETE';
endpoint = `/mssp/accountGroup/${qs.account_group_uuid}`;
}
}
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);
}