n8n-nodes-arubaclearpass
Version:
n8n community node for Aruba ClearPass API integration with comprehensive identity, policy, and enforcement profile management
213 lines (212 loc) • 7.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listEndpoints = listEndpoints;
exports.getEndpoint = getEndpoint;
exports.getEndpointByMac = getEndpointByMac;
exports.createEndpoint = createEndpoint;
exports.updateEndpoint = updateEndpoint;
exports.updateEndpointByMac = updateEndpointByMac;
exports.deleteEndpoint = deleteEndpoint;
exports.deleteEndpointByMac = deleteEndpointByMac;
const apiRequest_1 = require("../../helpers/apiRequest");
const responseFormatter_1 = require("../../helpers/responseFormatter");
/**
* Get a list of all endpoints
*/
async function listEndpoints() {
try {
const returnAll = this.getNodeParameter('returnAll', 0);
const filters = this.getNodeParameter('filters', 0, {});
const endpoint = '/endpoint';
let responseData;
if (returnAll) {
responseData = await apiRequest_1.apiRequestAllItems.call(this, 'GET', endpoint, {}, filters);
}
else {
const limit = this.getNodeParameter('limit', 0);
if (!filters.limit) {
filters.limit = limit;
}
responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, filters);
}
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
console.log('Error in listEndpoints:', error);
throw error;
}
}
/**
* Get an endpoint by ID
*/
async function getEndpoint() {
try {
const endpointId = this.getNodeParameter('endpointId', 0);
const endpoint = `/endpoint/${endpointId}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
console.log('Error in getEndpoint:', error);
throw error;
}
}
/**
* Get an endpoint by MAC address
*/
async function getEndpointByMac() {
try {
const macAddress = this.getNodeParameter('macAddress', 0);
const endpoint = `/endpoint/mac-address/${macAddress}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
console.log('Error in getEndpointByMac:', error);
throw error;
}
}
/**
* Create a new endpoint
*/
async function createEndpoint() {
try {
const body = {};
// Required parameters
body.mac_address = this.getNodeParameter('macAddress', 0);
// Optional parameters
const description = this.getNodeParameter('description', 0, '');
if (description)
body.description = description;
const status = this.getNodeParameter('status', 0, '');
if (status)
body.status = status;
const randomizedMac = this.getNodeParameter('randomizedMac', 0, false);
body.randomized_mac = randomizedMac;
const deviceInsightTags = this.getNodeParameter('deviceInsightTags', 0, '');
if (deviceInsightTags)
body.device_insight_tags = deviceInsightTags;
const attributesJson = this.getNodeParameter('attributes', 0, '{}');
try {
if (attributesJson) {
body.attributes = JSON.parse(attributesJson);
}
}
catch (error) {
throw new Error(`Invalid JSON in attributes field: ${error.message}`);
}
const endpoint = '/endpoint';
const responseData = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
console.log('Error in createEndpoint:', error);
throw error;
}
}
/**
* Update an endpoint by ID
*/
async function updateEndpoint() {
try {
const endpointId = this.getNodeParameter('endpointId', 0);
const body = {};
// Optional parameters
const description = this.getNodeParameter('description', 0, '');
if (description)
body.description = description;
const status = this.getNodeParameter('status', 0, '');
if (status)
body.status = status;
const randomizedMac = this.getNodeParameter('randomizedMac', 0, null);
if (randomizedMac !== null)
body.randomized_mac = randomizedMac;
const deviceInsightTags = this.getNodeParameter('deviceInsightTags', 0, '');
if (deviceInsightTags)
body.device_insight_tags = deviceInsightTags;
const attributesJson = this.getNodeParameter('attributes', 0, '');
try {
if (attributesJson) {
body.attributes = JSON.parse(attributesJson);
}
}
catch (error) {
throw new Error(`Invalid JSON in attributes field: ${error.message}`);
}
const endpoint = `/endpoint/${endpointId}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
console.log('Error in updateEndpoint:', error);
throw error;
}
}
/**
* Update an endpoint by MAC address
*/
async function updateEndpointByMac() {
try {
const macAddress = this.getNodeParameter('macAddress', 0);
const body = {};
// Optional parameters
const description = this.getNodeParameter('description', 0, '');
if (description)
body.description = description;
const status = this.getNodeParameter('status', 0, '');
if (status)
body.status = status;
const randomizedMac = this.getNodeParameter('randomizedMac', 0, null);
if (randomizedMac !== null)
body.randomized_mac = randomizedMac;
const deviceInsightTags = this.getNodeParameter('deviceInsightTags', 0, '');
if (deviceInsightTags)
body.device_insight_tags = deviceInsightTags;
const attributesJson = this.getNodeParameter('attributes', 0, '');
try {
if (attributesJson) {
body.attributes = JSON.parse(attributesJson);
}
}
catch (error) {
throw new Error(`Invalid JSON in attributes field: ${error.message}`);
}
const endpoint = `/endpoint/mac-address/${macAddress}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body);
return responseFormatter_1.formatResponse.call(this, responseData);
}
catch (error) {
console.log('Error in updateEndpointByMac:', error);
throw error;
}
}
/**
* Delete an endpoint by ID
*/
async function deleteEndpoint() {
try {
const endpointId = this.getNodeParameter('endpointId', 0);
const endpoint = `/endpoint/${endpointId}`;
await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint);
return [{ json: { success: true } }];
}
catch (error) {
console.log('Error in deleteEndpoint:', error);
throw error;
}
}
/**
* Delete an endpoint by MAC address
*/
async function deleteEndpointByMac() {
try {
const macAddress = this.getNodeParameter('macAddress', 0);
const endpoint = `/endpoint/mac-address/${macAddress}`;
await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint);
return [{ json: { success: true } }];
}
catch (error) {
console.log('Error in deleteEndpointByMac:', error);
throw error;
}
}