2023-01-27 03:22:44 -08:00
|
|
|
import type { IExecuteFunctions } from 'n8n-core';
|
|
|
|
import type {
|
2020-03-12 11:57:57 -07:00
|
|
|
IDataObject,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
2023-01-27 03:22:44 -08:00
|
|
|
import { NodeOperationError } 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',
|
2022-07-10 13:50:51 -07:00
|
|
|
action: 'Execute a job',
|
2020-03-15 11:20:41 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Get Metadata',
|
|
|
|
value: 'getMetadata',
|
|
|
|
description: 'Get metadata of a job',
|
2022-07-10 13:50:51 -07:00
|
|
|
action: '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: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['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: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['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: {
|
2022-08-17 08:50:24 -07:00
|
|
|
operation: ['getMetadata'],
|
|
|
|
resource: ['job'],
|
2020-03-15 11:20:41 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
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
|
|
|
|
2022-12-02 03:53:59 -08:00
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
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;
|
2022-08-17 08:50:24 -07:00
|
|
|
const rundeckArguments = (this.getNodeParameter('arguments', i) as IDataObject)
|
|
|
|
.arguments as IDataObject[];
|
2020-03-15 11:20:41 -07:00
|
|
|
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 {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The operation "${operation}" is not supported!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
2020-03-12 11:57:57 -07:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-17 08:50:24 -07:00
|
|
|
throw new NodeOperationError(
|
|
|
|
this.getNode(),
|
|
|
|
`The resource "${resource}" is not supported!`,
|
|
|
|
{ itemIndex: i },
|
|
|
|
);
|
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)];
|
|
|
|
}
|
|
|
|
}
|