mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
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:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user