Add full continue-on-fail support to all nodes (#1996)

* Update Compression node

* Update Crypto node

* Update DateTime node

* Update EditImage node

* Update EmailSend node

* Update ExecuteWorkflow node

* Update FTP node

* Update Function node

* Update FunctionItem node

* Update ExecuteCommand node

* Update OpenWeatherMap node

* Update ReadBinaryFile node

* Update ReadPdf node

* Update RssFeedRead node & add URL validation

* Update SpreadsheetFile node

* Update Switch node

* Update WriteBinaryFile node

* Update Xml node

* Update ActiveCampaign node

* Update Airtable node

* Update ApiTemplateIo node

* Update Asana node

* Update AwsLambda node

* Update AwsSns node

* Update AwsComprehend node

* Update AwsRekognition node

* Update AwsS3 node

* Fix Error item

* Update AwsSes node

* Update AwsSqs node

* Update Amqp node

* Update Bitly node

* Update Box node

* Update Brandfetch node

* Update CircleCi node

* Update Clearbit node

* Update ClickUp node

* Update Cockpit node

* Update CoinGecko node

* Update Contentful node

* Update ConvertKit node

* Update Cortex node

* Update CustomerIo node

* Update DeepL node

* Update Demio node

* Update Disqus node

* Update Drift node

* Update Dropbox node

* Update GetResponse node

* Refactor & Update Ghost node

* Update Github node

* Update Gitlab node

* Update GoogleAnalytics node

* Update GoogleBooks node

* Update GoogleCalendar node

* Update GoogleDrive node

* Update Gmail node

* Update GoogleSheets node

* Update GoogleSlides node

* Update GoogleTasks node

* Update Gotify node

* Update GraphQL node

* Update HackerNews node

* Update Harvest node

* Update HtmlExtract node

* Update Hubspot node

* Update Hunter node

* Update Intercom node

* Update Kafka node

* Refactor & update Line node

* Update LinkedIn node

* Update Mailchimp node

* Update Mandrill node

* Update Matrix node

* Update Mautic node

* Update Medium node

* Update MessageBird node

* Update Mindee node

* Update Mocean node

* Update MondayCom node

* Update MicrosoftExcel node

* Update MicrosoftOneDrive node

* Update MicrosoftOutlook node

* Update Affinity node

* Update Chargebee node

* Update Discourse node

* Update Freshdesk node

* Update YouTube node

* Update InvoiceNinja node

* Update MailerLite node

* Update Mailgun node

* Update Mailjet node

* Update Mattermost node

* Update Nasa node

* Update NextCloud node

* Update OpenThesaurus node

* Update Orbit node

* Update PagerDuty node

* Update PayPal node

* Update Peekalink node

* Update Phantombuster node

* Update PostHog node

* Update ProfitWell node

* Refactor & Update Pushbullet node

* Update QuickBooks node

* Update Raindrop node

* Update Reddit node

* Update Rocketchat node

* Update S3 node

* Update Salesforce node

* Update SendGrid node

* Update SentryIo node

* Update Shopify node

* Update Signl4 node

* Update Slack node

* Update Spontit node

* Update Spotify node

* Update Storyblok node

* Refactor & Update Strapi node

* Refactor & Update Strava node

* Update Taiga node

* Refactor & update Tapfiliate node

* Update Telegram node

* Update TheHive node

* Update Todoist node

* Update TravisCi node

* Update Trello node

* Update Twilio node

* Update Twist node

* Update Twitter node

* Update Uplead node

* Update UProc node

* Update Vero node

* Update Webflow node

* Update Wekan node

* Update Wordpress node

* Update Xero node

* Update Yourls node

* Update Zendesk node

* Update ZohoCrm node

* Refactor & Update Zoom node

* Update Zulip node

* Update Clockify node

* Update MongoDb node

* Update MySql node

* Update MicrosoftTeams node

* Update Stackby node

* Refactor Discourse node

* Support corner-case in Github node update

* Support corner-case in Gitlab node update

* Refactor & Update GoogleContacts node

* Refactor Mindee node

* Update Coda node

* Lint fixes

* Update Beeminder node

* Update Google Firebase RealtimeDatabase node

* Update HelpScout node

* Update Mailcheck node

* Update Paddle node

* Update Pipedrive node

* Update Pushover node

* Update Segment node

* Refactor & Update Vonage node

* Added new conditions to warnings on execute batch cmd

* Added keep only properties flag

* Fixed code for keep only props

* Added dependencies for image editing

Co-authored-by: dali <servfrdali@yahoo.fr>
This commit is contained in:
Omar Ajoue
2021-07-20 08:58:54 +02:00
committed by GitHub
parent 6a9401aa51
commit d6239d5bfb
159 changed files with 35795 additions and 33847 deletions

View File

@@ -204,264 +204,274 @@ export class Cortex implements INodeType {
const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < length; i++) {
if (resource === 'analyzer') {
//https://github.com/TheHive-Project/CortexDocs/blob/master/api/api-guide.md#run
if (operation === 'execute') {
try {
let force = false;
if (resource === 'analyzer') {
//https://github.com/TheHive-Project/CortexDocs/blob/master/api/api-guide.md#run
if (operation === 'execute') {
const analyzer = this.getNodeParameter('analyzer', i) as string;
let force = false;
const observableType = this.getNodeParameter('observableType', i) as string;
const analyzer = this.getNodeParameter('analyzer', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const observableType = this.getNodeParameter('observableType', i) as string;
const tlp = this.getNodeParameter('tlp', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const body: IDataObject = {
dataType: observableType,
tlp,
};
const tlp = this.getNodeParameter('tlp', i) as string;
if (additionalFields.force === true) {
force = true;
}
if (observableType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string;
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
}
const fileBufferData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING);
const options = {
formData: {
data: {
value: fileBufferData,
options: {
contentType: item.binary[binaryPropertyName].mimeType,
filename: item.binary[binaryPropertyName].fileName,
},
},
_json: JSON.stringify({
dataType: observableType,
tlp,
}),
},
const body: IDataObject = {
dataType: observableType,
tlp,
};
responseData = await cortexApiRequest.call(
this,
'POST',
`/analyzer/${analyzer.split('::')[0]}/run`,
{},
{ force },
'',
options,
) as IJob;
if (additionalFields.force === true) {
force = true;
}
continue;
if (observableType === 'file') {
} else {
const observableValue = this.getNodeParameter('observableValue', i) as string;
const item = items[i];
body.data = observableValue;
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
responseData = await cortexApiRequest.call(
this,
'POST',
`/analyzer/${analyzer.split('::')[0]}/run`,
body,
{ force },
) as IJob;
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i) as string;
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
}
const fileBufferData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING);
const options = {
formData: {
data: {
value: fileBufferData,
options: {
contentType: item.binary[binaryPropertyName].mimeType,
filename: item.binary[binaryPropertyName].fileName,
},
},
_json: JSON.stringify({
dataType: observableType,
tlp,
}),
},
};
responseData = await cortexApiRequest.call(
this,
'POST',
`/analyzer/${analyzer.split('::')[0]}/run`,
{},
{ force },
'',
options,
) as IJob;
continue;
} else {
const observableValue = this.getNodeParameter('observableValue', i) as string;
body.data = observableValue;
responseData = await cortexApiRequest.call(
this,
'POST',
`/analyzer/${analyzer.split('::')[0]}/run`,
body,
{ force },
) as IJob;
}
if (additionalFields.timeout) {
responseData = await cortexApiRequest.call(
this,
'GET',
`/job/${responseData.id}/waitreport`,
{},
{ atMost: `${additionalFields.timeout}second` },
);
}
}
}
if (resource === 'job') {
//https://github.com/TheHive-Project/CortexDocs/blob/master/api/api-guide.md#get-details-1
if (operation === 'get') {
const jobId = this.getNodeParameter('jobId', i) as string;
if (additionalFields.timeout) {
responseData = await cortexApiRequest.call(
this,
'GET',
`/job/${responseData.id}/waitreport`,
{},
{ atMost: `${additionalFields.timeout}second` },
`/job/${jobId}`,
);
}
//https://github.com/TheHive-Project/CortexDocs/blob/master/api/api-guide.md#get-details-and-report
if (operation === 'report') {
const jobId = this.getNodeParameter('jobId', i) as string;
responseData = await cortexApiRequest.call(
this,
'GET',
`/job/${jobId}/report`,
);
}
}
}
if (resource === 'job') {
//https://github.com/TheHive-Project/CortexDocs/blob/master/api/api-guide.md#get-details-1
if (operation === 'get') {
if (resource === 'responder') {
if (operation === 'execute') {
const responderId = (this.getNodeParameter('responder', i) as string).split('::')[0];
const jobId = this.getNodeParameter('jobId', i) as string;
const entityType = this.getNodeParameter('entityType', i) as string;
responseData = await cortexApiRequest.call(
this,
'GET',
`/job/${jobId}`,
);
}
//https://github.com/TheHive-Project/CortexDocs/blob/master/api/api-guide.md#get-details-and-report
if (operation === 'report') {
const jobId = this.getNodeParameter('jobId', i) as string;
responseData = await cortexApiRequest.call(
this,
'GET',
`/job/${jobId}/report`,
);
}
}
if (resource === 'responder') {
if (operation === 'execute') {
const responderId = (this.getNodeParameter('responder', i) as string).split('::')[0];
const entityType = this.getNodeParameter('entityType', i) as string;
const isJSON = this.getNodeParameter('jsonObject', i) as boolean;
let body: IDataObject;
const isJSON = this.getNodeParameter('jsonObject', i) as boolean;
let body: IDataObject;
if (isJSON) {
const entityJson = JSON.parse(this.getNodeParameter('objectData', i) as string);
if (isJSON) {
const entityJson = JSON.parse(this.getNodeParameter('objectData', i) as string);
body = {
responderId,
label: getEntityLabel(entityJson),
dataType: `thehive:${entityType}`,
data: entityJson,
tlp: entityJson.tlp || 2,
pap: entityJson.pap || 2,
message: entityJson.message || '',
parameters: [],
};
body = {
responderId,
label: getEntityLabel(entityJson),
dataType: `thehive:${entityType}`,
data: entityJson,
tlp: entityJson.tlp || 2,
pap: entityJson.pap || 2,
message: entityJson.message || '',
parameters: [],
};
} else {
} else {
const values = (this.getNodeParameter('parameters', i) as IDataObject).values as IDataObject;
const values = (this.getNodeParameter('parameters', i) as IDataObject).values as IDataObject;
body = {
responderId,
dataType: `thehive:${entityType}`,
data: {
_type: entityType,
...prepareParameters(values),
},
};
if (entityType === 'alert') {
// deal with alert artifacts
const artifacts = (body.data as IDataObject).artifacts as IDataObject;
body = {
responderId,
dataType: `thehive:${entityType}`,
data: {
_type: entityType,
...prepareParameters(values),
},
};
if (entityType === 'alert') {
// deal with alert artifacts
const artifacts = (body.data as IDataObject).artifacts as IDataObject;
if (artifacts) {
if (artifacts) {
const artifactValues = (artifacts as IDataObject).artifactValues as IDataObject[];
const artifactValues = (artifacts as IDataObject).artifactValues as IDataObject[];
if (artifactValues) {
if (artifactValues) {
const artifactData = [];
const artifactData = [];
for (const artifactvalue of artifactValues) {
for (const artifactvalue of artifactValues) {
const element: IDataObject = {};
const element: IDataObject = {};
element.message = artifactvalue.message as string;
element.message = artifactvalue.message as string;
element.tags = splitTags(artifactvalue.tags as string) as string[];
element.tags = splitTags(artifactvalue.tags as string) as string[];
element.dataType = artifactvalue.dataType as string;
element.dataType = artifactvalue.dataType as string;
element.data = artifactvalue.data as string;
element.data = artifactvalue.data as string;
if (artifactvalue.dataType === 'file') {
if (artifactvalue.dataType === 'file') {
const item = items[i];
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
const binaryPropertyName = artifactvalue.binaryProperty as string;
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property '${binaryPropertyName}' does not exists on item!`);
}
const binaryData = item.binary[binaryPropertyName] as IBinaryData;
element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`;
}
const binaryPropertyName = artifactvalue.binaryProperty as string;
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property '${binaryPropertyName}' does not exists on item!`);
}
const binaryData = item.binary[binaryPropertyName] as IBinaryData;
element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`;
artifactData.push(element);
}
artifactData.push(element);
(body.data as IDataObject).artifacts = artifactData;
}
}
}
if (entityType === 'case_artifact') {
// deal with file observable
if ((body.data as IDataObject).dataType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
(body.data as IDataObject).artifacts = artifactData;
const binaryPropertyName = (body.data as IDataObject).binaryPropertyName as string;
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
}
const fileBufferData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING);
const sha256 = createHash('sha256').update(fileBufferData).digest('hex');
(body.data as IDataObject).attachment = {
name: item.binary[binaryPropertyName].fileName,
hashes: [
sha256,
createHash('sha1').update(fileBufferData).digest('hex'),
createHash('md5').update(fileBufferData).digest('hex'),
],
size: fileBufferData.byteLength,
contentType: item.binary[binaryPropertyName].mimeType,
id: sha256,
};
delete (body.data as IDataObject).binaryPropertyName;
}
}
// add the job label after getting all entity attributes
body = {
label: getEntityLabel(body.data as IDataObject),
...body,
};
}
if (entityType === 'case_artifact') {
// deal with file observable
if ((body.data as IDataObject).dataType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
}
const binaryPropertyName = (body.data as IDataObject).binaryPropertyName as string;
if (item.binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`);
}
const fileBufferData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING);
const sha256 = createHash('sha256').update(fileBufferData).digest('hex');
(body.data as IDataObject).attachment = {
name: item.binary[binaryPropertyName].fileName,
hashes: [
sha256,
createHash('sha1').update(fileBufferData).digest('hex'),
createHash('md5').update(fileBufferData).digest('hex'),
],
size: fileBufferData.byteLength,
contentType: item.binary[binaryPropertyName].mimeType,
id: sha256,
};
delete (body.data as IDataObject).binaryPropertyName;
}
}
// add the job label after getting all entity attributes
body = {
label: getEntityLabel(body.data as IDataObject),
...body,
};
responseData = await cortexApiRequest.call(
this,
'POST',
`/responder/${responderId}/run`,
body,
) as IJob;
}
responseData = await cortexApiRequest.call(
this,
'POST',
`/responder/${responderId}/run`,
body,
) as IJob;
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });
continue;
}
throw error;
}
}
return [this.helpers.returnJsonArray(returnData)];