2020-03-12 11:57:57 -07:00
|
|
|
import { IExecuteFunctions } from 'n8n-core';
|
|
|
|
import {
|
|
|
|
IDataObject,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2021-04-16 09:33:36 -07:00
|
|
|
NodeOperationError,
|
2020-03-12 11:57:57 -07:00
|
|
|
} from 'n8n-workflow';
|
2020-03-15 11:20:41 -07:00
|
|
|
import { RundeckApi } from './RundeckApi';
|
2020-03-12 11:57:57 -07:00
|
|
|
|
|
|
|
export class Rundeck implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Rundeck',
|
|
|
|
name: 'rundeck',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2020-03-12 11:57:57 -07:00
|
|
|
icon: 'file:rundeck.png',
|
|
|
|
group: ['transform'],
|
|
|
|
version: 1,
|
2020-03-15 11:20:41 -07:00
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2020-03-12 11:57:57 -07:00
|
|
|
description: 'Manage Rundeck API',
|
|
|
|
defaults: {
|
|
|
|
name: 'Rundeck',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
2020-03-15 11:20:41 -07:00
|
|
|
name: 'rundeckApi',
|
2020-03-12 11:57:57 -07:00
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-03-12 11:57:57 -07:00
|
|
|
],
|
|
|
|
properties: [
|
2020-03-15 11:20:41 -07:00
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-03-15 11:20:41 -07:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Job',
|
|
|
|
value: 'job',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'job',
|
|
|
|
},
|
2020-03-12 11:57:57 -07:00
|
|
|
{
|
|
|
|
displayName: 'Operation',
|
|
|
|
name: 'operation',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-03-12 11:57:57 -07:00
|
|
|
options: [
|
|
|
|
{
|
2020-03-15 11:20:41 -07:00
|
|
|
name: 'Execute',
|
|
|
|
value: 'execute',
|
2020-07-24 03:56:41 -07:00
|
|
|
description: 'Execute a job',
|
2020-03-15 11:20:41 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Get Metadata',
|
|
|
|
value: 'getMetadata',
|
|
|
|
description: 'Get metadata of a job',
|
2020-03-12 11:57:57 -07:00
|
|
|
},
|
|
|
|
],
|
2020-03-15 11:20:41 -07:00
|
|
|
default: 'execute',
|
2020-03-12 11:57:57 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// ----------------------------------
|
2020-03-15 11:20:41 -07:00
|
|
|
// job:execute
|
2020-03-12 11:57:57 -07:00
|
|
|
// ----------------------------------
|
|
|
|
{
|
2022-05-20 14:47:24 -07:00
|
|
|
displayName: 'Job ID',
|
2020-03-12 11:57:57 -07:00
|
|
|
name: 'jobid',
|
|
|
|
type: 'string',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
2020-03-15 11:20:41 -07:00
|
|
|
'execute',
|
|
|
|
],
|
|
|
|
resource: [
|
|
|
|
'job',
|
2020-03-12 11:57:57 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
2022-06-03 10:23:49 -07:00
|
|
|
placeholder: 'Rundeck Job ID',
|
2020-03-12 11:57:57 -07:00
|
|
|
required: true,
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The job ID to execute',
|
2020-03-12 11:57:57 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Arguments',
|
|
|
|
name: 'arguments',
|
2020-03-15 11:20:41 -07:00
|
|
|
placeholder: 'Add Argument',
|
2020-03-12 11:57:57 -07:00
|
|
|
type: 'fixedCollection',
|
|
|
|
typeOptions: {
|
|
|
|
multipleValues: true,
|
|
|
|
},
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
2020-03-15 11:20:41 -07:00
|
|
|
'execute',
|
|
|
|
],
|
|
|
|
resource: [
|
|
|
|
'job',
|
2020-03-12 11:57:57 -07:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: {},
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'arguments',
|
2020-03-15 11:20:41 -07:00
|
|
|
displayName: 'Arguments',
|
2020-03-12 11:57:57 -07:00
|
|
|
values: [
|
|
|
|
{
|
|
|
|
displayName: 'Name',
|
|
|
|
name: 'name',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayName: 'Value',
|
|
|
|
name: 'value',
|
|
|
|
type: 'string',
|
|
|
|
default: '',
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2020-03-12 11:57:57 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-03-15 11:20:41 -07:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------
|
|
|
|
// job:getMetadata
|
|
|
|
// ----------------------------------
|
|
|
|
{
|
2022-05-20 14:47:24 -07:00
|
|
|
displayName: 'Job ID',
|
2020-03-15 11:20:41 -07:00
|
|
|
name: 'jobid',
|
|
|
|
type: 'string',
|
|
|
|
displayOptions: {
|
|
|
|
show: {
|
|
|
|
operation: [
|
|
|
|
'getMetadata',
|
|
|
|
],
|
|
|
|
resource: [
|
|
|
|
'job',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
default: '',
|
2022-06-03 10:23:49 -07:00
|
|
|
placeholder: 'Rundeck Job ID',
|
2020-03-15 11:20:41 -07:00
|
|
|
required: true,
|
2022-05-06 14:01:25 -07:00
|
|
|
description: 'The job ID to get metadata off',
|
2020-03-15 11:20:41 -07:00
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2020-03-12 11:57:57 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
|
|
|
|
// Input data
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-03-12 11:57:57 -07:00
|
|
|
|
|
|
|
const operation = this.getNodeParameter('operation', 0) as string;
|
2020-03-15 11:20:41 -07:00
|
|
|
const resource = this.getNodeParameter('resource', 0) as string;
|
2021-10-06 11:14:53 -07:00
|
|
|
const rundeckApi = new RundeckApi(this);
|
|
|
|
await rundeckApi.init();
|
|
|
|
|
2020-03-12 11:57:57 -07:00
|
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
2020-03-15 11:20:41 -07:00
|
|
|
|
|
|
|
if (resource === 'job') {
|
|
|
|
if (operation === 'execute') {
|
|
|
|
// ----------------------------------
|
|
|
|
// job: execute
|
|
|
|
// ----------------------------------
|
|
|
|
const jobid = this.getNodeParameter('jobid', i) as string;
|
|
|
|
const rundeckArguments = (this.getNodeParameter('arguments', i) as IDataObject).arguments as IDataObject[];
|
|
|
|
const response = await rundeckApi.executeJob(jobid, rundeckArguments);
|
|
|
|
|
|
|
|
returnData.push(response);
|
|
|
|
} else if (operation === 'getMetadata') {
|
|
|
|
// ----------------------------------
|
|
|
|
// job: getMetadata
|
|
|
|
// ----------------------------------
|
|
|
|
const jobid = this.getNodeParameter('jobid', i) as string;
|
|
|
|
const response = await rundeckApi.getJobMetadata(jobid);
|
|
|
|
|
|
|
|
returnData.push(response);
|
|
|
|
} else {
|
2021-04-16 09:33:36 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not supported!`);
|
2020-03-12 11:57:57 -07:00
|
|
|
}
|
|
|
|
} else {
|
2021-04-16 09:33:36 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not supported!`);
|
2020-03-12 11:57:57 -07:00
|
|
|
}
|
|
|
|
}
|
2020-03-15 11:20:41 -07:00
|
|
|
|
2020-03-12 11:57:57 -07:00
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
2020-03-15 11:20:41 -07:00
|
|
|
|
2020-03-12 11:57:57 -07:00
|
|
|
}
|
|
|
|
}
|