mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add TheHive & Cortex nodes (#952)
* ✨ TheHive & Cortex nodes * 🔨 Make changes mentioned in #887 * ⚡ Improvements * ⚡ Improvements * ⚡ Improvements * ⚡ Add descriptions * ⚡ Improvements * ⚡ Improvements Co-authored-by: MedAliMarz <servfrdali@yahoo.fr>
This commit is contained in:
109
packages/nodes-base/nodes/Cortex/GenericFunctions.ts
Normal file
109
packages/nodes-base/nodes/Cortex/GenericFunctions.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IAnalyzer,
|
||||
IJob,
|
||||
IResponder,
|
||||
} from './AnalyzerInterface';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import * as moment from 'moment';
|
||||
|
||||
export async function cortexApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const credentials = this.getCredentials('cortexApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
const headerWithAuthentication = Object.assign({}, { Authorization: ` Bearer ${credentials.cortexApiKey}`});
|
||||
|
||||
let options: OptionsWithUri = {
|
||||
headers: headerWithAuthentication,
|
||||
method,
|
||||
qs: query,
|
||||
uri: uri || `${credentials.host}/api${resource}`,
|
||||
body,
|
||||
json: true,
|
||||
|
||||
};
|
||||
if (Object.keys(option).length !== 0) {
|
||||
options = Object.assign({},options, option);
|
||||
}
|
||||
if (Object.keys(body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
if (Object.keys(query).length === 0) {
|
||||
delete options.qs;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
if (error.error ) {
|
||||
const errorMessage = `Cortex error response [${error.statusCode}]: ${error.error.message}`;
|
||||
throw new Error(errorMessage);
|
||||
} else throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function getEntityLabel(entity: IDataObject): string{
|
||||
let label = '';
|
||||
switch (entity._type) {
|
||||
case 'case':
|
||||
label = `#${entity.caseId} ${entity.title}`;
|
||||
break;
|
||||
case 'case_artifact':
|
||||
//@ts-ignore
|
||||
label = `[${entity.dataType}] ${entity.data?entity.data:(entity.attachment.name)}`;
|
||||
break;
|
||||
case 'alert':
|
||||
label = `[${entity.source}:${entity.sourceRef}] ${entity.title}`;
|
||||
break;
|
||||
case 'case_task_log':
|
||||
label = `${entity.message} from ${entity.createdBy}`;
|
||||
break;
|
||||
case 'case_task':
|
||||
label = `${entity.title} (${entity.status})`;
|
||||
break;
|
||||
case 'job':
|
||||
label = `${entity.analyzerName} (${entity.status})`;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return label;
|
||||
}
|
||||
|
||||
export function splitTags(tags: string): string[] {
|
||||
return tags.split(',').filter(tag => tag !== ' ' && tag);
|
||||
}
|
||||
|
||||
export function prepareParameters(values: IDataObject): IDataObject {
|
||||
const response: IDataObject = {};
|
||||
for (const key in values) {
|
||||
if (values[key]!== undefined && values[key]!==null && values[key]!=='') {
|
||||
if (moment(values[key] as string, moment.ISO_8601).isValid()) {
|
||||
response[key] = Date.parse(values[key] as string);
|
||||
} else if (key === 'tags') {
|
||||
response[key] = splitTags(values[key] as string);
|
||||
} else {
|
||||
response[key] = values[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
Reference in New Issue
Block a user