Skip to content

Commit

Permalink
feat(Rundeck Node): Update credential with test and make useable in H…
Browse files Browse the repository at this point in the history
…TTP Request node (#3879)

* add support for authenticate, test to RundeckApi Credentials

* ensure that the RunDeckApi note uses the authentication mechanism
defined incredentials
  • Loading branch information
AndLLA committed Oct 16, 2022
1 parent b67e41b commit fc87650
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
25 changes: 24 additions & 1 deletion packages/nodes-base/credentials/RundeckApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
},
};
}
12 changes: 7 additions & 5 deletions packages/nodes-base/nodes/Rundeck/RundeckApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down

0 comments on commit fc87650

Please sign in to comment.