refactor: Format nodes-base package (A-F) (#3800)

* 🔨 prettier formated nodes - A

* 🔨 prettier formated nodes - B

*  prettier formated nodes - C

*  prettier formated nodes - D

*  prettier formated nodes - E-F

* 🎨 Adjust nodes-base formatting command (#3805)

* Format additional files in nodes A-F (#3811)

*  fixes

* 🎨 Add Mindee to ignored dirs

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Michael Kret
2022-08-01 23:47:55 +03:00
committed by GitHub
parent 2c17e6f3ca
commit 0ecbb4a19d
411 changed files with 12906 additions and 20148 deletions

View File

@@ -1,10 +1,6 @@
import {
INodeProperties,
} from 'n8n-workflow';
import { INodeProperties } from 'n8n-workflow';
import {
TLP,
} from './AnalyzerInterface';
import { TLP } from './AnalyzerInterface';
export const analyzersOperations: INodeProperties[] = [
{
@@ -16,9 +12,7 @@ export const analyzersOperations: INodeProperties[] = [
description: 'Choose an operation',
displayOptions: {
show: {
resource: [
'analyzer',
],
resource: ['analyzer'],
},
},
default: 'execute',
@@ -44,15 +38,12 @@ export const analyzerFields: INodeProperties[] = [
},
displayOptions: {
show: {
resource: [
'analyzer',
],
operation: [
'execute',
],
resource: ['analyzer'],
operation: ['execute'],
},
},
description: 'Choose the analyzer. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'Choose the analyzer. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
default: '',
},
{
@@ -62,27 +53,20 @@ export const analyzerFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'analyzer',
],
operation: [
'execute',
],
resource: ['analyzer'],
operation: ['execute'],
},
hide: {
analyzer: [
'',
],
analyzer: [''],
},
},
typeOptions: {
loadOptionsMethod: 'loadObservableOptions',
loadOptionsDependsOn: [
'analyzer',
],
loadOptionsDependsOn: ['analyzer'],
},
default: '',
description: 'Choose the observable type. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'Choose the observable type. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
// Observable type != file
@@ -93,20 +77,12 @@ export const analyzerFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'analyzer',
],
operation: [
'execute',
],
resource: ['analyzer'],
operation: ['execute'],
},
hide: {
observableType: [
'file',
],
analyzer: [
'',
],
observableType: ['file'],
analyzer: [''],
},
},
default: '',
@@ -120,15 +96,9 @@ export const analyzerFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
observableType: [
'file',
],
resource: [
'analyzer',
],
operation: [
'execute',
],
observableType: ['file'],
resource: ['analyzer'],
operation: ['execute'],
},
},
description: 'Name of the binary property to which to write the data of the read file',
@@ -139,20 +109,12 @@ export const analyzerFields: INodeProperties[] = [
type: 'options',
displayOptions: {
show: {
resource: [
'analyzer',
],
operation: [
'execute',
],
resource: ['analyzer'],
operation: ['execute'],
},
hide: {
observableType: [
'',
],
analyzer: [
'',
],
observableType: [''],
analyzer: [''],
},
},
options: [
@@ -167,7 +129,8 @@ export const analyzerFields: INodeProperties[] = [
{
name: 'Amber',
value: TLP.amber,
}, {
},
{
name: 'Red',
value: TLP.red,
},
@@ -183,12 +146,8 @@ export const analyzerFields: INodeProperties[] = [
default: {},
displayOptions: {
show: {
resource: [
'analyzer',
],
operation: [
'execute',
],
resource: ['analyzer'],
operation: ['execute'],
},
},
options: [
@@ -204,7 +163,8 @@ export const analyzerFields: INodeProperties[] = [
name: 'timeout',
type: 'number',
default: 3,
description: 'Timeout to wait for the report in case it is not available at the time the query was made',
description:
'Timeout to wait for the report in case it is not available at the time the query was made',
},
],
},

View File

@@ -1,6 +1,4 @@
import {
IDataObject,
} from 'n8n-workflow';
import { IDataObject } from 'n8n-workflow';
export enum JobStatus {
WAITING = 'Waiting',

View File

@@ -1,18 +1,8 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import { IExecuteFunctions } from 'n8n-core';
import {
cortexApiRequest,
getEntityLabel,
prepareParameters,
splitTags,
} from './GenericFunctions';
import { cortexApiRequest, getEntityLabel, prepareParameters, splitTags } from './GenericFunctions';
import {
analyzerFields,
analyzersOperations,
} from './AnalyzerDescriptions';
import { analyzerFields, analyzersOperations } from './AnalyzerDescriptions';
import {
IBinaryData,
@@ -25,27 +15,15 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import {
responderFields,
respondersOperations,
} from './ResponderDescription';
import { responderFields, respondersOperations } from './ResponderDescription';
import {
jobFields,
jobOperations,
} from './JobDescription';
import { jobFields, jobOperations } from './JobDescription';
import {
upperFirst,
} from 'lodash';
import { upperFirst } from 'lodash';
import {
IJob,
} from './AnalyzerInterface';
import { IJob } from './AnalyzerInterface';
import {
createHash,
} from 'crypto';
import { createHash } from 'crypto';
import * as changeCase from 'change-case';
@@ -106,7 +84,6 @@ export class Cortex implements INodeType {
methods = {
loadOptions: {
async loadActiveAnalyzers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
// request the enabled analyzers from instance
const requestResult = await cortexApiRequest.call(
@@ -130,11 +107,7 @@ export class Cortex implements INodeType {
async loadActiveResponders(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
// request the enabled responders from instance
const requestResult = await cortexApiRequest.call(
this,
'GET',
`/responder`,
);
const requestResult = await cortexApiRequest.call(this, 'GET', `/responder`);
const returnData: INodePropertyOptions[] = [];
for (const responder of requestResult) {
@@ -159,12 +132,10 @@ export class Cortex implements INodeType {
// parse supported observable types into options
const returnData: INodePropertyOptions[] = [];
for (const dataType of requestResult.dataTypeList) {
returnData.push(
{
name: upperFirst(dataType as string),
value: dataType as string,
},
);
returnData.push({
name: upperFirst(dataType as string),
value: dataType as string,
});
}
return returnData;
},
@@ -180,16 +151,13 @@ export class Cortex implements INodeType {
// parse the accepted dataType into options
const returnData: INodePropertyOptions[] = [];
for (const dataType of requestResult.dataTypeList) {
returnData.push(
{
value: (dataType as string).split(':')[1],
name: changeCase.capitalCase((dataType as string).split(':')[1]),
},
);
returnData.push({
value: (dataType as string).split(':')[1],
name: changeCase.capitalCase((dataType as string).split(':')[1]),
});
}
return returnData;
},
},
};
@@ -204,11 +172,9 @@ export class Cortex implements INodeType {
for (let i = 0; i < length; i++) {
try {
if (resource === 'analyzer') {
//https://github.com/TheHive-Project/CortexDocs/blob/master/api/api-guide.md#run
if (operation === 'execute') {
let force = false;
const analyzer = this.getNodeParameter('analyzer', i) as string;
@@ -229,17 +195,22 @@ export class Cortex implements INodeType {
}
if (observableType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: i });
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
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!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`No binary data property "${binaryPropertyName}" does not exists on item!`,
{ itemIndex: i },
);
}
const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
@@ -260,7 +231,7 @@ export class Cortex implements INodeType {
},
};
responseData = await cortexApiRequest.call(
responseData = (await cortexApiRequest.call(
this,
'POST',
`/analyzer/${analyzer.split('::')[0]}/run`,
@@ -268,22 +239,21 @@ export class Cortex implements INodeType {
{ force },
'',
options,
) as IJob;
)) as IJob;
continue;
} else {
const observableValue = this.getNodeParameter('observableValue', i) as string;
body.data = observableValue;
responseData = await cortexApiRequest.call(
responseData = (await cortexApiRequest.call(
this,
'POST',
`/analyzer/${analyzer.split('::')[0]}/run`,
body,
{ force },
) as IJob;
)) as IJob;
}
if (additionalFields.timeout) {
@@ -301,25 +271,15 @@ export class Cortex implements INodeType {
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;
responseData = await cortexApiRequest.call(
this,
'GET',
`/job/${jobId}`,
);
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`,
);
responseData = await cortexApiRequest.call(this, 'GET', `/job/${jobId}/report`);
}
}
@@ -332,7 +292,6 @@ export class Cortex implements INodeType {
const isJSON = this.getNodeParameter('jsonObject', i) as boolean;
let body: IDataObject;
if (isJSON) {
const entityJson = JSON.parse(this.getNodeParameter('objectData', i) as string);
@@ -346,10 +305,9 @@ export class Cortex implements INodeType {
message: entityJson.message || '',
parameters: [],
};
} 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,
@@ -364,15 +322,12 @@ export class Cortex implements INodeType {
const artifacts = (body.data as IDataObject).artifacts as IDataObject;
if (artifacts) {
const artifactValues = (artifacts as IDataObject).artifactValues as IDataObject[];
if (artifactValues) {
const artifactData = [];
for (const artifactvalue of artifactValues) {
const element: IDataObject = {};
element.message = artifactvalue.message as string;
@@ -384,17 +339,24 @@ export class Cortex implements INodeType {
element.data = artifactvalue.data as string;
if (artifactvalue.dataType === 'file') {
const item = items[i];
if (item.binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
'No binary data exists on item!',
{ itemIndex: i },
);
}
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!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`No binary data property '${binaryPropertyName}' does not exists on item!`,
{ itemIndex: i },
);
}
const binaryData = item.binary[binaryPropertyName] as IBinaryData;
@@ -413,19 +375,28 @@ export class Cortex implements INodeType {
// 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!', { itemIndex: i });
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = (body.data as IDataObject).binaryPropertyName as string;
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!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`No binary data property "${binaryPropertyName}" does not exists on item!`,
{ itemIndex: i },
);
}
const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
const fileBufferData = await this.helpers.getBinaryDataBuffer(
i,
binaryPropertyName,
);
const sha256 = createHash('sha256').update(fileBufferData).digest('hex');
(body.data as IDataObject).attachment = {
@@ -448,14 +419,13 @@ export class Cortex implements INodeType {
label: getEntityLabel(body.data as IDataObject),
...body,
};
}
responseData = await cortexApiRequest.call(
responseData = (await cortexApiRequest.call(
this,
'POST',
`/responder/${responderId}/run`,
body,
) as IJob;
)) as IJob;
}
}
@@ -464,7 +434,6 @@ export class Cortex implements INodeType {
} else if (responseData !== undefined) {
returnData.push(responseData as IDataObject);
}
} catch (error) {
if (this.continueOnFail()) {
returnData.push({ error: error.message });

View File

@@ -1,6 +1,4 @@
import {
OptionsWithUri,
} from 'request';
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
@@ -9,14 +7,21 @@ import {
ILoadOptionsFunctions,
} from 'n8n-core';
import {
IDataObject, NodeApiError, NodeOperationError,
} from 'n8n-workflow';
import { IDataObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
import 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
export async function cortexApiRequest(
this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
method: string,
resource: string,
// tslint:disable-next-line:no-any
body: any = {},
query: IDataObject = {},
uri?: string,
option: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const credentials = await this.getCredentials('cortexApi');
let options: OptionsWithUri = {
@@ -26,7 +31,6 @@ export async function cortexApiRequest(this: IHookFunctions | IExecuteFunctions
uri: uri || `${credentials.host}/api${resource}`,
body,
json: true,
};
if (Object.keys(option).length !== 0) {
options = Object.assign({}, options, option);
@@ -53,7 +57,7 @@ export function getEntityLabel(entity: IDataObject): string {
break;
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':
label = `[${entity.source}:${entity.sourceRef}] ${entity.title}`;
@@ -74,7 +78,7 @@ export function getEntityLabel(entity: IDataObject): string {
}
export function splitTags(tags: string): string[] {
return tags.split(',').filter(tag => tag !== ' ' && tag);
return tags.split(',').filter((tag) => tag !== ' ' && tag);
}
export function prepareParameters(values: IDataObject): IDataObject {

View File

@@ -1,6 +1,4 @@
import {
INodeProperties,
} from 'n8n-workflow';
import { INodeProperties } from 'n8n-workflow';
export const jobOperations: INodeProperties[] = [
{
@@ -12,9 +10,7 @@ export const jobOperations: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'job',
],
resource: ['job'],
},
},
options: [
@@ -43,13 +39,8 @@ export const jobFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'job',
],
operation: [
'get',
'report',
],
resource: ['job'],
operation: ['get', 'report'],
},
},
default: '',

View File

@@ -1,10 +1,6 @@
import {
INodeProperties,
} from 'n8n-workflow';
import { INodeProperties } from 'n8n-workflow';
import {
TLP,
} from './AnalyzerInterface';
import { TLP } from './AnalyzerInterface';
export const respondersOperations: INodeProperties[] = [
{
@@ -16,9 +12,7 @@ export const respondersOperations: INodeProperties[] = [
description: 'Choose an operation',
displayOptions: {
show: {
resource: [
'responder',
],
resource: ['responder'],
},
},
options: [
@@ -45,12 +39,11 @@ export const responderFields: INodeProperties[] = [
default: '',
displayOptions: {
show: {
resource: [
'responder',
],
resource: ['responder'],
},
},
description: 'Choose the responder. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'Choose the responder. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
{
displayName: 'Entity Type Name or ID',
@@ -59,19 +52,16 @@ export const responderFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'responder',
],
resource: ['responder'],
},
},
typeOptions: {
loadOptionsMethod: 'loadDataTypeOptions',
loadOptionsDependsOn: [
'responder',
],
loadOptionsDependsOn: ['responder'],
},
default: '',
description: 'Choose the Data type. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
description:
'Choose the Data type. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
},
{
displayName: 'JSON Parameters',
@@ -82,9 +72,7 @@ export const responderFields: INodeProperties[] = [
description: 'Choose between providing JSON object or seperated attributes',
displayOptions: {
show: {
resource: [
'responder',
],
resource: ['responder'],
},
},
},
@@ -95,12 +83,8 @@ export const responderFields: INodeProperties[] = [
required: true,
displayOptions: {
show: {
resource: [
'responder',
],
jsonObject: [
true,
],
resource: ['responder'],
jsonObject: [true],
},
},
default: '',
@@ -135,7 +119,8 @@ 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: 'Severity',
@@ -208,30 +193,16 @@ export const responderFields: INodeProperties[] = [
},
],
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
loadOptionsDependsOn: ['entityType'],
},
displayOptions: {
show: {
resource: [
'responder',
],
jsonObject: [
false,
],
entityType: [
'case',
],
resource: ['responder'],
jsonObject: [false],
entityType: ['case'],
},
hide: {
entityType: [
'',
'alert',
'case_artifact',
'case_task',
'case_task_log',
],
entityType: ['', 'alert', 'case_artifact', 'case_task', 'case_task_log'],
},
},
default: {},
@@ -267,9 +238,7 @@ export const responderFields: INodeProperties[] = [
type: 'string',
displayOptions: {
show: {
dataType: [
'file',
],
dataType: ['file'],
},
},
default: 'data',
@@ -280,9 +249,7 @@ export const responderFields: INodeProperties[] = [
type: 'string',
displayOptions: {
hide: {
dataType: [
'file',
],
dataType: ['file'],
},
},
default: '',
@@ -497,33 +464,17 @@ export const responderFields: INodeProperties[] = [
},
],
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
loadOptionsDependsOn: ['entityType'],
},
displayOptions: {
show: {
resource: [
'responder',
],
jsonObject: [
false,
],
entityType: [
'alert',
],
resource: ['responder'],
jsonObject: [false],
entityType: ['alert'],
},
hide: {
responder: [
'',
],
entityType: [
'',
'case',
'case_artifact',
'case_task',
'case_task_log',
],
responder: [''],
entityType: ['', 'case', 'case_artifact', 'case_task', 'case_task_log'],
},
},
default: {},
@@ -545,9 +496,7 @@ export const responderFields: INodeProperties[] = [
default: 'data',
displayOptions: {
show: {
dataType: [
'file',
],
dataType: ['file'],
},
},
description: 'Name of the binary property which contains the attachement data',
@@ -559,9 +508,7 @@ export const responderFields: INodeProperties[] = [
default: '',
displayOptions: {
hide: {
dataType: [
'file',
],
dataType: ['file'],
},
},
},
@@ -683,7 +630,8 @@ export const responderFields: INodeProperties[] = [
{
name: 'Amber',
value: TLP.amber,
}, {
},
{
name: 'Red',
value: TLP.red,
},
@@ -694,33 +642,17 @@ export const responderFields: INodeProperties[] = [
},
],
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
loadOptionsDependsOn: ['entityType'],
},
displayOptions: {
show: {
resource: [
'responder',
],
jsonObject: [
false,
],
entityType: [
'case_artifact',
],
resource: ['responder'],
jsonObject: [false],
entityType: ['case_artifact'],
},
hide: {
responder: [
'',
],
entityType: [
'',
'case',
'alert',
'case_task',
'case_task_log',
],
responder: [''],
entityType: ['', 'case', 'alert', 'case_task', 'case_task_log'],
},
},
default: {},
@@ -776,33 +708,17 @@ export const responderFields: INodeProperties[] = [
},
],
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
loadOptionsDependsOn: ['entityType'],
},
displayOptions: {
show: {
resource: [
'responder',
],
jsonObject: [
false,
],
entityType: [
'case_task',
],
resource: ['responder'],
jsonObject: [false],
entityType: ['case_task'],
},
hide: {
responder: [
'',
],
entityType: [
'',
'case',
'alert',
'case_artifact',
'case_task_log',
],
responder: [''],
entityType: ['', 'case', 'alert', 'case_artifact', 'case_task_log'],
},
},
default: {},
@@ -851,33 +767,17 @@ export const responderFields: INodeProperties[] = [
},
],
typeOptions: {
loadOptionsDependsOn: [
'entityType',
],
loadOptionsDependsOn: ['entityType'],
},
displayOptions: {
show: {
resource: [
'responder',
],
jsonObject: [
false,
],
entityType: [
'case_task_log',
],
resource: ['responder'],
jsonObject: [false],
entityType: ['case_task_log'],
},
hide: {
responder: [
'',
],
entityType: [
'',
'case',
'alert',
'case_artifact',
'case_task',
],
responder: [''],
entityType: ['', 'case', 'alert', 'case_artifact', 'case_task'],
},
},
default: {},