🐛 Fix run deck node (#2285)

This commit is contained in:
Omar Ajoue 2021-10-06 20:14:53 +02:00 committed by GitHub
parent a5e714f1c4
commit 3fe5a2ddff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View file

@ -163,9 +163,11 @@ export class Rundeck implements INodeType {
const operation = this.getNodeParameter('operation', 0) as string;
const resource = this.getNodeParameter('resource', 0) as string;
const rundeckApi = new RundeckApi(this);
await rundeckApi.init();
for (let i = 0; i < length; i++) {
const rundeckApi = new RundeckApi(this);
if (resource === 'job') {
if (operation === 'execute') {

View file

@ -8,20 +8,12 @@ export interface RundeckCredentials {
}
export class RundeckApi {
private credentials: RundeckCredentials;
private credentials?: RundeckCredentials;
private executeFunctions: IExecuteFunctions;
constructor(executeFunctions: IExecuteFunctions) {
const credentials = executeFunctions.getCredentials('rundeckApi');
this.executeFunctions = executeFunctions;
if (credentials === undefined) {
throw new NodeOperationError(this.executeFunctions.getNode(), 'No credentials got returned!');
}
this.credentials = credentials as unknown as RundeckCredentials;
}
@ -30,12 +22,12 @@ export class RundeckApi {
const options: OptionsWithUri = {
headers: {
'user-agent': 'n8n',
'X-Rundeck-Auth-Token': this.credentials.token,
'X-Rundeck-Auth-Token': this.credentials?.token,
},
rejectUnauthorized: false,
method,
qs: query,
uri: this.credentials.url + endpoint,
uri: this.credentials?.url + endpoint,
body,
json: true,
};
@ -47,6 +39,15 @@ export class RundeckApi {
}
}
async init() {
const credentials = await this.executeFunctions.getCredentials('rundeckApi');
if (credentials === undefined) {
throw new NodeOperationError(this.executeFunctions.getNode(), 'No credentials got returned!');
}
this.credentials = credentials as unknown as RundeckCredentials;
}
executeJob(jobId: string, args: IDataObject[]): Promise<IDataObject> {