From fc876501809f5af0c7456867eae99f64b9ed653e Mon Sep 17 00:00:00 2001 From: AndLLA <44858649+AndLLA@users.noreply.github.com> Date: Sun, 16 Oct 2022 15:26:31 +0200 Subject: [PATCH] feat(Rundeck Node): Update credential with test and make useable in HTTP Request node (#3879) * add support for authenticate, test to RundeckApi Credentials * ensure that the RunDeckApi note uses the authentication mechanism defined incredentials --- .../credentials/RundeckApi.credentials.ts | 25 ++++++++++++++++++- .../nodes-base/nodes/Rundeck/RundeckApi.ts | 12 +++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/nodes-base/credentials/RundeckApi.credentials.ts b/packages/nodes-base/credentials/RundeckApi.credentials.ts index 719eea40bb..9cd4b3ffc1 100644 --- a/packages/nodes-base/credentials/RundeckApi.credentials.ts +++ b/packages/nodes-base/credentials/RundeckApi.credentials.ts @@ -1,4 +1,9 @@ -import { ICredentialType, INodeProperties } from 'n8n-workflow'; +import { + IAuthenticateGeneric, + ICredentialTestRequest, + ICredentialType, + INodeProperties, +} from 'n8n-workflow'; export class RundeckApi implements ICredentialType { name = 'rundeckApi'; @@ -19,4 +24,22 @@ export class RundeckApi implements ICredentialType { default: '', }, ]; + + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + 'user-agent': 'n8n', + 'X-Rundeck-Auth-Token': '={{$credentials?.token}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials.url}}', + url: '/api/14/system/info', + method: 'GET', + }, + }; } diff --git a/packages/nodes-base/nodes/Rundeck/RundeckApi.ts b/packages/nodes-base/nodes/Rundeck/RundeckApi.ts index bf13cec76a..59a47bd8f3 100644 --- a/packages/nodes-base/nodes/Rundeck/RundeckApi.ts +++ b/packages/nodes-base/nodes/Rundeck/RundeckApi.ts @@ -16,11 +16,9 @@ export class RundeckApi { } protected async request(method: string, endpoint: string, body: IDataObject, query: object) { + const credentialType = 'rundeckApi'; + const options: OptionsWithUri = { - headers: { - 'user-agent': 'n8n', - 'X-Rundeck-Auth-Token': this.credentials?.token, - }, rejectUnauthorized: false, method, qs: query, @@ -30,7 +28,11 @@ export class RundeckApi { }; try { - return await this.executeFunctions.helpers.request!(options); + return await this.executeFunctions.helpers.requestWithAuthentication.call( + this.executeFunctions, + credentialType, + options, + ); } catch (error) { throw new NodeApiError(this.executeFunctions.getNode(), error); }