feat(MISP Node): Rest search operations (#9196)

This commit is contained in:
Michael Kret
2024-04-26 11:12:22 +03:00
committed by GitHub
parent 9b3ac1648f
commit b694e7743e
7 changed files with 270 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ import type {
IHttpRequestMethods,
IRequestOptions,
} from 'n8n-workflow';
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
import { NodeApiError, NodeOperationError, jsonParse } from 'n8n-workflow';
import type { MispCredentials } from './types';
@@ -79,6 +79,57 @@ export async function mispApiRequestAllItems(this: IExecuteFunctions, endpoint:
return responseData;
}
export async function mispApiRestSearch(
this: IExecuteFunctions,
resource: 'attributes' | 'events' | 'objects',
itemIndex: number,
) {
let body: IDataObject = {};
const useJson = this.getNodeParameter('useJson', itemIndex) as boolean;
if (useJson) {
const json = this.getNodeParameter('jsonOutput', itemIndex);
if (typeof json === 'string') {
body = jsonParse(json);
} else {
body = json as IDataObject;
}
} else {
const value = this.getNodeParameter('value', itemIndex) as string;
const additionalFields = this.getNodeParameter('additionalFields', itemIndex);
body.value = value;
if (Object.keys(additionalFields).length) {
if (additionalFields.tags) {
additionalFields.tags = (additionalFields.tags as string)
.split(',')
.map((tag) => tag.trim());
}
Object.assign(body, additionalFields);
}
}
const endpoint = `/${resource}/restSearch`;
const { response } = await mispApiRequest.call(this, 'POST', endpoint, body);
if (response) {
if (resource === 'attributes') {
return response.Attribute;
}
if (resource === 'events') {
return (response as IDataObject[]).map((event) => event.Event);
}
if (resource === 'objects') {
return (response as IDataObject[]).map((obj) => obj.Object);
}
} else {
return [];
}
}
export function throwOnEmptyUpdate(
this: IExecuteFunctions,
resource: string,