mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -08:00
Change spaces for tabs
This commit is contained in:
parent
af2b6bbef4
commit
77fe157105
|
@ -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<T, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.request(config);
|
||||
}
|
||||
|
||||
protected getUri (config?: AxiosRequestConfig): string {
|
||||
return this.api.getUri(config);
|
||||
}
|
||||
protected get<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.get(url, config);
|
||||
}
|
||||
|
||||
protected request<T, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.request(config);
|
||||
}
|
||||
protected delete<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.delete(url, config);
|
||||
}
|
||||
|
||||
protected get<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.get(url, config);
|
||||
}
|
||||
protected head<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.head(url, config);
|
||||
}
|
||||
|
||||
protected delete<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.delete(url, config);
|
||||
}
|
||||
protected post<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.post(url, data, config);
|
||||
}
|
||||
|
||||
protected head<T, R = AxiosResponse<T>> (url: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.head(url, config);
|
||||
}
|
||||
protected put<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.put(url, data, config);
|
||||
}
|
||||
|
||||
protected post<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.post(url, data, config);
|
||||
}
|
||||
|
||||
protected put<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.put(url, data, config);
|
||||
}
|
||||
|
||||
protected patch<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.patch(url, data, config);
|
||||
}
|
||||
protected patch<T, R = AxiosResponse<T>> (url: string, data?: string, config?: AxiosRequestConfig): Promise<R> {
|
||||
return this.api.patch(url, data, config);
|
||||
}
|
||||
}
|
|
@ -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<Xml> {
|
||||
executeJob(jobId: string, args: IDataObject[]): Promise<Xml> {
|
||||
|
||||
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<Xml>(this.credentials.url + '/api/12/job/' + jobId + '/run?argString=' + params)
|
||||
.then((response: AxiosResponse<Xml>) => {
|
||||
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<Xml>(this.credentials.url + '/api/12/job/' + jobId + '/run?argString=' + params)
|
||||
.then((response: AxiosResponse<Xml>) => {
|
||||
const { data } = response;
|
||||
return data;
|
||||
})
|
||||
.catch((error: AxiosError) => {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue