From 1d10cc6f2578ec490f4885f61dc3c467847731d5 Mon Sep 17 00:00:00 2001 From: Mika Luhta <12100880+mluhta@users.noreply.github.com> Date: Mon, 5 Apr 2021 11:52:56 +0300 Subject: [PATCH] :zap: Fetch observable data types from TheHive (#1291) --- .../nodes-base/nodes/TheHive/TheHive.node.ts | 44 +++++++ .../TheHive/descriptions/AlertDescription.ts | 37 ++---- .../descriptions/ObservableDescription.ts | 122 +----------------- 3 files changed, 58 insertions(+), 145 deletions(-) diff --git a/packages/nodes-base/nodes/TheHive/TheHive.node.ts b/packages/nodes-base/nodes/TheHive/TheHive.node.ts index b41a50c40a..dc40862a62 100644 --- a/packages/nodes-base/nodes/TheHive/TheHive.node.ts +++ b/packages/nodes-base/nodes/TheHive/TheHive.node.ts @@ -195,6 +195,50 @@ export class TheHive implements INodeType { ]; return options; }, + async loadObservableTypes(this: ILoadOptionsFunctions): Promise { + const version = this.getCredentials('theHiveApi')?.apiVersion; + const endpoint = version === 'v1' ? '/observable/type?range=all' : '/list/list_artifactDataType'; + + const dataTypes = await theHiveApiRequest.call( + this, + 'GET', + endpoint as string, + ); + + 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; + + 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; + }, async loadTaskOptions(this: ILoadOptionsFunctions): Promise { const version = this.getCredentials('theHiveApi')?.apiVersion; const options = [ diff --git a/packages/nodes-base/nodes/TheHive/descriptions/AlertDescription.ts b/packages/nodes-base/nodes/TheHive/descriptions/AlertDescription.ts index 551c68ec02..1c607305eb 100644 --- a/packages/nodes-base/nodes/TheHive/descriptions/AlertDescription.ts +++ b/packages/nodes-base/nodes/TheHive/descriptions/AlertDescription.ts @@ -387,21 +387,10 @@ export const alertFields = [ name: 'dataType', type: 'options', default: '', - options: [ - { - name: 'IP', - value: 'ip', - }, - { - name: 'Domain', - value: 'domain', - }, - { - name: 'File', - value: 'file', - }, - ], - description: '', + typeOptions: { + loadOptionsMethod: 'loadObservableTypes', + }, + description: 'Type of the observable', }, { displayName: 'Data', @@ -545,20 +534,10 @@ export const alertFields = [ name: 'dataType', type: 'options', default: '', - options: [ - { - name: 'IP', - value: 'ip', - }, - { - name: 'Domain', - value: 'domain', - }, - { - name: 'File', - value: 'file', - }, - ], + typeOptions: { + loadOptionsMethod: 'loadObservableTypes', + }, + description: 'Type of the observable', }, { displayName: 'Data', diff --git a/packages/nodes-base/nodes/TheHive/descriptions/ObservableDescription.ts b/packages/nodes-base/nodes/TheHive/descriptions/ObservableDescription.ts index 12aa6e9478..9c2386569e 100644 --- a/packages/nodes-base/nodes/TheHive/descriptions/ObservableDescription.ts +++ b/packages/nodes-base/nodes/TheHive/descriptions/ObservableDescription.ts @@ -120,64 +120,9 @@ export const observableFields = [ type: 'options', required: true, default: '', - options: [ - { - name: 'domain', - value: 'domain', - }, - { - name: 'file', - value: 'file', - }, - { - name: 'filename', - value: 'filename', - }, - { - name: 'fqdn', - value: 'fqdn', - }, - { - name: 'hash', - value: 'hash', - }, - { - name: 'ip', - value: 'ip', - }, - { - name: 'mail', - value: 'mail', - }, - { - name: 'mail_subject', - value: 'mail_subject', - }, - { - name: 'other', - value: 'other', - }, - { - name: 'regexp', - value: 'regexp', - }, - { - name: 'registry', - value: 'registry', - }, - { - name: 'uri_path', - value: 'uri_path', - }, - { - name: 'url', - value: 'url', - }, - { - name: 'user-agent', - value: 'user-agent', - }, - ], + typeOptions: { + loadOptionsMethod: 'loadObservableTypes', + }, displayOptions: { show: { resource: [ @@ -604,64 +549,9 @@ export const observableFields = [ name: 'dataType', type: 'multiOptions', default: [], - options: [ - { - name: 'domain', - value: 'domain', - }, - { - name: 'file', - value: 'file', - }, - { - name: 'filename', - value: 'filename', - }, - { - name: 'fqdn', - value: 'fqdn', - }, - { - name: 'hash', - value: 'hash', - }, - { - name: 'ip', - value: 'ip', - }, - { - name: 'mail', - value: 'mail', - }, - { - name: 'mail_subject', - value: 'mail_subject', - }, - { - name: 'other', - value: 'other', - }, - { - name: 'regexp', - value: 'regexp', - }, - { - name: 'registry', - value: 'registry', - }, - { - name: 'uri_path', - value: 'uri_path', - }, - { - name: 'url', - value: 'url', - }, - { - name: 'user-agent', - value: 'user-agent', - }, - ], + typeOptions: { + loadOptionsMethod: 'loadObservableTypes', + }, description: 'Type of the observable', }, {