n8n-nodes-arubaclearpass
Version:
n8n community node for Aruba ClearPass API integration with comprehensive identity, policy, and enforcement profile management
281 lines (280 loc) • 13.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listServerCerts = listServerCerts;
exports.getServerCertByServiceId = getServerCertByServiceId;
exports.getServerCertByServiceName = getServerCertByServiceName;
exports.replaceServerCertByServiceId = replaceServerCertByServiceId;
exports.replaceServerCertByServiceName = replaceServerCertByServiceName;
exports.enableServerCert = enableServerCert;
exports.disableServerCert = disableServerCert;
// methods/PlatformCertificates/ServerCert.methods.ts
const n8n_workflow_1 = require("n8n-workflow");
const apiRequest_1 = require("../../helpers/apiRequest");
const responseFormatter_1 = require("../../helpers/responseFormatter");
/**
* Read binary data by property name, with a clear error if the property doesn't exist.
*/
async function getBinaryData(context, propertyName, itemIndex) {
var _a, _b, _c, _d;
const inputData = context.getInputData();
const binaryKeys = Object.keys((_b = (_a = inputData[itemIndex]) === null || _a === void 0 ? void 0 : _a.binary) !== null && _b !== void 0 ? _b : {});
if (!((_d = (_c = inputData[itemIndex]) === null || _c === void 0 ? void 0 : _c.binary) === null || _d === void 0 ? void 0 : _d[propertyName])) {
throw new Error(`Binary property "${propertyName}" not found on the input item. ` +
`Available binary properties: [${binaryKeys.join(', ') || 'none'}]. ` +
`Check the binary field name matches the file input name from the previous node.`);
}
return context.helpers.getBinaryDataBuffer(itemIndex, propertyName);
}
/**
* List all server certificate assignments
* GET /server-cert
*/
async function listServerCerts() {
try {
const responseData = await apiRequest_1.apiRequest.call(this, 'GET', '/server-cert');
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
const errorObject = {};
if (error instanceof Error) {
errorObject.message = error.message;
if (error.stack) {
errorObject.stackTrace = error.stack;
}
}
else {
errorObject.message = 'Unknown error in listServerCerts';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Get the certificate assigned to a service by numeric service ID
* GET /server-cert/{service_id}
* service_id: 1=RADIUS, 2=HTTPS(ECC), 7=HTTPS(RSA), 21=RadSec, 106=Database
*/
async function getServerCertByServiceId() {
try {
const serviceId = this.getNodeParameter('serviceId', 0);
const endpoint = `/server-cert/${serviceId}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
const errorObject = {};
if (error instanceof Error) {
errorObject.message = error.message;
if (error.stack) {
errorObject.stackTrace = error.stack;
}
}
else {
errorObject.message = 'Unknown error in getServerCertByServiceId';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Get the certificate assigned to a service by server UUID and service name
* GET /server-cert/name/{server_uuid}/{service_name}
* service_name: RADIUS | HTTPS(RSA) | HTTPS(ECC) | RadSec
*/
async function getServerCertByServiceName() {
try {
const serverUuid = this.getNodeParameter('serverUuid', 0);
const serviceName = this.getNodeParameter('serviceName', 0);
const endpoint = `/server-cert/name/${encodeURIComponent(serverUuid)}/${encodeURIComponent(serviceName)}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
const errorObject = {};
if (error instanceof Error) {
errorObject.message = error.message;
if (error.stack) {
errorObject.stackTrace = error.stack;
}
}
else {
errorObject.message = 'Unknown error in getServerCertByServiceName';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Replace/update the certificate assigned to a service by numeric service ID
* PATCH /server-cert/{service_id}
* Provide cert via PKCS12 binary upload, separate cert+key binary upload, or URL.
*/
async function replaceServerCertByServiceId() {
var _a, _b, _c, _d;
try {
const serviceId = this.getNodeParameter('serviceId', 0);
const certInputMode = this.getNodeParameter('certInputMode', 0, 'pkcs12');
const body = {};
console.log(`[ClearPass] replaceServerCertByServiceId: serviceId=${serviceId}, certInputMode=${certInputMode}`);
if (certInputMode === 'pkcs12') {
const pkcs12BinaryProperty = this.getNodeParameter('pkcs12BinaryProperty', 0, 'data');
const pkcs12Passphrase = this.getNodeParameter('pkcs12_passphrase', 0, '');
console.log(`[ClearPass] PKCS12 mode: binaryProperty="${pkcs12BinaryProperty}"`);
const inputData = this.getInputData();
console.log(`[ClearPass] Input item binary keys: ${JSON.stringify(Object.keys((_b = (_a = inputData[0]) === null || _a === void 0 ? void 0 : _a.binary) !== null && _b !== void 0 ? _b : {}))}`);
const binaryData = await getBinaryData(this, pkcs12BinaryProperty, 0);
console.log(`[ClearPass] Binary data retrieved: ${binaryData.length} bytes`);
body.cert_file = binaryData.toString('base64');
if (pkcs12Passphrase)
body.pkcs12_passphrase = pkcs12Passphrase;
}
else if (certInputMode === 'certAndKey') {
const certBinaryProperty = this.getNodeParameter('certBinaryProperty', 0, 'data');
const keyBinaryProperty = this.getNodeParameter('keyBinaryProperty', 0, 'data');
const privateKeyPassword = this.getNodeParameter('private_key_password', 0, '');
console.log(`[ClearPass] Cert+Key mode: certBinaryProperty="${certBinaryProperty}", keyBinaryProperty="${keyBinaryProperty}"`);
const inputData = this.getInputData();
console.log(`[ClearPass] Input item binary keys: ${JSON.stringify(Object.keys((_d = (_c = inputData[0]) === null || _c === void 0 ? void 0 : _c.binary) !== null && _d !== void 0 ? _d : {}))}`);
const certData = await getBinaryData(this, certBinaryProperty, 0);
console.log(`[ClearPass] Cert binary data retrieved: ${certData.length} bytes`);
body.cert_file = certData.toString('base64');
const keyData = await getBinaryData(this, keyBinaryProperty, 0);
console.log(`[ClearPass] Key binary data retrieved: ${keyData.length} bytes`);
body.private_key_file = keyData.toString('base64');
if (privateKeyPassword)
body.private_key_password = privateKeyPassword;
}
else {
// URL mode
const certificateUrl = this.getNodeParameter('certificate_url', 0, '');
const pkcs12FileUrl = this.getNodeParameter('pkcs12_file_url', 0, '');
const pkcs12Passphrase = this.getNodeParameter('url_pkcs12_passphrase', 0, '');
console.log(`[ClearPass] URL mode: certificate_url="${certificateUrl}", pkcs12_file_url="${pkcs12FileUrl}"`);
if (certificateUrl)
body.certificate_url = certificateUrl;
if (pkcs12FileUrl)
body.pkcs12_file_url = pkcs12FileUrl;
if (pkcs12Passphrase)
body.pkcs12_passphrase = pkcs12Passphrase;
}
console.log(`[ClearPass] Request body keys: ${JSON.stringify(Object.keys(body))}`);
if (body.cert_file) {
console.log(`[ClearPass] cert_file length (base64 chars): ${body.cert_file.length}`);
}
const endpoint = `/server-cert/${serviceId}`;
console.log(`[ClearPass] Sending PATCH ${endpoint}`);
const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body);
console.log(`[ClearPass] Response received: ${JSON.stringify(responseData)}`);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
console.log(`[ClearPass] replaceServerCertByServiceId error: ${error instanceof Error ? error.message : String(error)}`);
if (error instanceof Error && error.stack) {
console.log(`[ClearPass] Stack: ${error.stack}`);
}
const errorObject = {};
if (error instanceof Error) {
errorObject.message = error.message;
if (error.stack)
errorObject.stackTrace = error.stack;
}
else {
errorObject.message = 'Unknown error in replaceServerCertByServiceId';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Replace/assign the certificate for a service by server UUID and service name
* PUT /server-cert/name/{server_uuid}/{service_name}
* service_name: RADIUS | HTTPS(RSA) | HTTPS(ECC) | RadSec
*/
async function replaceServerCertByServiceName() {
try {
const serverUuid = this.getNodeParameter('serverUuid', 0);
const serviceName = this.getNodeParameter('serviceName', 0);
const body = {};
const certificateUrl = this.getNodeParameter('certificate_url_byname', 0, '');
const pkcs12FileUrl = this.getNodeParameter('pkcs12_file_url_byname', 0, '');
const pkcs12Passphrase = this.getNodeParameter('pkcs12_passphrase_byname', 0, '');
console.log(`[ClearPass] replaceServerCertByServiceName: serverUuid="${serverUuid}", serviceName="${serviceName}"`);
console.log(`[ClearPass] certificate_url="${certificateUrl}", pkcs12_file_url="${pkcs12FileUrl}"`);
if (certificateUrl)
body.certificate_url = certificateUrl;
if (pkcs12FileUrl)
body.pkcs12_file_url = pkcs12FileUrl;
if (pkcs12Passphrase)
body.pkcs12_passphrase = pkcs12Passphrase;
console.log(`[ClearPass] Request body keys: ${JSON.stringify(Object.keys(body))}`);
const endpoint = `/server-cert/name/${encodeURIComponent(serverUuid)}/${encodeURIComponent(serviceName)}`;
console.log(`[ClearPass] Sending PUT ${endpoint}`);
const responseData = await apiRequest_1.apiRequest.call(this, 'PUT', endpoint, body);
console.log(`[ClearPass] Response received: ${JSON.stringify(responseData)}`);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
console.log(`[ClearPass] replaceServerCertByServiceName error: ${error instanceof Error ? error.message : String(error)}`);
if (error instanceof Error && error.stack) {
console.log(`[ClearPass] Stack: ${error.stack}`);
}
const errorObject = {};
if (error instanceof Error) {
errorObject.message = error.message;
if (error.stack)
errorObject.stackTrace = error.stack;
}
else {
errorObject.message = 'Unknown error in replaceServerCertByServiceName';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Enable a server certificate for a service
* PATCH /server-cert/name/{server_uuid}/{service_name}/enable
*/
async function enableServerCert() {
try {
const serverUuid = this.getNodeParameter('serverUuid', 0);
const serviceName = this.getNodeParameter('serviceName', 0);
const endpoint = `/server-cert/name/${encodeURIComponent(serverUuid)}/${encodeURIComponent(serviceName)}/enable`;
const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
const errorObject = {};
if (error instanceof Error) {
errorObject.message = error.message;
if (error.stack) {
errorObject.stackTrace = error.stack;
}
}
else {
errorObject.message = 'Unknown error in enableServerCert';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Disable a server certificate for a service
* PATCH /server-cert/name/{server_uuid}/{service_name}/disable
*/
async function disableServerCert() {
try {
const serverUuid = this.getNodeParameter('serverUuid', 0);
const serviceName = this.getNodeParameter('serviceName', 0);
const endpoint = `/server-cert/name/${encodeURIComponent(serverUuid)}/${encodeURIComponent(serviceName)}/disable`;
const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
const errorObject = {};
if (error instanceof Error) {
errorObject.message = error.message;
if (error.stack) {
errorObject.stackTrace = error.stack;
}
}
else {
errorObject.message = 'Unknown error in disableServerCert';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}