Skip to content

Commit

Permalink
feat(MISP Node): Update credential to support HTTP Request node (#7268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joffcom authored Sep 27, 2023
1 parent 6d7fe95 commit e4c302c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
24 changes: 23 additions & 1 deletion packages/nodes-base/credentials/MispApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ICredentialType, INodeProperties } from 'n8n-workflow';
import type {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';

export class MispApi implements ICredentialType {
name = 'mispApi';
Expand Down Expand Up @@ -29,4 +34,21 @@ export class MispApi implements ICredentialType {
default: false,
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '={{$credentials.apiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials.baseUrl.replace(new RegExp("/$"), "")}}',
url: '/tags',
skipSslCertificateValidation: '={{$credentials.allowUnauthorizedCerts}}',
},
};
}
7 changes: 2 additions & 5 deletions packages/nodes-base/nodes/Misp/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ export async function mispApiRequest(
body: IDataObject = {},
qs: IDataObject = {},
) {
const { baseUrl, apiKey, allowUnauthorizedCerts } = (await this.getCredentials(
const { baseUrl, allowUnauthorizedCerts } = (await this.getCredentials(
'mispApi',
)) as MispCredentials;

const options: OptionsWithUri = {
headers: {
Authorization: apiKey,
},
method,
body,
qs,
Expand All @@ -44,7 +41,7 @@ export async function mispApiRequest(
}

try {
return await this.helpers.request(options);
return await this.helpers.requestWithAuthentication.call(this, 'mispApi', options);
} catch (error) {
// MISP API wrongly returns 403 for malformed requests
if (error.statusCode === 403) {
Expand Down

0 comments on commit e4c302c

Please sign in to comment.