Fetch observable data types from TheHive (#1291)

This commit is contained in:
Mika Luhta 2021-04-05 11:52:56 +03:00 committed by GitHub
parent cf73387214
commit 1d10cc6f25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 145 deletions

View file

@ -195,6 +195,50 @@ export class TheHive implements INodeType {
];
return options;
},
async loadObservableTypes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
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<INodePropertyOptions[]> {
const version = this.getCredentials('theHiveApi')?.apiVersion;
const options = [

View file

@ -387,21 +387,10 @@ export const alertFields = [
name: 'dataType',
type: 'options',
default: '',
options: [
{
name: 'IP',
value: 'ip',
typeOptions: {
loadOptionsMethod: 'loadObservableTypes',
},
{
name: 'Domain',
value: 'domain',
},
{
name: 'File',
value: 'file',
},
],
description: '',
description: 'Type of the observable',
},
{
displayName: 'Data',
@ -545,20 +534,10 @@ export const alertFields = [
name: 'dataType',
type: 'options',
default: '',
options: [
{
name: 'IP',
value: 'ip',
typeOptions: {
loadOptionsMethod: 'loadObservableTypes',
},
{
name: 'Domain',
value: 'domain',
},
{
name: 'File',
value: 'file',
},
],
description: 'Type of the observable',
},
{
displayName: 'Data',

View file

@ -120,64 +120,9 @@ export const observableFields = [
type: 'options',
required: true,
default: '',
options: [
{
name: 'domain',
value: 'domain',
typeOptions: {
loadOptionsMethod: 'loadObservableTypes',
},
{
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',
},
],
displayOptions: {
show: {
resource: [
@ -604,64 +549,9 @@ export const observableFields = [
name: 'dataType',
type: 'multiOptions',
default: [],
options: [
{
name: 'domain',
value: 'domain',
typeOptions: {
loadOptionsMethod: 'loadObservableTypes',
},
{
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',
},
],
description: 'Type of the observable',
},
{