mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
feat(TheHive Node): Overhaul (#6457)
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
INodeExecutionData,
|
||||
INodeProperties,
|
||||
} from 'n8n-workflow';
|
||||
import { updateDisplayOptions, wrapData } from '@utils/utilities';
|
||||
import { observableRLC, observableTypeOptions } from '../../descriptions';
|
||||
import { theHiveApiRequest } from '../../transport';
|
||||
|
||||
const properties: INodeProperties[] = [
|
||||
observableRLC,
|
||||
observableTypeOptions,
|
||||
{
|
||||
displayName: 'Analyzer Names or IDs',
|
||||
name: 'analyzers',
|
||||
type: 'multiOptions',
|
||||
description:
|
||||
'Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
|
||||
required: true,
|
||||
default: [],
|
||||
typeOptions: {
|
||||
loadOptionsDependsOn: ['observableId.value', 'dataType'],
|
||||
loadOptionsMethod: 'loadAnalyzers',
|
||||
},
|
||||
displayOptions: {
|
||||
hide: {
|
||||
id: [''],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const displayOptions = {
|
||||
show: {
|
||||
resource: ['observable'],
|
||||
operation: ['executeAnalyzer'],
|
||||
},
|
||||
};
|
||||
|
||||
export const description = updateDisplayOptions(displayOptions, properties);
|
||||
|
||||
export async function execute(this: IExecuteFunctions, i: number): Promise<INodeExecutionData[]> {
|
||||
let responseData: IDataObject = {};
|
||||
|
||||
const observableId = this.getNodeParameter('observableId', i, '', {
|
||||
extractValue: true,
|
||||
}) as string;
|
||||
|
||||
const analyzers = (this.getNodeParameter('analyzers', i) as string[]).map((analyzer) => {
|
||||
const parts = analyzer.split('::');
|
||||
return {
|
||||
analyzerId: parts[0],
|
||||
cortexId: parts[1],
|
||||
};
|
||||
});
|
||||
let response: any;
|
||||
let body: IDataObject;
|
||||
|
||||
const qs: IDataObject = {};
|
||||
for (const analyzer of analyzers) {
|
||||
body = {
|
||||
...analyzer,
|
||||
artifactId: observableId,
|
||||
};
|
||||
// execute the analyzer
|
||||
response = await theHiveApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
'/connector/cortex/job' as string,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
const jobId = response.id;
|
||||
qs.name = 'observable-jobs';
|
||||
// query the job result (including the report)
|
||||
do {
|
||||
responseData = await theHiveApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/connector/cortex/job/${jobId}`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
} while (responseData.status === 'Waiting' || responseData.status === 'InProgress');
|
||||
}
|
||||
|
||||
const executionData = this.helpers.constructExecutionMetaData(wrapData(responseData), {
|
||||
itemData: { item: i },
|
||||
});
|
||||
|
||||
return executionData;
|
||||
}
|
||||
Reference in New Issue
Block a user