2020-12-02 02:24:25 -08:00
|
|
|
import {
|
2020-12-02 02:54:10 -08:00
|
|
|
IExecuteFunctions
|
2020-12-02 02:24:25 -08:00
|
|
|
} from 'n8n-core';
|
|
|
|
|
|
|
|
import {
|
2020-12-02 02:54:10 -08:00
|
|
|
IBinaryData,
|
2020-12-02 02:24:25 -08:00
|
|
|
IDataObject,
|
|
|
|
ILoadOptionsFunctions,
|
2020-12-02 02:54:10 -08:00
|
|
|
INodeExecutionData,
|
|
|
|
INodeParameters,
|
2020-12-02 02:24:25 -08:00
|
|
|
INodePropertyOptions,
|
2020-12-02 02:54:10 -08:00
|
|
|
INodeType,
|
2021-04-16 09:33:36 -07:00
|
|
|
INodeTypeDescription,
|
|
|
|
NodeOperationError,
|
2020-12-02 02:24:25 -08:00
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import {
|
|
|
|
alertFields,
|
2020-12-02 02:54:10 -08:00
|
|
|
alertOperations,
|
2020-12-02 02:24:25 -08:00
|
|
|
} from './descriptions/AlertDescription';
|
|
|
|
|
|
|
|
import {
|
|
|
|
observableFields,
|
2020-12-02 02:54:10 -08:00
|
|
|
observableOperations,
|
2020-12-02 02:24:25 -08:00
|
|
|
} from './descriptions/ObservableDescription';
|
|
|
|
|
|
|
|
import {
|
|
|
|
caseFields,
|
2020-12-02 02:54:10 -08:00
|
|
|
caseOperations,
|
2020-12-02 02:24:25 -08:00
|
|
|
} from './descriptions/CaseDescription';
|
|
|
|
|
|
|
|
import {
|
|
|
|
taskFields,
|
2020-12-02 02:54:10 -08:00
|
|
|
taskOperations,
|
2020-12-02 02:24:25 -08:00
|
|
|
} from './descriptions/TaskDescription';
|
|
|
|
|
|
|
|
import {
|
|
|
|
logFields,
|
2020-12-02 02:54:10 -08:00
|
|
|
logOperations,
|
2020-12-02 02:24:25 -08:00
|
|
|
} from './descriptions/LogDescription';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Buffer,
|
|
|
|
} from 'buffer';
|
|
|
|
|
|
|
|
import {
|
|
|
|
And,
|
|
|
|
Between,
|
|
|
|
ContainsString,
|
2020-12-02 02:54:10 -08:00
|
|
|
Eq,
|
|
|
|
Id,
|
|
|
|
In,
|
|
|
|
IQueryObject,
|
|
|
|
Parent,
|
2020-12-02 02:24:25 -08:00
|
|
|
} from './QueryFunctions';
|
|
|
|
|
|
|
|
import {
|
2021-07-14 10:18:46 -07:00
|
|
|
buildCustomFieldSearch,
|
2020-12-02 02:24:25 -08:00
|
|
|
mapResource,
|
2021-07-14 10:18:46 -07:00
|
|
|
prepareCustomFields,
|
2020-12-02 02:24:25 -08:00
|
|
|
prepareOptional,
|
|
|
|
prepareRangeQuery,
|
2020-12-02 02:54:10 -08:00
|
|
|
prepareSortQuery,
|
|
|
|
splitTags,
|
|
|
|
theHiveApiRequest,
|
2020-12-02 02:24:25 -08:00
|
|
|
} from './GenericFunctions';
|
|
|
|
|
|
|
|
export class TheHive implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'TheHive',
|
|
|
|
name: 'theHive',
|
2021-03-18 05:06:51 -07:00
|
|
|
icon: 'file:thehive.svg',
|
2020-12-02 02:24:25 -08:00
|
|
|
group: ['transform'],
|
|
|
|
subtitle: '={{$parameter["operation"]}} : {{$parameter["resource"]}}',
|
|
|
|
version: 1,
|
2021-07-03 05:40:16 -07:00
|
|
|
description: 'Consume TheHive API',
|
2020-12-02 02:24:25 -08:00
|
|
|
defaults: {
|
|
|
|
name: 'TheHive',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'theHiveApi',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
|
|
|
required: true,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Alert',
|
|
|
|
value: 'alert',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Case',
|
|
|
|
value: 'case',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Log',
|
|
|
|
value: 'log',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Observable',
|
|
|
|
value: 'observable',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Task',
|
|
|
|
value: 'task',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'alert',
|
|
|
|
},
|
|
|
|
// Alert
|
|
|
|
...alertOperations,
|
|
|
|
...alertFields,
|
|
|
|
// Observable
|
|
|
|
...observableOperations,
|
|
|
|
...observableFields,
|
|
|
|
// Case
|
|
|
|
...caseOperations,
|
|
|
|
...caseFields,
|
|
|
|
// Task
|
|
|
|
...taskOperations,
|
|
|
|
...taskFields,
|
|
|
|
// Log
|
|
|
|
...logOperations,
|
|
|
|
...logFields,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
methods = {
|
|
|
|
loadOptions: {
|
|
|
|
async loadResponders(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
// request the analyzers from instance
|
|
|
|
const resource = mapResource(this.getNodeParameter('resource') as string);
|
|
|
|
const resourceId = this.getNodeParameter('id');
|
|
|
|
const endpoint = `/connector/cortex/responder/${resource}/${resourceId}`;
|
|
|
|
|
|
|
|
const responders = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
endpoint as string,
|
|
|
|
);
|
|
|
|
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
for (const responder of responders) {
|
|
|
|
returnData.push({
|
|
|
|
name: responder.name as string,
|
|
|
|
value: responder.id,
|
|
|
|
description: responder.description as string,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
|
|
|
|
|
|
|
async loadAnalyzers(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
// request the analyzers from instance
|
|
|
|
const dataType = this.getNodeParameter('dataType') as string;
|
|
|
|
const endpoint = `/connector/cortex/analyzer/type/${dataType}`;
|
|
|
|
const requestResult = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
2020-12-02 02:54:10 -08:00
|
|
|
endpoint as string,
|
2020-12-02 02:24:25 -08:00
|
|
|
);
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
for (const analyzer of requestResult) {
|
|
|
|
for (const cortexId of analyzer.cortexIds) {
|
|
|
|
returnData.push({
|
|
|
|
name: `[${cortexId}] ${analyzer.name}`,
|
|
|
|
value: `${analyzer.id as string}::${cortexId as string}`,
|
|
|
|
description: analyzer.description as string,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnData;
|
|
|
|
},
|
2021-07-14 10:18:46 -07:00
|
|
|
async loadCustomFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi');
|
|
|
|
if (credentials === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained');
|
|
|
|
}
|
|
|
|
const version = credentials.apiVersion;
|
2021-07-14 10:18:46 -07:00
|
|
|
const endpoint = version === 'v1' ? '/customField' : '/list/custom_fields';
|
|
|
|
|
|
|
|
const requestResult = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
endpoint as string,
|
|
|
|
);
|
|
|
|
|
|
|
|
const returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
// Convert TheHive3 response to the same format as TheHive 4
|
|
|
|
const customFields = version === 'v1' ? requestResult : Object.keys(requestResult).map(key => requestResult[key]);
|
|
|
|
|
|
|
|
for (const field of customFields) {
|
|
|
|
returnData.push({
|
|
|
|
name: `${field.name}: ${field.reference}`,
|
|
|
|
value: field.reference,
|
|
|
|
description: `${field.type}: ${field.description}`,
|
|
|
|
} as INodePropertyOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
},
|
2020-12-02 02:24:25 -08:00
|
|
|
async loadObservableOptions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
|
|
|
// if v1 is not used we remove 'count' option
|
2021-08-20 09:57:30 -07:00
|
|
|
const version = (await this.getCredentials('theHiveApi'))?.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2020-12-02 02:54:10 -08:00
|
|
|
const options = [
|
|
|
|
...(version === 'v1') ? [{ name: 'Count', value: 'count', description: 'Count observables' }] : [],
|
|
|
|
{ name: 'Create', value: 'create', description: 'Create observable' },
|
|
|
|
{ name: 'Execute Analyzer', value: 'executeAnalyzer', description: 'Execute an responder on selected observable' },
|
|
|
|
{ name: 'Execute Responder', value: 'executeResponder', description: 'Execute a responder on selected observable' },
|
|
|
|
{ name: 'Get All', value: 'getAll', description: 'Get all observables of a specific case' },
|
|
|
|
{ name: 'Get', value: 'get', description: 'Get a single observable' },
|
|
|
|
{ name: 'Search', value: 'search', description: 'Search observables' },
|
|
|
|
{ name: 'Update', value: 'update', description: 'Update observable' },
|
2020-12-02 02:24:25 -08:00
|
|
|
];
|
|
|
|
return options;
|
|
|
|
},
|
2021-04-05 01:52:56 -07:00
|
|
|
async loadObservableTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const version = (await this.getCredentials('theHiveApi'))?.apiVersion;
|
2021-04-05 01:52:56 -07:00
|
|
|
const endpoint = version === 'v1' ? '/observable/type?range=all' : '/list/list_artifactDataType';
|
|
|
|
|
|
|
|
const dataTypes = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
endpoint as string,
|
|
|
|
);
|
2021-12-23 04:30:35 -08:00
|
|
|
|
2021-04-05 01:52:56 -07:00
|
|
|
let returnData: INodePropertyOptions[] = [];
|
|
|
|
|
|
|
|
if (version === 'v1') {
|
|
|
|
returnData = dataTypes.map((dataType: IDataObject) => {
|
|
|
|
return {
|
|
|
|
name: dataType.name as string,
|
|
|
|
value: dataType.name as string,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
returnData = Object.keys(dataTypes).map(key => {
|
|
|
|
const dataType = dataTypes[key] as string;
|
2021-12-23 04:30:35 -08:00
|
|
|
|
2021-04-05 01:52:56 -07:00
|
|
|
return {
|
|
|
|
name: dataType,
|
|
|
|
value: dataType,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort the array by option name
|
|
|
|
returnData.sort((a, b) => {
|
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
return returnData;
|
|
|
|
},
|
2020-12-02 02:54:10 -08:00
|
|
|
async loadTaskOptions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi');
|
|
|
|
if (credentials === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained');
|
|
|
|
}
|
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:54:10 -08:00
|
|
|
const options = [
|
|
|
|
...(version === 'v1') ? [{ name: 'Count', value: 'count', description: 'Count tasks' }] : [],
|
|
|
|
{ name: 'Create', value: 'create', description: 'Create a task' },
|
|
|
|
{ name: 'Execute Responder', value: 'executeResponder', description: 'Execute a responder on the specified task' },
|
|
|
|
{ name: 'Get All', value: 'getAll', description: 'Get all asks of a specific case' },
|
|
|
|
{ name: 'Get', value: 'get', description: 'Get a single task' },
|
|
|
|
{ name: 'Search', value: 'search', description: 'Search tasks' },
|
|
|
|
{ name: 'Update', value: 'update', description: 'Update a task' },
|
2020-12-02 02:24:25 -08:00
|
|
|
];
|
|
|
|
return options;
|
|
|
|
},
|
2020-12-02 02:54:10 -08:00
|
|
|
async loadAlertOptions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi');
|
|
|
|
if (credentials === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained');
|
|
|
|
}
|
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
const options = [
|
2020-12-02 02:54:10 -08:00
|
|
|
...(version === 'v1') ? [{ name: 'Count', value: 'count', description: 'Count alerts' }] : [],
|
2020-12-02 02:24:25 -08:00
|
|
|
{ name: 'Create', value: 'create', description: 'Create alert' },
|
|
|
|
{ name: 'Execute Responder', value: 'executeResponder', description: 'Execute a responder on the specified alert' },
|
|
|
|
{ name: 'Get', value: 'get', description: 'Get an alert' },
|
|
|
|
{ name: 'Get All', value: 'getAll', description: 'Get all alerts' },
|
2021-03-18 05:06:51 -07:00
|
|
|
{ name: 'Mark as Read', value: 'markAsRead', description: 'Mark the alert as read' },
|
|
|
|
{ name: 'Mark as Unread', value: 'markAsUnread', description: 'Mark the alert as unread' },
|
2020-12-02 02:24:25 -08:00
|
|
|
{ name: 'Merge', value: 'merge', description: 'Merge alert into an existing case' },
|
|
|
|
{ name: 'Promote', value: 'promote', description: 'Promote an alert into a case' },
|
|
|
|
{ name: 'Update', value: 'update', description: 'Update alert' },
|
|
|
|
];
|
|
|
|
return options;
|
|
|
|
},
|
2020-12-02 02:54:10 -08:00
|
|
|
async loadCaseOptions(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi');
|
|
|
|
if (credentials === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), 'Credentials could not be obtained');
|
|
|
|
}
|
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:54:10 -08:00
|
|
|
const options = [
|
|
|
|
...(version === 'v1') ? [{ name: 'Count', value: 'count', description: 'Count a case' }] : [],
|
2020-12-02 02:24:25 -08:00
|
|
|
{ name: 'Create', value: 'create', description: 'Create a case' },
|
|
|
|
{ name: 'Execute Responder', value: 'executeResponder', description: 'Execute a responder on the specified case' },
|
|
|
|
{ name: 'Get All', value: 'getAll', description: 'Get all cases' },
|
|
|
|
{ name: 'Get', value: 'get', description: 'Get a single case' },
|
|
|
|
{ name: 'Update', value: 'update', description: 'Update a case' },
|
|
|
|
];
|
|
|
|
return options;
|
2020-12-02 02:54:10 -08:00
|
|
|
},
|
|
|
|
},
|
2020-12-02 02:24:25 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
|
|
|
const length = (items.length as unknown) as number;
|
|
|
|
const qs: IDataObject = {};
|
|
|
|
let responseData;
|
|
|
|
const resource = this.getNodeParameter('resource', 0) as string;
|
|
|
|
const operation = this.getNodeParameter('operation', 0) as string;
|
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
if (resource === 'alert') {
|
|
|
|
if (operation === 'count') {
|
|
|
|
const filters = this.getNodeParameter('filters', i, {}) as INodeParameters;
|
|
|
|
const countQueryAttributs: any = prepareOptional(filters); // tslint:disable-line:no-any
|
2021-12-23 04:30:35 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const _countSearchQuery: IQueryObject = And();
|
2021-07-14 10:18:46 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if ('customFieldsUi' in filters) {
|
|
|
|
const customFields = await prepareCustomFields.call(this, filters) as IDataObject;
|
|
|
|
const searchQueries = buildCustomFieldSearch(customFields);
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(...searchQueries);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
for (const key of Object.keys(countQueryAttributs)) {
|
|
|
|
if (key === 'tags') {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
In(key, countQueryAttributs[key] as string[]),
|
|
|
|
);
|
|
|
|
} else if (key === 'description' || key === 'title') {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
ContainsString(key, countQueryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Eq(key, countQueryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'listAlert',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': _countSearchQuery['_and'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
body['query'].push(
|
2020-12-02 02:24:25 -08:00
|
|
|
{
|
2021-07-19 23:58:54 -07:00
|
|
|
'_name': 'count',
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
2021-07-19 23:58:54 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
qs.name = 'count-Alert';
|
|
|
|
|
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/v1/query',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { count: responseData };
|
|
|
|
}
|
2021-07-14 10:18:46 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'create') {
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as INodeParameters;
|
|
|
|
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
|
|
|
|
|
|
|
const customFields = await prepareCustomFields.call(this, additionalFields, jsonParameters);
|
|
|
|
const body: IDataObject = {
|
|
|
|
title: this.getNodeParameter('title', i),
|
|
|
|
description: this.getNodeParameter('description', i),
|
|
|
|
severity: this.getNodeParameter('severity', i),
|
|
|
|
date: Date.parse(this.getNodeParameter('date', i) as string),
|
|
|
|
tags: splitTags(this.getNodeParameter('tags', i) as string),
|
|
|
|
tlp: this.getNodeParameter('tlp', i),
|
|
|
|
status: this.getNodeParameter('status', i),
|
|
|
|
type: this.getNodeParameter('type', i),
|
|
|
|
source: this.getNodeParameter('source', i),
|
|
|
|
sourceRef: this.getNodeParameter('sourceRef', i),
|
|
|
|
follow: this.getNodeParameter('follow', i, true),
|
|
|
|
customFields,
|
|
|
|
...prepareOptional(additionalFields),
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const artifactUi = this.getNodeParameter('artifactUi', i) as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (artifactUi) {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const artifactValues = (artifactUi as IDataObject).artifactValues as IDataObject[];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (artifactValues) {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const artifactData = [];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
for (const artifactvalue of artifactValues) {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const element: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.message = artifactvalue.message as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.tags = (artifactvalue.tags as string).split(',') as string[];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.dataType = artifactvalue.dataType as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.data = artifactvalue.data as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (artifactvalue.dataType === 'file') {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const item = items[i];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const binaryPropertyName = artifactvalue.binaryProperty as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary[binaryPropertyName] === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), `No binary data property '${binaryPropertyName}' does not exists on item!`);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const binaryData = item.binary[binaryPropertyName] as IBinaryData;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
artifactData.push(element);
|
|
|
|
}
|
|
|
|
body.artifacts = artifactData;
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/alert' as string,
|
|
|
|
body,
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
/*
|
|
|
|
Execute responder feature differs from Cortex execute responder
|
|
|
|
if it doesn't interfere with n8n standards then we should keep it
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (operation === 'executeResponder') {
|
|
|
|
const alertId = this.getNodeParameter('id', i);
|
|
|
|
const responderId = this.getNodeParameter('responder', i) as string;
|
|
|
|
let body: IDataObject;
|
|
|
|
let response;
|
|
|
|
responseData = [];
|
|
|
|
body = {
|
|
|
|
responderId,
|
|
|
|
objectId: alertId,
|
|
|
|
objectType: 'alert',
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
2021-07-19 23:58:54 -07:00
|
|
|
'/connector/cortex/action' as string,
|
2020-12-02 02:24:25 -08:00
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
query: [
|
|
|
|
{
|
|
|
|
'_name': 'listAction',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': [
|
|
|
|
{
|
|
|
|
'_field': 'cortexId',
|
|
|
|
'_value': response.cortexId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'objectId',
|
|
|
|
'_value': response.objectId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'startDate',
|
|
|
|
'_value': response.startDate,
|
|
|
|
},
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
qs.name = 'log-actions';
|
|
|
|
do {
|
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/v1/query`,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} while (response.status === 'Waiting' || response.status === 'InProgress');
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = response;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'get') {
|
|
|
|
const alertId = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'GET',
|
|
|
|
`/alert/${alertId}`,
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (operation === 'getAll') {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const filters = this.getNodeParameter('filters', i, {}) as INodeParameters;
|
|
|
|
const queryAttributs: any = prepareOptional(filters); // tslint:disable-line:no-any
|
|
|
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const _searchQuery: IQueryObject = And();
|
2021-07-14 10:18:46 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if ('customFieldsUi' in filters) {
|
|
|
|
const customFields = await prepareCustomFields.call(this, filters) as IDataObject;
|
|
|
|
const searchQueries = buildCustomFieldSearch(customFields);
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(...searchQueries);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
for (const key of Object.keys(queryAttributs)) {
|
|
|
|
if (key === 'tags') {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
In(key, queryAttributs[key] as string[]),
|
|
|
|
);
|
|
|
|
} else if (key === 'description' || key === 'title') {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
ContainsString(key, queryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Eq(key, queryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let limit = undefined;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll === false) {
|
|
|
|
limit = this.getNodeParameter('limit', i) as number;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'listAlert',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': _searchQuery['_and'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
|
|
|
//@ts-ignore
|
2021-07-19 23:58:54 -07:00
|
|
|
prepareSortQuery(options.sort, body);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
//@ts-ignore
|
|
|
|
prepareRangeQuery(`0-${limit}`, body);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'alerts';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/alert/_search';
|
|
|
|
|
|
|
|
if (limit !== undefined) {
|
|
|
|
qs.range = `0-${limit}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
body.query = _searchQuery;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, prepareOptional(options));
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'markAsRead') {
|
|
|
|
const alertId = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/alert/${alertId}/markAsRead`,
|
|
|
|
);
|
|
|
|
}
|
2021-03-18 05:06:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'markAsUnread') {
|
|
|
|
const alertId = this.getNodeParameter('id', i) as string;
|
2021-03-18 05:06:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/alert/${alertId}/markAsUnread`,
|
|
|
|
);
|
|
|
|
}
|
2021-03-18 05:06:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'merge') {
|
|
|
|
const alertId = this.getNodeParameter('id', i) as string;
|
2021-03-18 05:06:51 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const caseId = this.getNodeParameter('caseId', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/alert/${alertId}/merge/${caseId}`,
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'promote') {
|
|
|
|
const alertId = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, additionalFields);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/alert/${alertId}/createCase`,
|
|
|
|
body,
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'update') {
|
|
|
|
const alertId = this.getNodeParameter('id', i) as string;
|
|
|
|
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
|
|
|
const customFields = await prepareCustomFields.call(this, updateFields, jsonParameters);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const artifactUi = updateFields.artifactUi as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
delete updateFields.artifactUi;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
customFields,
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(body, updateFields);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (artifactUi) {
|
|
|
|
const artifactValues = (artifactUi as IDataObject).artifactValues as IDataObject[];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (artifactValues) {
|
|
|
|
const artifactData = [];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
for (const artifactvalue of artifactValues) {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const element: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.message = artifactvalue.message as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.tags = (artifactvalue.tags as string).split(',') as string[];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.dataType = artifactvalue.dataType as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.data = artifactvalue.data as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (artifactvalue.dataType === 'file') {
|
|
|
|
const item = items[i];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const binaryPropertyName = artifactvalue.binaryProperty as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary[binaryPropertyName] === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), `No binary data property '${binaryPropertyName}' does not exists on item!`);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const binaryData = item.binary[binaryPropertyName] as IBinaryData;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
element.data = `${binaryData.fileName};${binaryData.mimeType};${binaryData.data}`;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
artifactData.push(element);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
body.artifacts = artifactData;
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PATCH',
|
|
|
|
`/alert/${alertId}` as string,
|
|
|
|
body,
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'observable') {
|
|
|
|
if (operation === 'count') {
|
|
|
|
const countQueryAttributs: any = prepareOptional(this.getNodeParameter('filters', i, {}) as INodeParameters); // tslint:disable-line:no-any
|
|
|
|
|
|
|
|
const _countSearchQuery: IQueryObject = And();
|
|
|
|
|
|
|
|
for (const key of Object.keys(countQueryAttributs)) {
|
|
|
|
if (key === 'dataType' || key === 'tags') {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
In(key, countQueryAttributs[key] as string[]),
|
|
|
|
);
|
|
|
|
} else if (key === 'description' || key === 'keywork' || key === 'message') {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
ContainsString(key, countQueryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
} else if (key === 'range') {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Between(
|
|
|
|
'startDate',
|
|
|
|
countQueryAttributs['range']['dateRange']['fromDate'],
|
|
|
|
countQueryAttributs['range']['dateRange']['toDate'],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Eq(key, countQueryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'listObservable',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': _countSearchQuery['_and'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
body['query'].push(
|
2020-12-02 02:24:25 -08:00
|
|
|
{
|
2021-07-19 23:58:54 -07:00
|
|
|
'_name': 'count',
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
2021-07-19 23:58:54 -07:00
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'count-observables';
|
|
|
|
|
|
|
|
responseData = await theHiveApiRequest.call(
|
2020-12-02 02:24:25 -08:00
|
|
|
this,
|
|
|
|
'POST',
|
2021-07-19 23:58:54 -07:00
|
|
|
'/v1/query',
|
2020-12-02 02:24:25 -08:00
|
|
|
body,
|
2020-12-02 02:54:10 -08:00
|
|
|
qs,
|
2020-12-02 02:24:25 -08:00
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
responseData = { count: responseData };
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'executeAnalyzer') {
|
|
|
|
const observableId = this.getNodeParameter('id', i);
|
|
|
|
const analyzers = (this.getNodeParameter('analyzers', i) as string[])
|
|
|
|
.map(analyzer => {
|
|
|
|
const parts = analyzer.split('::');
|
|
|
|
return {
|
|
|
|
analyzerId: parts[0],
|
|
|
|
cortexId: parts[1],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
let response: any; // tslint:disable-line:no-any
|
|
|
|
let body: IDataObject;
|
|
|
|
responseData = [];
|
|
|
|
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');
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'executeResponder') {
|
|
|
|
const observableId = this.getNodeParameter('id', i);
|
|
|
|
const responderId = this.getNodeParameter('responder', i) as string;
|
|
|
|
let body: IDataObject;
|
|
|
|
let response;
|
|
|
|
responseData = [];
|
|
|
|
body = {
|
|
|
|
responderId,
|
|
|
|
objectId: observableId,
|
|
|
|
objectType: 'case_artifact',
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
2021-07-19 23:58:54 -07:00
|
|
|
'/connector/cortex/action' as string,
|
2020-12-02 02:24:25 -08:00
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
query: [
|
|
|
|
{
|
|
|
|
'_name': 'listAction',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': [
|
|
|
|
{
|
|
|
|
'_field': 'cortexId',
|
|
|
|
'_value': response.cortexId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'objectId',
|
|
|
|
'_value': response.objectId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'startDate',
|
|
|
|
'_value': response.startDate,
|
|
|
|
},
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
qs.name = 'log-actions';
|
|
|
|
do {
|
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/v1/query`,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} while (response.status === 'Waiting' || response.status === 'InProgress');
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = response;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'create') {
|
|
|
|
const caseId = this.getNodeParameter('caseId', i);
|
|
|
|
|
|
|
|
let body: IDataObject = {
|
|
|
|
dataType: this.getNodeParameter('dataType', i) as string,
|
|
|
|
message: this.getNodeParameter('message', i) as string,
|
|
|
|
startDate: Date.parse(this.getNodeParameter('startDate', i) as string),
|
|
|
|
tlp: this.getNodeParameter('tlp', i) as number,
|
|
|
|
ioc: this.getNodeParameter('ioc', i) as boolean,
|
|
|
|
sighted: this.getNodeParameter('sighted', i) as boolean,
|
|
|
|
status: this.getNodeParameter('status', i) as string,
|
|
|
|
...prepareOptional(this.getNodeParameter('options', i, {}) as INodeParameters),
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let options: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (body.dataType === 'file') {
|
|
|
|
const item = items[i];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const binaryPropertyName = this.getNodeParameter('binaryProperty', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary[binaryPropertyName] === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), `No binary data property '${binaryPropertyName}' does not exists on item!`);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const binaryData = item.binary[binaryPropertyName] as IBinaryData;
|
2021-08-20 09:08:40 -07:00
|
|
|
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
options = {
|
|
|
|
formData: {
|
|
|
|
attachment: {
|
2021-08-20 09:08:40 -07:00
|
|
|
value: dataBuffer,
|
2021-07-19 23:58:54 -07:00
|
|
|
options: {
|
|
|
|
contentType: binaryData.mimeType,
|
|
|
|
filename: binaryData.fileName,
|
|
|
|
},
|
2020-12-02 02:54:10 -08:00
|
|
|
},
|
2021-07-19 23:58:54 -07:00
|
|
|
_json: JSON.stringify(body),
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
|
|
|
body = {};
|
|
|
|
} else {
|
|
|
|
body.data = this.getNodeParameter('data', i) as string;
|
|
|
|
}
|
|
|
|
|
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/case/${caseId}/artifact` as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
'',
|
|
|
|
options,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'get') {
|
|
|
|
const observableId = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'getObservable',
|
|
|
|
'idOrName': observableId,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = `get-observable-${observableId}`;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'GET';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `/case/artifact/${observableId}`;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'getAll') {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const caseId = this.getNodeParameter('caseId', i);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let limit = undefined;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll === false) {
|
|
|
|
limit = this.getNodeParameter('limit', i) as number;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'getCase',
|
|
|
|
'idOrName': caseId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'observables',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
//@ts-ignore
|
|
|
|
prepareSortQuery(options.sort, body);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
//@ts-ignore
|
|
|
|
prepareRangeQuery(`0-${limit}`, body);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'observables';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
|
|
|
method = 'POST';
|
|
|
|
|
|
|
|
endpoint = '/case/artifact/_search';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
qs.range = `0-${limit}`;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.query = Parent('case', Id(caseId as string));
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, prepareOptional(options));
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'search') {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
|
|
|
|
|
|
|
const version = credentials.apiVersion;
|
|
|
|
|
|
|
|
const queryAttributs: any = prepareOptional(this.getNodeParameter('filters', i, {}) as INodeParameters); // tslint:disable-line:no-any
|
|
|
|
|
|
|
|
const _searchQuery: IQueryObject = And();
|
|
|
|
|
|
|
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
|
|
|
|
|
|
|
for (const key of Object.keys(queryAttributs)) {
|
|
|
|
if (key === 'dataType' || key === 'tags') {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
In(key, queryAttributs[key] as string[]),
|
|
|
|
);
|
|
|
|
} else if (key === 'description' || key === 'keywork' || key === 'message') {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
ContainsString(key, queryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
} else if (key === 'range') {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Between(
|
|
|
|
'startDate',
|
|
|
|
queryAttributs['range']['dateRange']['fromDate'],
|
|
|
|
queryAttributs['range']['dateRange']['toDate'],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Eq(key, queryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let limit = undefined;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll === false) {
|
|
|
|
limit = this.getNodeParameter('limit', i) as number;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
|
|
|
|
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'listObservable',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': _searchQuery['_and'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
//@ts-ignore
|
|
|
|
prepareSortQuery(options.sort, body);
|
|
|
|
|
|
|
|
if (limit !== undefined) {
|
|
|
|
//@ts-ignore
|
|
|
|
prepareRangeQuery(`0-${limit}`, body);
|
|
|
|
}
|
|
|
|
|
|
|
|
qs.name = 'observables';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
|
|
|
} else {
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
|
|
|
|
|
|
|
endpoint = '/case/artifact/_search';
|
|
|
|
|
|
|
|
if (limit !== undefined) {
|
|
|
|
qs.range = `0-${limit}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
body.query = _searchQuery;
|
|
|
|
|
|
|
|
Object.assign(qs, prepareOptional(options));
|
|
|
|
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'update') {
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
...prepareOptional(this.getNodeParameter('updateFields', i, {}) as INodeParameters),
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PATCH',
|
|
|
|
`/case/artifact/${id}` as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { success: true };
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'case') {
|
|
|
|
if (operation === 'count') {
|
|
|
|
const filters = this.getNodeParameter('filters', i, {}) as INodeParameters;
|
|
|
|
const countQueryAttributs: any = prepareOptional(filters); // tslint:disable-line:no-any
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const _countSearchQuery: IQueryObject = And();
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if ('customFieldsUi' in filters) {
|
|
|
|
const customFields = await prepareCustomFields.call(this, filters) as IDataObject;
|
|
|
|
const searchQueries = buildCustomFieldSearch(customFields);
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(...searchQueries);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const key of Object.keys(countQueryAttributs)) {
|
|
|
|
if (key === 'tags') {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
In(key, countQueryAttributs[key] as string[]),
|
|
|
|
);
|
|
|
|
} else if (key === 'description' || key === 'summary' || key === 'title') {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
ContainsString(key, countQueryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Eq(key, countQueryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const body = {
|
2020-12-02 02:24:25 -08:00
|
|
|
'query': [
|
|
|
|
{
|
2021-07-19 23:58:54 -07:00
|
|
|
'_name': 'listCase',
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
2021-07-19 23:58:54 -07:00
|
|
|
'_and': _countSearchQuery['_and'],
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
2020-12-02 02:54:10 -08:00
|
|
|
],
|
2020-12-02 02:24:25 -08:00
|
|
|
};
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body['query'].push(
|
|
|
|
{
|
|
|
|
'_name': 'count',
|
|
|
|
},
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'count-cases';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/v1/query',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { count: responseData };
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'executeResponder') {
|
|
|
|
const caseId = this.getNodeParameter('id', i);
|
|
|
|
const responderId = this.getNodeParameter('responder', i) as string;
|
|
|
|
let body: IDataObject;
|
|
|
|
let response;
|
|
|
|
responseData = [];
|
|
|
|
body = {
|
|
|
|
responderId,
|
|
|
|
objectId: caseId,
|
|
|
|
objectType: 'case',
|
|
|
|
};
|
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/connector/cortex/action' as string,
|
|
|
|
body,
|
|
|
|
);
|
|
|
|
body = {
|
|
|
|
query: [
|
|
|
|
{
|
|
|
|
'_name': 'listAction',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': [
|
|
|
|
{
|
|
|
|
'_field': 'cortexId',
|
|
|
|
'_value': response.cortexId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'objectId',
|
|
|
|
'_value': response.objectId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'startDate',
|
|
|
|
'_value': response.startDate,
|
|
|
|
},
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
qs.name = 'log-actions';
|
|
|
|
do {
|
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/v1/query`,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} while (response.status === 'Waiting' || response.status === 'InProgress');
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = response;
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'create') {
|
|
|
|
const options = this.getNodeParameter('options', i, {}) as INodeParameters;
|
|
|
|
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
|
|
|
const customFields = await prepareCustomFields.call(this, options, jsonParameters);
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
title: this.getNodeParameter('title', i),
|
|
|
|
description: this.getNodeParameter('description', i),
|
|
|
|
severity: this.getNodeParameter('severity', i),
|
|
|
|
startDate: Date.parse(this.getNodeParameter('startDate', i) as string),
|
|
|
|
owner: this.getNodeParameter('owner', i),
|
|
|
|
flag: this.getNodeParameter('flag', i),
|
|
|
|
tlp: this.getNodeParameter('tlp', i),
|
|
|
|
tags: splitTags(this.getNodeParameter('tags', i) as string),
|
|
|
|
customFields,
|
|
|
|
...prepareOptional(options),
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/case' as string,
|
|
|
|
body,
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'get') {
|
|
|
|
const caseId = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2021-07-14 10:18:46 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'getCase',
|
|
|
|
'idOrName': caseId,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = `get-case-${caseId}`;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'GET';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `/case/${caseId}`;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
responseData = await theHiveApiRequest.call(
|
2020-12-02 02:24:25 -08:00
|
|
|
this,
|
2021-07-19 23:58:54 -07:00
|
|
|
method,
|
|
|
|
endpoint as string,
|
2020-12-02 02:24:25 -08:00
|
|
|
body,
|
2020-12-02 02:54:10 -08:00
|
|
|
qs,
|
2020-12-02 02:24:25 -08:00
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'getAll') {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const filters = this.getNodeParameter('filters', i, {}) as INodeParameters;
|
|
|
|
const queryAttributs: any = prepareOptional(filters); // tslint:disable-line:no-any
|
2021-12-23 04:30:35 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const _searchQuery: IQueryObject = And();
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if ('customFieldsUi' in filters) {
|
|
|
|
const customFields = await prepareCustomFields.call(this, filters) as IDataObject;
|
|
|
|
const searchQueries = buildCustomFieldSearch(customFields);
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(...searchQueries);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
for (const key of Object.keys(queryAttributs)) {
|
|
|
|
if (key === 'tags') {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
In(key, queryAttributs[key] as string[]),
|
|
|
|
);
|
|
|
|
} else if (key === 'description' || key === 'summary' || key === 'title') {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
ContainsString(key, queryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Eq(key, queryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let limit = undefined;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll === false) {
|
|
|
|
limit = this.getNodeParameter('limit', i) as number;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'listCase',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': _searchQuery['_and'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
//@ts-ignore
|
|
|
|
prepareSortQuery(options.sort, body);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
//@ts-ignore
|
|
|
|
prepareRangeQuery(`0-${limit}`, body);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'cases';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/case/_search';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
qs.range = `0-${limit}`;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.query = _searchQuery;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, prepareOptional(options));
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2021-07-14 10:18:46 -07:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'update') {
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
|
|
|
const updateFields = this.getNodeParameter('updateFields', i, {}) as INodeParameters;
|
|
|
|
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
|
|
|
|
|
|
|
const customFields = await prepareCustomFields.call(this, updateFields, jsonParameters);
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
customFields,
|
|
|
|
...prepareOptional(updateFields),
|
|
|
|
};
|
|
|
|
|
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PATCH',
|
|
|
|
`/case/${id}` as string,
|
|
|
|
body,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'task') {
|
|
|
|
if (operation === 'count') {
|
|
|
|
const countQueryAttributs: any = prepareOptional(this.getNodeParameter('filters', i, {}) as INodeParameters); // tslint:disable-line:no-any
|
|
|
|
|
|
|
|
const _countSearchQuery: IQueryObject = And();
|
|
|
|
|
|
|
|
for (const key of Object.keys(countQueryAttributs)) {
|
|
|
|
if (key === 'title' || key === 'description') {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
ContainsString(key, countQueryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
(_countSearchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Eq(key, countQueryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'listTask',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': _countSearchQuery['_and'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body['query'].push(
|
|
|
|
{
|
|
|
|
'_name': 'count',
|
|
|
|
},
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'count-tasks';
|
|
|
|
|
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/v1/query',
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = { count: responseData };
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'create') {
|
|
|
|
const caseId = this.getNodeParameter('caseId', i) as string;
|
|
|
|
|
|
|
|
const body: IDataObject = {
|
|
|
|
title: this.getNodeParameter('title', i) as string,
|
|
|
|
status: this.getNodeParameter('status', i) as string,
|
|
|
|
flag: this.getNodeParameter('flag', i),
|
|
|
|
...prepareOptional(this.getNodeParameter('options', i, {}) as INodeParameters),
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/case/${caseId}/task` as string,
|
|
|
|
body,
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'executeResponder') {
|
|
|
|
const taskId = this.getNodeParameter('id', i);
|
|
|
|
const responderId = this.getNodeParameter('responder', i) as string;
|
|
|
|
let body: IDataObject;
|
|
|
|
let response;
|
|
|
|
responseData = [];
|
|
|
|
body = {
|
|
|
|
responderId,
|
|
|
|
objectId: taskId,
|
|
|
|
objectType: 'case_task',
|
|
|
|
};
|
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
'/connector/cortex/action' as string,
|
|
|
|
body,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
body = {
|
2021-07-19 23:58:54 -07:00
|
|
|
query: [
|
2020-12-02 02:24:25 -08:00
|
|
|
{
|
2021-07-19 23:58:54 -07:00
|
|
|
'_name': 'listAction',
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
2021-07-19 23:58:54 -07:00
|
|
|
'_and': [
|
|
|
|
{
|
|
|
|
'_field': 'cortexId',
|
|
|
|
'_value': response.cortexId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'objectId',
|
|
|
|
'_value': response.objectId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'startDate',
|
|
|
|
'_value': response.startDate,
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
2020-12-02 02:54:10 -08:00
|
|
|
],
|
2020-12-02 02:24:25 -08:00
|
|
|
};
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'task-actions';
|
|
|
|
do {
|
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/v1/query`,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} while (response.status === 'Waiting' || response.status === 'InProgress');
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = response;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'get') {
|
|
|
|
const taskId = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2021-07-14 10:18:46 -07:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'getTask',
|
|
|
|
'idOrName': taskId,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = `get-task-${taskId}`;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
|
|
|
} else {
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'GET';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = `/case/task/${taskId}`;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:54:10 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
2020-12-02 02:24:25 -08:00
|
|
|
this,
|
2021-07-19 23:58:54 -07:00
|
|
|
method,
|
|
|
|
endpoint as string,
|
2020-12-02 02:24:25 -08:00
|
|
|
body,
|
2020-12-02 02:54:10 -08:00
|
|
|
qs,
|
2020-12-02 02:24:25 -08:00
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'getAll') {
|
|
|
|
// get all require a case id (it retursn all tasks for a specific case)
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const caseId = this.getNodeParameter('caseId', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let limit = undefined;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll === false) {
|
|
|
|
limit = this.getNodeParameter('limit', i) as number;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'getCase',
|
|
|
|
'idOrName': caseId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'tasks',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
//@ts-ignore
|
|
|
|
prepareSortQuery(options.sort, body);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
//@ts-ignore
|
|
|
|
prepareRangeQuery(`0-${limit}`, body);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'case-tasks';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/case/task/_search';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
qs.range = `0-${limit}`;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.query = And(Parent('case', Id(caseId)));
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, prepareOptional(options));
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'search') {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const queryAttributs: any = prepareOptional(this.getNodeParameter('filters', i, {}) as INodeParameters); // tslint:disable-line:no-any
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const _searchQuery: IQueryObject = And();
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const options = this.getNodeParameter('options', i) as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
for (const key of Object.keys(queryAttributs)) {
|
|
|
|
if (key === 'title' || key === 'description') {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
ContainsString(key, queryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
(_searchQuery['_and'] as IQueryObject[]).push(
|
|
|
|
Eq(key, queryAttributs[key] as string),
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let limit = undefined;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll === false) {
|
|
|
|
limit = this.getNodeParameter('limit', i) as number;
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'listTask',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': _searchQuery['_and'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
//@ts-ignore
|
|
|
|
prepareSortQuery(options.sort, body);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
//@ts-ignore
|
|
|
|
prepareRangeQuery(`0-${limit}`, body);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'tasks';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/case/task/_search';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
qs.range = `0-${limit}`;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.query = _searchQuery;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
Object.assign(qs, prepareOptional(options));
|
2020-12-02 02:24:25 -08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'update') {
|
|
|
|
const id = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const body: IDataObject = {
|
|
|
|
...prepareOptional(this.getNodeParameter('updateFields', i, {}) as INodeParameters),
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'PATCH',
|
|
|
|
`/case/task/${id}` as string,
|
|
|
|
body,
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (resource === 'log') {
|
|
|
|
if (operation === 'create') {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const taskId = this.getNodeParameter('taskId', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {
|
|
|
|
message: this.getNodeParameter('message', i),
|
|
|
|
startDate: Date.parse(this.getNodeParameter('startDate', i) as string),
|
|
|
|
status: this.getNodeParameter('status', i),
|
|
|
|
};
|
|
|
|
const optionals = this.getNodeParameter('options', i) as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let options: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (optionals.attachementUi) {
|
|
|
|
const attachmentValues = (optionals.attachementUi as IDataObject).attachmentValues as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (attachmentValues) {
|
|
|
|
const item = items[i];
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!');
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const binaryPropertyName = attachmentValues.binaryProperty as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (item.binary[binaryPropertyName] === undefined) {
|
|
|
|
throw new NodeOperationError(this.getNode(), `No binary data property '${binaryPropertyName}' does not exists on item!`);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const binaryData = item.binary[binaryPropertyName] as IBinaryData;
|
2021-08-20 09:08:40 -07:00
|
|
|
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
options = {
|
|
|
|
formData: {
|
|
|
|
attachment: {
|
2021-08-20 09:08:40 -07:00
|
|
|
value: dataBuffer,
|
2021-07-19 23:58:54 -07:00
|
|
|
options: {
|
|
|
|
contentType: binaryData.mimeType,
|
|
|
|
filename: binaryData.fileName,
|
|
|
|
},
|
2020-12-02 02:54:10 -08:00
|
|
|
},
|
2021-07-19 23:58:54 -07:00
|
|
|
_json: JSON.stringify(body),
|
2020-12-02 02:24:25 -08:00
|
|
|
},
|
2021-07-19 23:58:54 -07:00
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {};
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/case/task/${taskId}/log` as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
'',
|
|
|
|
options,
|
|
|
|
);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'executeResponder') {
|
|
|
|
const logId = this.getNodeParameter('id', i);
|
|
|
|
const responderId = this.getNodeParameter('responder', i) as string;
|
|
|
|
let body: IDataObject;
|
|
|
|
let response;
|
|
|
|
responseData = [];
|
|
|
|
body = {
|
|
|
|
responderId,
|
|
|
|
objectId: logId,
|
|
|
|
objectType: 'case_task_log',
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
2021-07-19 23:58:54 -07:00
|
|
|
'/connector/cortex/action' as string,
|
2020-12-02 02:24:25 -08:00
|
|
|
body,
|
|
|
|
);
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
query: [
|
|
|
|
{
|
|
|
|
'_name': 'listAction',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'filter',
|
|
|
|
'_and': [
|
|
|
|
{
|
|
|
|
'_field': 'cortexId',
|
|
|
|
'_value': response.cortexId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'objectId',
|
|
|
|
'_value': response.objectId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_field': 'startDate',
|
|
|
|
'_value': response.startDate,
|
|
|
|
},
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
qs.name = 'log-actions';
|
|
|
|
do {
|
|
|
|
response = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
'POST',
|
|
|
|
`/v1/query`,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
|
|
|
} while (response.status === 'Waiting' || response.status === 'InProgress');
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = response;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'get') {
|
|
|
|
const logId = this.getNodeParameter('id', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
|
|
|
|
|
|
|
body = {
|
|
|
|
query: [
|
|
|
|
{
|
|
|
|
_name: 'getLog',
|
|
|
|
idOrName: logId,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
qs.name = `get-log-${logId}`;
|
|
|
|
} else {
|
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/case/task/log/_search';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.query = { _id: logId };
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (operation === 'getAll') {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('theHiveApi') as IDataObject;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const version = credentials.apiVersion;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
const taskId = this.getNodeParameter('taskId', i) as string;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let endpoint;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let method;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let body: IDataObject = {};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
let limit = undefined;
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (returnAll === false) {
|
|
|
|
limit = this.getNodeParameter('limit', i) as number;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (version === 'v1') {
|
|
|
|
endpoint = '/v1/query';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body = {
|
|
|
|
'query': [
|
|
|
|
{
|
|
|
|
'_name': 'getTask',
|
|
|
|
'idOrName': taskId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'_name': 'logs',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
//@ts-ignore
|
|
|
|
prepareRangeQuery(`0-${limit}`, body);
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
qs.name = 'case-task-logs';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else {
|
|
|
|
method = 'POST';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
endpoint = '/case/task/log/_search';
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (limit !== undefined) {
|
|
|
|
qs.range = `0-${limit}`;
|
|
|
|
}
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
body.query = And(Parent(
|
|
|
|
'task',
|
|
|
|
Id(taskId),
|
|
|
|
));
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
responseData = await theHiveApiRequest.call(
|
|
|
|
this,
|
|
|
|
method,
|
|
|
|
endpoint as string,
|
|
|
|
body,
|
|
|
|
qs,
|
|
|
|
);
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
if (Array.isArray(responseData)) {
|
|
|
|
returnData.push.apply(returnData, responseData as IDataObject[]);
|
2020-12-02 02:24:25 -08:00
|
|
|
|
2021-07-19 23:58:54 -07:00
|
|
|
} else if (responseData !== undefined) {
|
|
|
|
returnData.push(responseData as IDataObject);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
if (this.continueOnFail()) {
|
|
|
|
returnData.push({ error: error.message });
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
throw error;
|
2020-12-02 02:24:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|