diff --git a/packages/nodes-base/nodes/Rundeck/Api.ts b/packages/nodes-base/nodes/Rundeck/Api.ts index 28f64c9d347..deac944ec1d 100644 --- a/packages/nodes-base/nodes/Rundeck/Api.ts +++ b/packages/nodes-base/nodes/Rundeck/Api.ts @@ -1,44 +1,44 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios"; export class Api { - private api: AxiosInstance; + private api: AxiosInstance; - constructor (config: AxiosRequestConfig) { - this.api = axios.create(config); - this.api.interceptors.request.use((param: AxiosRequestConfig) => ({ - ...param - })); - } + constructor (config: AxiosRequestConfig) { + this.api = axios.create(config); + this.api.interceptors.request.use((param: AxiosRequestConfig) => ({ + ...param + })); + } + + protected getUri (config?: AxiosRequestConfig): string { + return this.api.getUri(config); + } + + protected request> (config: AxiosRequestConfig): Promise { + return this.api.request(config); + } - protected getUri (config?: AxiosRequestConfig): string { - return this.api.getUri(config); - } + protected get> (url: string, config?: AxiosRequestConfig): Promise { + return this.api.get(url, config); + } - protected request> (config: AxiosRequestConfig): Promise { - return this.api.request(config); - } + protected delete> (url: string, config?: AxiosRequestConfig): Promise { + return this.api.delete(url, config); + } - protected get> (url: string, config?: AxiosRequestConfig): Promise { - return this.api.get(url, config); - } + protected head> (url: string, config?: AxiosRequestConfig): Promise { + return this.api.head(url, config); + } - protected delete> (url: string, config?: AxiosRequestConfig): Promise { - return this.api.delete(url, config); - } + protected post> (url: string, data?: string, config?: AxiosRequestConfig): Promise { + return this.api.post(url, data, config); + } - protected head> (url: string, config?: AxiosRequestConfig): Promise { - return this.api.head(url, config); - } + protected put> (url: string, data?: string, config?: AxiosRequestConfig): Promise { + return this.api.put(url, data, config); + } - protected post> (url: string, data?: string, config?: AxiosRequestConfig): Promise { - return this.api.post(url, data, config); - } - - protected put> (url: string, data?: string, config?: AxiosRequestConfig): Promise { - return this.api.put(url, data, config); - } - - protected patch> (url: string, data?: string, config?: AxiosRequestConfig): Promise { - return this.api.patch(url, data, config); - } + protected patch> (url: string, data?: string, config?: AxiosRequestConfig): Promise { + return this.api.patch(url, data, config); + } } \ No newline at end of file diff --git a/packages/nodes-base/nodes/Rundeck/RundeckApi.ts b/packages/nodes-base/nodes/Rundeck/RundeckApi.ts index 137ed2bd571..23edf71f7ec 100644 --- a/packages/nodes-base/nodes/Rundeck/RundeckApi.ts +++ b/packages/nodes-base/nodes/Rundeck/RundeckApi.ts @@ -5,59 +5,59 @@ import { Xml } from "../Xml.node"; import { IDataObject } from "n8n-workflow"; export interface RundeckCredentials { - url: string; - apiVersion: number; - token: string; + url: string; + apiVersion: number; + token: string; } function acceptVersion(credentialsApiVersion: number, apiVersion: number) { - if(apiVersion > credentialsApiVersion) { - throw Error('This endpoint is not supported for this version!'); - } + if(apiVersion > credentialsApiVersion) { + throw Error('This endpoint is not supported for this version!'); + } } export class RundeckApi extends Api { + + private credentials: RundeckCredentials; - private credentials: RundeckCredentials; + constructor (credentials: RundeckCredentials) { - constructor (credentials: RundeckCredentials) { + const config: AxiosRequestConfig = { + httpsAgent: new https.Agent({ + rejectUnauthorized: false + }), + headers: { + 'Accept': 'application/xml', + 'user-agent': 'n8n', + 'X-Rundeck-Auth-Token': credentials.token, + } + }; - const config: AxiosRequestConfig = { - httpsAgent: new https.Agent({ - rejectUnauthorized: false - }), - headers: { - 'Accept': 'application/xml', - 'user-agent': 'n8n', - 'X-Rundeck-Auth-Token': credentials.token, - } - }; - - super(config); - this.credentials = credentials; + super(config); + this.credentials = credentials; - } + } - executeJob(jobId: string, args: IDataObject[]): Promise { + executeJob(jobId: string, args: IDataObject[]): Promise { - acceptVersion(this.credentials.apiVersion, 12); + acceptVersion(this.credentials.apiVersion, 12); - let params = ''; + let params = ''; - if(args) { - for(const arg of args) { - params += "-" + arg.name + " " + arg.value + " "; - } - } - - return this.post(this.credentials.url + '/api/12/job/' + jobId + '/run?argString=' + params) - .then((response: AxiosResponse) => { - const { data } = response; - return data; - }) - .catch((error: AxiosError) => { - throw error; - }); - } + if(args) { + for(const arg of args) { + params += "-" + arg.name + " " + arg.value + " "; + } + } + + return this.post(this.credentials.url + '/api/12/job/' + jobId + '/run?argString=' + params) + .then((response: AxiosResponse) => { + const { data } = response; + return data; + }) + .catch((error: AxiosError) => { + throw error; + }); + } } \ No newline at end of file