Fix lint issues, formatting and icons

This commit is contained in:
Jan Oberhauser
2020-12-02 11:54:10 +01:00
parent ea9f61089b
commit a38665e82c
24 changed files with 870 additions and 893 deletions

View File

@@ -4,7 +4,7 @@ import {
import {
TLP,
}from './AnalyzerInterface';
} from './AnalyzerInterface';
export const analyzersOperations = [
{
@@ -31,7 +31,7 @@ export const analyzersOperations = [
},
] as INodeProperties[];
export const analyzerFields: INodeProperties[] =[
export const analyzerFields: INodeProperties[] = [
{
displayName: 'Analyzer Type',
name: 'analyzer',
@@ -40,12 +40,12 @@ export const analyzerFields: INodeProperties[] =[
typeOptions: {
loadOptionsMethod: 'loadActiveAnalyzers',
},
displayOptions:{
displayOptions: {
show: {
resource: [
'analyzer',
],
operation:[
operation: [
'execute',
],
},
@@ -58,22 +58,22 @@ export const analyzerFields: INodeProperties[] =[
name: 'observableType',
type: 'options',
required: true,
displayOptions:{
displayOptions: {
show: {
resource: [
'analyzer',
],
operation:[
operation: [
'execute',
],
},
hide:{
analyzer:[
hide: {
analyzer: [
'',
],
},
},
typeOptions:{
typeOptions: {
loadOptionsMethod: 'loadObservableOptions',
loadOptionsDependsOn: [
'analyzer',
@@ -94,15 +94,15 @@ export const analyzerFields: INodeProperties[] =[
resource: [
'analyzer',
],
operation:[
operation: [
'execute',
],
},
hide:{
hide: {
observableType: [
'file',
],
analyzer:[
analyzer: [
'',
],
},
@@ -136,7 +136,7 @@ export const analyzerFields: INodeProperties[] =[
name: 'tlp',
type: 'options',
required: false,
displayOptions:{
displayOptions: {
show: {
resource: [
'analyzer',
@@ -145,7 +145,7 @@ export const analyzerFields: INodeProperties[] =[
'execute',
],
},
hide:{
hide: {
observableType: [
'',
],
@@ -166,10 +166,10 @@ export const analyzerFields: INodeProperties[] =[
{
name: 'Amber',
value: TLP.amber,
},{
}, {
name: 'Red',
value: TLP.red,
}
},
],
default: 2,
description: 'The TLP of the analyzed observable',

View File

@@ -1,39 +1,39 @@
import {
IDataObject,
}from 'n8n-workflow';
IDataObject,
} from 'n8n-workflow';
export enum JobStatus {
WAITING = 'Waiting',
INPROGRESS = 'InProgress',
SUCCESS = 'Success',
FAILURE = 'Failure',
DELETED = 'Deleted'
DELETED = 'Deleted',
}
export enum TLP {
white,
green,
amber,
red
white,
green,
amber,
red,
}
export enum ObservableDataType {
'domain'= 'domain',
'file'= 'file',
'filename'= 'filename',
'fqdn'= 'fqdn',
'hash'= 'hash',
'ip'= 'ip',
'mail'= 'mail',
'mail_subject'= 'mail_subject',
'other'= 'other',
'regexp'= 'regexp',
'registry'= 'registry',
'uri_path'= 'uri_path',
'url'= 'url',
'user-agent'= 'user-agent'
'domain' = 'domain',
'file' = 'file',
'filename' = 'filename',
'fqdn' = 'fqdn',
'hash' = 'hash',
'ip' = 'ip',
'mail' = 'mail',
'mail_subject' = 'mail_subject',
'other' = 'other',
'regexp' = 'regexp',
'registry' = 'registry',
'uri_path' = 'uri_path',
'url' = 'url',
'user-agent' = 'user-agent',
}
export interface IJob{
export interface IJob {
id?: string;
organization?: string;
analyzerDefinitionId?: string;
@@ -44,7 +44,7 @@ export interface IJob{
data?: string;
attachment?: IDataObject;
parameters?: IDataObject;
message? :string;
message?: string;
tlp?: TLP;
startDate?: Date;
endDate?: Date;
@@ -54,10 +54,10 @@ export interface IJob{
updatedBy?: Date;
report?: IDataObject | string;
}
export interface IAnalyzer{
export interface IAnalyzer {
id?: string;
analyzerDefinitionId?: string;
name? :string;
name?: string;
version?: string;
description?: string;
author?: string;
@@ -74,7 +74,7 @@ export interface IAnalyzer{
updatedBy?: Date;
}
export interface IResponder{
export interface IResponder {
id?: string;
name?: string;
version?: string;

View File

@@ -1,6 +1,6 @@
import {
IExecuteFunctions,
BINARY_ENCODING,
IExecuteFunctions,
} from 'n8n-core';
import {
@@ -11,23 +11,23 @@ import {
} from './GenericFunctions';
import {
analyzersOperations,
analyzerFields,
analyzersOperations,
} from './AnalyzerDescriptions';
import {
IBinaryData,
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
INodePropertyOptions,
ILoadOptionsFunctions,
IDataObject,
IBinaryData,
} from 'n8n-workflow';
import {
respondersOperations,
responderFields,
respondersOperations,
} from './ResponderDescription';
import {
@@ -43,7 +43,7 @@ import {
IJob,
} from './AnalyzerInterface';
import {
import {
createHash,
} from 'crypto';
@@ -74,21 +74,21 @@ export class Cortex implements INodeType {
// Node properties which the user gets displayed and
// can change on the node.
{
displayName:'Resource',
name:'resource',
type:'options',
options:[
displayName: 'Resource',
name: 'resource',
type: 'options',
options: [
{
name: 'Analyzer',
value:'analyzer',
},
{
name: 'Responder',
value:'responder',
value: 'analyzer',
},
{
name: 'Job',
value:'job',
value: 'job',
},
{
name: 'Responder',
value: 'responder',
},
],
default: 'analyzer',
@@ -100,7 +100,7 @@ export class Cortex implements INodeType {
...respondersOperations,
...responderFields,
...jobOperations,
...jobFields
...jobFields,
],
};
@@ -183,7 +183,7 @@ export class Cortex implements INodeType {
returnData.push(
{
value: (dataType as string).split(':')[1],
name: changeCase.capitalCase((dataType as string).split(':')[1])
name: changeCase.capitalCase((dataType as string).split(':')[1]),
},
);
}
@@ -249,13 +249,13 @@ export class Cortex implements INodeType {
options: {
contentType: item.binary[binaryPropertyName].mimeType,
filename: item.binary[binaryPropertyName].fileName,
}
},
},
_json: JSON.stringify({
dataType: observableType,
tlp,
})
}
}),
},
};
responseData = await cortexApiRequest.call(
@@ -327,15 +327,13 @@ export class Cortex implements INodeType {
const entityType = this.getNodeParameter('entityType', i) as string;
const isJSON = this.getNodeParameter('jsonObject',i) as boolean;
let body:IDataObject;
if(isJSON){
const isJSON = this.getNodeParameter('jsonObject', i) as boolean;
let body: IDataObject;
if (isJSON) {
const entityJson = JSON.parse(this.getNodeParameter('objectData', i) as string);
body = {
responderId,
label: getEntityLabel(entityJson),
@@ -344,29 +342,29 @@ export class Cortex implements INodeType {
tlp: entityJson.tlp || 2,
pap: entityJson.pap || 2,
message: entityJson.message || '',
parameters:[],
parameters: [],
};
}else{
const values = (this.getNodeParameter('parameters',i) as IDataObject).values as IDataObject;
} else {
body= {
const values = (this.getNodeParameter('parameters', i) as IDataObject).values as IDataObject;
body = {
responderId,
dataType: `thehive:${entityType}`,
data: {
data: {
_type: entityType,
...prepareParameters(values)
}
...prepareParameters(values),
},
};
if( entityType === 'alert'){
if (entityType === 'alert') {
// deal with alert artifacts
const artifacts = (body.data as IDataObject).artifacts as IDataObject;
if (artifacts) {
const artifactValues = (artifacts as IDataObject).artifactValues as IDataObject[];
if (artifactValues) {
const artifactData = [];
@@ -404,51 +402,51 @@ export class Cortex implements INodeType {
artifactData.push(element);
}
(body.data as IDataObject).artifacts = artifactData;
}
}
}
if(entityType ==='case_artifact'){
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 Error('No binary data exists on item!');
}
const binaryPropertyName = (body.data as IDataObject).binaryPropertyName as string;
if (item.binary[binaryPropertyName] === undefined) {
throw new Error(`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')
sha256,
createHash('sha1').update(fileBufferData).digest('hex'),
createHash('md5').update(fileBufferData).digest('hex'),
],
size:fileBufferData.byteLength,
size: fileBufferData.byteLength,
contentType: item.binary[binaryPropertyName].mimeType,
id:sha256,
};
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
...body,
};
}
responseData = await cortexApiRequest.call(
this,

View File

@@ -10,9 +10,9 @@ import {
import {
IExecuteFunctions,
IExecuteSingleFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IExecuteSingleFunctions,
} from 'n8n-core';
import {
@@ -29,7 +29,7 @@ export async function cortexApiRequest(this: IHookFunctions | IExecuteFunctions
throw new Error('No credentials got returned!');
}
const headerWithAuthentication = Object.assign({}, { Authorization: ` Bearer ${credentials.cortexApiKey}`});
const headerWithAuthentication = Object.assign({}, { Authorization: ` Bearer ${credentials.cortexApiKey}` });
let options: OptionsWithUri = {
headers: headerWithAuthentication,
@@ -41,45 +41,45 @@ export async function cortexApiRequest(this: IHookFunctions | IExecuteFunctions
};
if (Object.keys(option).length !== 0) {
options = Object.assign({},options, option);
options = Object.assign({}, options, option);
}
if (Object.keys(body).length === 0) {
if (Object.keys(body).length === 0) {
delete options.body;
}
if (Object.keys(query).length === 0) {
if (Object.keys(query).length === 0) {
delete options.qs;
}
try {
return await this.helpers.request!(options);
} catch (error) {
if (error.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{
export function getEntityLabel(entity: IDataObject): string {
let label = '';
switch (entity._type) {
case 'case':
case 'case':
label = `#${entity.caseId} ${entity.title}`;
break;
case 'case_artifact':
case 'case_artifact':
//@ts-ignore
label = `[${entity.dataType}] ${entity.data?entity.data:(entity.attachment.name)}`;
label = `[${entity.dataType}] ${entity.data ? entity.data : (entity.attachment.name)}`;
break;
case 'alert':
case 'alert':
label = `[${entity.source}:${entity.sourceRef}] ${entity.title}`;
break;
case 'case_task_log':
case 'case_task_log':
label = `${entity.message} from ${entity.createdBy}`;
break;
case 'case_task':
case 'case_task':
label = `${entity.title} (${entity.status})`;
break;
case 'job':
case 'job':
label = `${entity.analyzerName} (${entity.status})`;
break;
default:
@@ -95,7 +95,7 @@ export function splitTags(tags: string): string[] {
export function prepareParameters(values: IDataObject): IDataObject {
const response: IDataObject = {};
for (const key in values) {
if (values[key]!== undefined && values[key]!==null && values[key]!=='') {
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') {

View File

@@ -7,7 +7,7 @@ export const jobOperations = [
displayName: 'Operation',
name: 'operation',
type: 'options',
description:'Choose an operation',
description: 'Choose an operation',
required: true,
displayOptions: {
show: {
@@ -32,13 +32,13 @@ export const jobOperations = [
},
] as INodeProperties[];
export const jobFields: INodeProperties[] =[
export const jobFields: INodeProperties[] = [
{
displayName: 'Job ID',
name: 'jobId',
type: 'string',
required: true,
displayOptions:{
displayOptions: {
show: {
resource: [
'job',
@@ -49,7 +49,7 @@ export const jobFields: INodeProperties[] =[
],
},
},
default:'',
default: '',
description: 'ID of the job',
},
];

View File

@@ -1,8 +1,8 @@
import {
import {
INodeProperties,
} from 'n8n-workflow';
import {
import {
TLP,
} from './AnalyzerInterface';
@@ -12,7 +12,7 @@ export const respondersOperations = [
name: 'operation',
type: 'options',
required: true,
description: 'Choose an operation',
description: 'Choose an operation.',
displayOptions: {
show: {
resource: [
@@ -24,11 +24,11 @@ export const respondersOperations = [
{
name: 'Execute',
value: 'execute',
description: 'Execute Responder'
}
description: 'Execute Responder',
},
],
default: 'execute'
}
default: 'execute',
},
] as INodeProperties[];
export const responderFields: INodeProperties[] = [
@@ -38,7 +38,7 @@ export const responderFields: INodeProperties[] = [
type: 'options',
required: true,
typeOptions: {
loadOptionsMethod: 'loadActiveResponders'
loadOptionsMethod: 'loadActiveResponders',
},
default: '',
displayOptions: {
@@ -48,7 +48,7 @@ export const responderFields: INodeProperties[] = [
],
},
},
description: 'Choose the responder'
description: 'Choose the responder.',
},
{
displayName: 'Entity Type',
@@ -59,7 +59,7 @@ export const responderFields: INodeProperties[] = [
show: {
resource: [
'responder',
]
],
},
},
typeOptions: {
@@ -69,14 +69,14 @@ export const responderFields: INodeProperties[] = [
],
},
default: '',
description: 'Choose the Data type',
description: 'Choose the Data type.',
},
{
displayName: 'JSON Parameters',
name: 'jsonObject',
type: 'boolean',
default: false,
description: 'Choose between providing JSON object or seperated attributes',
description: 'Choose between providing JSON object or seperated attributes.',
displayOptions: {
show: {
resource: [
@@ -100,7 +100,7 @@ export const responderFields: INodeProperties[] = [
],
},
},
default: ''
default: '',
},
{
displayName: 'Parameters',
@@ -125,7 +125,7 @@ export const responderFields: INodeProperties[] = [
name: 'description',
type: 'string',
default: '',
description: 'Description of the case',
description: 'Description of the case',
},
{
displayName: 'Severity',
@@ -160,14 +160,14 @@ export const responderFields: INodeProperties[] = [
name: 'owner',
type: 'string',
default: '',
description: `User who owns the case. This is automatically set to current user when status is set to InProgress`,
description: `User who owns the case. This is automatically set to current user when status is set to InProgress.`,
},
{
displayName: 'Flag',
name: 'flag',
type: 'boolean',
default: false,
description: 'Flag of the case default=false',
description: 'Flag of the case default=false.',
},
{
displayName: 'TLP',
@@ -199,13 +199,13 @@ export const responderFields: INodeProperties[] = [
name: 'tags',
type: 'string',
default: '',
placeholder:'tag1,tag2,...',
placeholder: 'tag1,tag2,...',
},
],
},
],
typeOptions:{
loadOptionsDependsOn:[
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
},
@@ -231,7 +231,7 @@ export const responderFields: INodeProperties[] = [
],
},
},
default: {}
default: {},
},
{
displayName: 'Parameters',
@@ -263,14 +263,14 @@ export const responderFields: INodeProperties[] = [
name: 'severity',
type: 'options',
default: 2,
options:[
options: [
{
name: 'Low',
value: 1
value: 1,
},
{
name: 'Medium',
value: 2
value: 2,
},
{
name: 'High',
@@ -284,14 +284,14 @@ export const responderFields: INodeProperties[] = [
name: 'date',
type: 'dateTime',
default: '',
description: 'Date and time when the alert was raised default=now',
description: 'Date and time when the alert was raised default=now.',
},
{
displayName: 'Tags',
name: 'tags',
type: 'string',
placeholder:'tag1,tag2,...',
default: ''
placeholder: 'tag1,tag2,...',
default: '',
},
{
displayName: 'TLP',
@@ -300,19 +300,19 @@ export const responderFields: INodeProperties[] = [
default: 2,
options: [
{
name:'White',
value:TLP.white,
name: 'White',
value: TLP.white,
},
{
name:'Green',
value:TLP.green,
name: 'Green',
value: TLP.green,
},
{
name:'Amber',
value:TLP.amber,
},{
name:'Red',
value:TLP.red,
name: 'Amber',
value: TLP.amber,
}, {
name: 'Red',
value: TLP.red,
}
],
description: 'Traffict Light Protocol (TLP). Default=Amber',
@@ -322,7 +322,7 @@ export const responderFields: INodeProperties[] = [
name: 'status',
type: 'options',
default: 'New',
options:[
options: [
{
name: 'New',
value: 'New',
@@ -333,28 +333,28 @@ export const responderFields: INodeProperties[] = [
},
{
name: 'Ignored',
value: 'Ignored'
value: 'Ignored',
},
{
name: 'Imported',
value: 'Imported',
},
],
description: 'Status of the alert. Default=New'
description: 'Status of the alert. Default=New',
},
{
displayName: 'Type',
name: 'type',
type: 'string',
default: '',
description: 'Type of the alert',
description: 'Type of the alert.',
},
{
displayName: 'Source',
name: 'source',
type: 'string',
default: '',
description: 'Source of the alert',
description: 'Source of the alert.',
},
{
displayName: 'SourceRef',
@@ -367,13 +367,13 @@ export const responderFields: INodeProperties[] = [
displayName: 'Follow',
name: 'follow',
type: 'boolean',
default: false
default: false,
},
{
displayName: 'Artifacts',
name: 'artifacts',
type: 'fixedCollection',
placeholder:'Add an artifact',
placeholder: 'Add an artifact',
required: false,
typeOptions: {
multipleValues: true,
@@ -397,55 +397,55 @@ export const responderFields: INodeProperties[] = [
},
{
name: 'File',
value: 'file'
value: 'file',
},
{
name: 'Filename',
value: 'filename'
value: 'filename',
},
{
name: 'Fqdn',
value: 'fqdn'
value: 'fqdn',
},
{
name: 'Hash',
value: 'hash'
value: 'hash',
},
{
name: 'IP',
value: 'ip'
value: 'ip',
},
{
name: 'Mail',
value: 'mail'
value: 'mail',
},
{
name: 'Mail Subject',
value: 'mail_subject'
value: 'mail_subject',
},
{
name: 'Other',
value: 'other'
value: 'other',
},
{
name: 'Regexp',
value: 'regexp'
value: 'regexp',
},
{
name: 'Registry',
value: 'registry'
value: 'registry',
},
{
name: 'Uri Path',
value: 'uri_path'
value: 'uri_path',
},
{
name: 'URL',
value: 'url'
value: 'url',
},
{
name: 'User Agent',
value: 'user-agent'
value: 'user-agent',
},
],
description: '',
@@ -493,14 +493,14 @@ export const responderFields: INodeProperties[] = [
description: '',
},
],
}
]
},
],
},
]
}
],
},
],
typeOptions:{
loadOptionsDependsOn:[
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
},
@@ -554,55 +554,55 @@ export const responderFields: INodeProperties[] = [
},
{
name: 'File',
value: 'file'
value: 'file',
},
{
name: 'Filename',
value: 'filename'
value: 'filename',
},
{
name: 'Fqdn',
value: 'fqdn'
value: 'fqdn',
},
{
name: 'Hash',
value: 'hash'
value: 'hash',
},
{
name: 'IP',
value: 'ip'
value: 'ip',
},
{
name: 'Mail',
value: 'mail'
value: 'mail',
},
{
name: 'Mail Subject',
value: 'mail_subject'
value: 'mail_subject',
},
{
name: 'Other',
value: 'other'
value: 'other',
},
{
name: 'Regexp',
value: 'regexp'
value: 'regexp',
},
{
name: 'Registry',
value: 'registry'
value: 'registry',
},
{
name: 'Uri Path',
value: 'uri_path'
value: 'uri_path',
},
{
name: 'URL',
value: 'url'
value: 'url',
},
{
name: 'User Agent',
value: 'user-agent'
value: 'user-agent',
},
],
},
@@ -611,9 +611,9 @@ export const responderFields: INodeProperties[] = [
name: 'data',
type: 'string',
default: '',
displayOptions:{
hide:{
dataType:[
displayOptions: {
hide: {
dataType: [
'file',
],
},
@@ -626,25 +626,25 @@ export const responderFields: INodeProperties[] = [
default: 'data',
displayOptions: {
show: {
dataType:[
dataType: [
'file',
],
},
},
description: 'Name of the binary property which contains the attachement data',
description: 'Name of the binary property which contains the attachement data.',
},
{
displayName: 'Message',
name: 'message',
type: 'string',
default: ''
default: '',
},
{
displayName: 'Start Date',
name: 'startDate',
type: 'dateTime',
default: '',
description: 'Date and time of the begin of the case default=now',
description: 'Date and time of the begin of the case default=now.',
},
{
displayName: 'TLP',
@@ -653,20 +653,20 @@ export const responderFields: INodeProperties[] = [
default: 2,
options: [
{
name:'White',
value:TLP.white,
name: 'White',
value: TLP.white,
},
{
name:'Green',
value:TLP.green,
name: 'Green',
value: TLP.green,
},
{
name:'Amber',
value:TLP.amber,
},{
name:'Red',
value:TLP.red,
}
name: 'Amber',
value: TLP.amber,
}, {
name: 'Red',
value: TLP.red,
},
],
description: 'Traffict Light Protocol (TLP). Default=Amber',
},
@@ -675,7 +675,7 @@ export const responderFields: INodeProperties[] = [
name: 'ioc',
type: 'boolean',
default: false,
description: 'Indicates if the observable is an IOC (Indicator of compromise)',
description: 'Indicates if the observable is an IOC (Indicator of compromise).',
},
{
displayName: 'Status',
@@ -692,13 +692,13 @@ export const responderFields: INodeProperties[] = [
value: 'Deleted',
},
],
description: 'Status of the observable (Ok or Deleted) default=Ok',
}
description: 'Status of the observable (Ok or Deleted) default=Ok.',
},
],
},
],
typeOptions:{
loadOptionsDependsOn:[
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
},
@@ -746,7 +746,7 @@ export const responderFields: INodeProperties[] = [
type: 'string',
required: false,
default: '',
description: 'Title of the task',
description: 'Title of the task.',
},
{
displayName: 'Status',
@@ -776,13 +776,13 @@ export const responderFields: INodeProperties[] = [
displayName: 'Flag',
name: 'flag',
type: 'boolean',
default: false
}
]
}
default: false,
},
],
},
],
typeOptions:{
loadOptionsDependsOn:[
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
},
@@ -828,7 +828,7 @@ export const responderFields: INodeProperties[] = [
displayName: 'Message',
name: 'message',
type: 'string',
default: ''
default: '',
},
{
displayName: 'Start Date',
@@ -857,8 +857,8 @@ export const responderFields: INodeProperties[] = [
],
},
],
typeOptions:{
loadOptionsDependsOn:[
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
},
@@ -889,4 +889,4 @@ export const responderFields: INodeProperties[] = [
},
default: {},
},
];
];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 837 B