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
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 = [