2024-07-15 07:16:41 -07:00
|
|
|
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
|
2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2022-10-07 06:10:02 -07:00
|
|
|
IDataObject,
|
2023-03-06 08:33:32 -08:00
|
|
|
IExecuteFunctions,
|
2022-10-07 06:10:02 -07:00
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
JsonObject,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
2024-07-15 07:16:41 -07:00
|
|
|
import { netscalerADCApiRequest } from './GenericFunctions';
|
2022-10-07 06:10:02 -07:00
|
|
|
|
|
|
|
import { fileDescription } from './FileDescription';
|
|
|
|
|
|
|
|
import { certificateDescription } from './CertificateDescription';
|
|
|
|
|
2024-07-15 07:16:41 -07:00
|
|
|
export class NetscalerAdc implements INodeType {
|
2022-10-07 06:10:02 -07:00
|
|
|
description: INodeTypeDescription = {
|
2024-07-15 07:16:41 -07:00
|
|
|
displayName: 'Netscaler ADC',
|
|
|
|
// This prevents a breaking change
|
2022-10-07 06:10:02 -07:00
|
|
|
name: 'citrixAdc',
|
2024-07-15 07:16:41 -07:00
|
|
|
icon: { light: 'file:netscaler.svg', dark: 'file:netscaler.dark.svg' },
|
2022-10-07 06:10:02 -07:00
|
|
|
group: ['output'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
2024-07-15 07:16:41 -07:00
|
|
|
description: 'Consume Netscaler ADC API',
|
2022-10-07 06:10:02 -07:00
|
|
|
defaults: {
|
2024-07-15 07:16:41 -07:00
|
|
|
name: 'Netscaler ADC',
|
2022-10-07 06:10:02 -07:00
|
|
|
},
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'citrixAdcApi',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
|
|
|
noDataExpression: true,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Certificate',
|
|
|
|
value: 'certificate',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'File',
|
|
|
|
value: 'file',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'file',
|
|
|
|
},
|
|
|
|
...certificateDescription,
|
|
|
|
...fileDescription,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2022-10-07 06:10:02 -07:00
|
|
|
let responseData: IDataObject | IDataObject[] = {};
|
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
try {
|
|
|
|
if (resource === 'file') {
|
|
|
|
if (operation === 'upload') {
|
|
|
|
const fileLocation = this.getNodeParameter('fileLocation', i) as string;
|
2022-12-02 03:53:59 -08:00
|
|
|
const binaryProperty = this.getNodeParameter('binaryProperty', i);
|
2022-11-18 07:29:44 -08:00
|
|
|
const options = this.getNodeParameter('options', i);
|
2022-12-29 03:20:43 -08:00
|
|
|
const endpoint = '/config/systemfile';
|
2022-10-07 06:10:02 -07:00
|
|
|
|
2023-03-06 08:33:32 -08:00
|
|
|
const binaryData = this.helpers.assertBinaryData(i, binaryProperty);
|
2022-10-07 06:10:02 -07:00
|
|
|
const buffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty);
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
systemfile: {
|
2023-03-06 08:33:32 -08:00
|
|
|
filename: binaryData.fileName,
|
2022-10-07 06:10:02 -07:00
|
|
|
filecontent: Buffer.from(buffer).toString('base64'),
|
|
|
|
filelocation: fileLocation,
|
|
|
|
fileencoding: 'BASE64',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (options.fileName) {
|
|
|
|
body.systemfile.filename = options.fileName as string;
|
|
|
|
}
|
|
|
|
|
2024-07-15 07:16:41 -07:00
|
|
|
await netscalerADCApiRequest.call(this, 'POST', endpoint, body);
|
2022-10-07 06:10:02 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
if (operation === 'delete') {
|
|
|
|
const fileName = this.getNodeParameter('fileName', i) as string;
|
|
|
|
const fileLocation = this.getNodeParameter('fileLocation', i) as string;
|
|
|
|
|
|
|
|
const endpoint = `/config/systemfile?args=filename:${fileName},filelocation:${encodeURIComponent(
|
|
|
|
fileLocation,
|
|
|
|
)}`;
|
|
|
|
|
2024-07-15 07:16:41 -07:00
|
|
|
await netscalerADCApiRequest.call(this, 'DELETE', endpoint);
|
2022-10-07 06:10:02 -07:00
|
|
|
responseData = { success: true };
|
|
|
|
}
|
|
|
|
if (operation === 'download') {
|
|
|
|
const fileName = this.getNodeParameter('fileName', i) as string;
|
|
|
|
const fileLocation = this.getNodeParameter('fileLocation', i) as string;
|
2022-12-02 03:53:59 -08:00
|
|
|
const binaryProperty = this.getNodeParameter('binaryProperty', i);
|
2022-10-07 06:10:02 -07:00
|
|
|
|
|
|
|
const endpoint = `/config/systemfile?args=filename:${fileName},filelocation:${encodeURIComponent(
|
|
|
|
fileLocation,
|
|
|
|
)}`;
|
|
|
|
|
2024-07-15 07:16:41 -07:00
|
|
|
const { systemfile } = await netscalerADCApiRequest.call(this, 'GET', endpoint);
|
2022-10-07 06:10:02 -07:00
|
|
|
|
|
|
|
const file = systemfile[0];
|
|
|
|
|
|
|
|
const binaryData = await this.helpers.prepareBinaryData(
|
2023-02-27 19:39:43 -08:00
|
|
|
Buffer.from(file.filecontent as string, 'base64'),
|
|
|
|
file.filename as string,
|
2022-10-07 06:10:02 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
responseData = {
|
|
|
|
json: file,
|
|
|
|
binary: {
|
|
|
|
[binaryProperty]: binaryData,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resource === 'certificate') {
|
|
|
|
if (operation === 'create') {
|
|
|
|
const certificateFileName = this.getNodeParameter('certificateFileName', i) as string;
|
|
|
|
const certificateFormat = this.getNodeParameter('certificateFormat', i) as string;
|
|
|
|
const certificateType = this.getNodeParameter('certificateType', i) as string;
|
|
|
|
const certificateRequestFileName = this.getNodeParameter(
|
|
|
|
'certificateRequestFileName',
|
|
|
|
i,
|
|
|
|
) as string;
|
2022-12-02 12:54:28 -08:00
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
2022-10-07 06:10:02 -07:00
|
|
|
|
|
|
|
let body: IDataObject = {
|
|
|
|
reqfile: certificateRequestFileName,
|
|
|
|
certfile: certificateFileName,
|
|
|
|
certform: certificateFormat,
|
|
|
|
certType: certificateType,
|
|
|
|
...additionalFields,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (certificateType === 'ROOT_CERT') {
|
|
|
|
const privateKeyFileName = this.getNodeParameter('privateKeyFileName', i) as string;
|
|
|
|
body = {
|
|
|
|
...body,
|
|
|
|
keyfile: privateKeyFileName,
|
|
|
|
};
|
|
|
|
} else {
|
2022-10-11 05:55:49 -07:00
|
|
|
const caCertificateFileName = this.getNodeParameter(
|
|
|
|
'caCertificateFileName',
|
|
|
|
i,
|
|
|
|
) as string;
|
|
|
|
const caCertificateFileFormat = this.getNodeParameter(
|
|
|
|
'caCertificateFileFormat',
|
|
|
|
i,
|
|
|
|
) as string;
|
|
|
|
const caPrivateKeyFileFormat = this.getNodeParameter(
|
|
|
|
'caPrivateKeyFileFormat',
|
|
|
|
i,
|
|
|
|
) as string;
|
|
|
|
const caPrivateKeyFileName = this.getNodeParameter(
|
|
|
|
'caPrivateKeyFileName',
|
|
|
|
i,
|
|
|
|
) as string;
|
2022-10-07 06:10:02 -07:00
|
|
|
const caSerialFileNumber = this.getNodeParameter('caSerialFileNumber', i) as string;
|
|
|
|
|
|
|
|
body = {
|
|
|
|
...body,
|
|
|
|
cacert: caCertificateFileName,
|
|
|
|
cacertform: caCertificateFileFormat,
|
|
|
|
cakey: caPrivateKeyFileName,
|
|
|
|
cakeyform: caPrivateKeyFileFormat,
|
|
|
|
caserial: caSerialFileNumber,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-29 03:20:43 -08:00
|
|
|
const endpoint = '/config/sslcert?action=create';
|
2022-10-07 06:10:02 -07:00
|
|
|
|
2024-07-15 07:16:41 -07:00
|
|
|
await netscalerADCApiRequest.call(this, 'POST', endpoint, { sslcert: body });
|
2022-10-07 06:10:02 -07:00
|
|
|
|
|
|
|
responseData = { success: true };
|
|
|
|
}
|
2022-10-11 05:55:49 -07:00
|
|
|
|
|
|
|
if (operation === 'install') {
|
|
|
|
const certificateKeyPairName = this.getNodeParameter(
|
|
|
|
'certificateKeyPairName',
|
|
|
|
i,
|
|
|
|
) as string;
|
|
|
|
const certificateFileName = this.getNodeParameter('certificateFileName', i) as string;
|
|
|
|
const privateKeyFileName = this.getNodeParameter('privateKeyFileName', i) as string;
|
|
|
|
const certificateFormat = this.getNodeParameter('certificateFormat', i) as string;
|
|
|
|
const notifyExpiration = this.getNodeParameter('notifyExpiration', i) as boolean;
|
|
|
|
const body: IDataObject = {
|
|
|
|
cert: certificateFileName,
|
|
|
|
certkey: certificateKeyPairName,
|
|
|
|
key: privateKeyFileName,
|
|
|
|
inform: certificateFormat,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (certificateFormat === 'PEM') {
|
|
|
|
const password = this.getNodeParameter('password', i) as string;
|
|
|
|
const certificateBundle = this.getNodeParameter('certificateBundle', i) as boolean;
|
|
|
|
Object.assign(body, {
|
|
|
|
passplain: password,
|
|
|
|
bundle: certificateBundle ? 'YES' : 'NO',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (notifyExpiration) {
|
|
|
|
const notificationPeriod = this.getNodeParameter('notificationPeriod', i) as number;
|
|
|
|
Object.assign(body, {
|
|
|
|
expirymonitor: 'ENABLED',
|
|
|
|
notificationperiod: notificationPeriod,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-29 03:20:43 -08:00
|
|
|
const endpoint = '/config/sslcertkey';
|
2022-10-11 05:55:49 -07:00
|
|
|
|
2024-07-15 07:16:41 -07:00
|
|
|
await netscalerADCApiRequest.call(this, 'POST', endpoint, { sslcertkey: body });
|
2022-10-11 05:55:49 -07:00
|
|
|
|
|
|
|
responseData = { success: true };
|
|
|
|
}
|
2022-10-07 06:10:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
returnData.push(
|
|
|
|
...this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), {
|
|
|
|
itemData: { item: i },
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
} catch (error) {
|
2024-06-19 22:45:00 -07:00
|
|
|
if (this.continueOnFail(error)) {
|
2022-10-07 06:10:02 -07:00
|
|
|
returnData.push({ error: (error as JsonObject).toString() });
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [returnData as INodeExecutionData[]];
|
|
|
|
}
|
|
|
|
}
|