n8n-nodes-arubacentralnextgen
Version:
n8n community node for Aruba Central NextGen API integration with modern monitoring and management capabilities
462 lines (461 loc) • 18.5 kB
JavaScript
"use strict";
// methods/security/security.methods.ts
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllFirewall = getAllFirewall;
exports.getFirewall = getFirewall;
exports.createFirewall = createFirewall;
exports.updateFirewall = updateFirewall;
exports.deleteFirewall = deleteFirewall;
exports.getAllPortSecurity = getAllPortSecurity;
exports.getPortSecurity = getPortSecurity;
exports.createPortSecurity = createPortSecurity;
exports.updatePortSecurity = updatePortSecurity;
exports.deletePortSecurity = deletePortSecurity;
exports.getAllMACAuth = getAllMACAuth;
exports.getMACAuth = getMACAuth;
exports.createMACAuth = createMACAuth;
exports.updateMACAuth = updateMACAuth;
exports.deleteMACAuth = deleteMACAuth;
const apiRequest_1 = require("../../helpers/apiRequest");
const responseFormatter_1 = require("../../helpers/responseFormatter");
const logger = __importStar(require("../../helpers/logger"));
/**
* Security Domain Methods — Firewall, Port Security, MAC Authentication
* API Base Path: /network-config/v1alpha1/
*/
const FIREWALL_PATH = '/network-config/v1alpha1/firewall';
const PORT_SECURITY_PATH = '/network-config/v1alpha1/port-security';
const MAC_AUTH_PATH = '/network-config/v1alpha1/mac-authentication';
// ============================================================================
// Shared Helpers
// ============================================================================
function parseProfileBody(raw) {
try {
return typeof raw === 'string' ? JSON.parse(raw) : raw;
}
catch (e) {
throw new Error('Invalid JSON in Profile Body');
}
}
function buildGetAllQueryParams(additionalFields) {
const queryParams = {};
if (additionalFields.viewType)
queryParams['view-type'] = additionalFields.viewType;
if (additionalFields.objectType)
queryParams['object-type'] = additionalFields.objectType;
if (additionalFields.scopeId)
queryParams['scope-id'] = additionalFields.scopeId;
if (additionalFields.persona)
queryParams.persona = additionalFields.persona;
if (additionalFields.effective !== undefined)
queryParams.effective = additionalFields.effective;
if (additionalFields.detailed !== undefined)
queryParams.detailed = additionalFields.detailed;
if (additionalFields.limit)
queryParams.limit = additionalFields.limit;
if (additionalFields.offset !== undefined)
queryParams.offset = additionalFields.offset;
return queryParams;
}
// ============================================================================
// Firewall Methods
// ============================================================================
/**
* Get all firewall profiles
*/
async function getAllFirewall() {
var _a, _b;
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting getAllFirewall operation', undefined, this);
}
try {
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
const queryParams = buildGetAllQueryParams(additionalFields);
if (debugMode) {
logger.debug('Query parameters', queryParams, this);
}
const response = await apiRequest_1.apiRequest.call(this, 'GET', FIREWALL_PATH, {}, queryParams);
if (debugMode) {
logger.debug(`Retrieved ${((_a = response.items) === null || _a === void 0 ? void 0 : _a.length) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.length) || 0} firewall profiles`, undefined, this);
}
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in getAllFirewall', error);
throw error;
}
}
/**
* Get a specific firewall profile by name
*/
async function getFirewall() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting getFirewall operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
if (debugMode) {
logger.debug('Getting firewall profile', { profileName }, this);
}
const endpoint = `${FIREWALL_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in getFirewall', error);
throw error;
}
}
/**
* Create a new firewall profile
*/
async function createFirewall() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting createFirewall operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}');
const profileBody = parseProfileBody(profileBodyRaw);
if (debugMode) {
logger.debug('Creating firewall profile', { profileName, profileBody }, this);
}
const endpoint = `${FIREWALL_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, profileBody, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in createFirewall', error);
throw error;
}
}
/**
* Update an existing firewall profile
*/
async function updateFirewall() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting updateFirewall operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}');
const profileBody = parseProfileBody(profileBodyRaw);
if (debugMode) {
logger.debug('Updating firewall profile', { profileName, profileBody }, this);
}
const endpoint = `${FIREWALL_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, profileBody, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in updateFirewall', error);
throw error;
}
}
/**
* Delete a firewall profile
*/
async function deleteFirewall() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting deleteFirewall operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
if (debugMode) {
logger.debug('Deleting firewall profile', { profileName }, this);
}
const endpoint = `${FIREWALL_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, {});
return responseFormatter_1.formatResponse.call(this, response && Object.keys(response).length > 0
? response
: { success: true, profileName, message: 'Firewall profile deleted successfully' });
}
catch (error) {
logger.error('Error in deleteFirewall', error);
throw error;
}
}
// ============================================================================
// Port Security Methods
// ============================================================================
/**
* Get all port security profiles
*/
async function getAllPortSecurity() {
var _a, _b;
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting getAllPortSecurity operation', undefined, this);
}
try {
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
const queryParams = buildGetAllQueryParams(additionalFields);
if (debugMode) {
logger.debug('Query parameters', queryParams, this);
}
const response = await apiRequest_1.apiRequest.call(this, 'GET', PORT_SECURITY_PATH, {}, queryParams);
if (debugMode) {
logger.debug(`Retrieved ${((_a = response.items) === null || _a === void 0 ? void 0 : _a.length) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.length) || 0} port security profiles`, undefined, this);
}
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in getAllPortSecurity', error);
throw error;
}
}
/**
* Get a specific port security profile by name
*/
async function getPortSecurity() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting getPortSecurity operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
if (debugMode) {
logger.debug('Getting port security profile', { profileName }, this);
}
const endpoint = `${PORT_SECURITY_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in getPortSecurity', error);
throw error;
}
}
/**
* Create a new port security profile
*/
async function createPortSecurity() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting createPortSecurity operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}');
const profileBody = parseProfileBody(profileBodyRaw);
if (debugMode) {
logger.debug('Creating port security profile', { profileName, profileBody }, this);
}
const endpoint = `${PORT_SECURITY_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, profileBody, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in createPortSecurity', error);
throw error;
}
}
/**
* Update an existing port security profile
*/
async function updatePortSecurity() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting updatePortSecurity operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}');
const profileBody = parseProfileBody(profileBodyRaw);
if (debugMode) {
logger.debug('Updating port security profile', { profileName, profileBody }, this);
}
const endpoint = `${PORT_SECURITY_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, profileBody, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in updatePortSecurity', error);
throw error;
}
}
/**
* Delete a port security profile
*/
async function deletePortSecurity() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting deletePortSecurity operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
if (debugMode) {
logger.debug('Deleting port security profile', { profileName }, this);
}
const endpoint = `${PORT_SECURITY_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, {});
return responseFormatter_1.formatResponse.call(this, response && Object.keys(response).length > 0
? response
: { success: true, profileName, message: 'Port security profile deleted successfully' });
}
catch (error) {
logger.error('Error in deletePortSecurity', error);
throw error;
}
}
// ============================================================================
// MAC Authentication Methods
// ============================================================================
/**
* Get all MAC authentication profiles
*/
async function getAllMACAuth() {
var _a, _b;
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting getAllMACAuth operation', undefined, this);
}
try {
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
const queryParams = buildGetAllQueryParams(additionalFields);
if (debugMode) {
logger.debug('Query parameters', queryParams, this);
}
const response = await apiRequest_1.apiRequest.call(this, 'GET', MAC_AUTH_PATH, {}, queryParams);
if (debugMode) {
logger.debug(`Retrieved ${((_a = response.items) === null || _a === void 0 ? void 0 : _a.length) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.length) || 0} MAC auth profiles`, undefined, this);
}
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in getAllMACAuth', error);
throw error;
}
}
/**
* Get a specific MAC authentication profile by name
*/
async function getMACAuth() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting getMACAuth operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
if (debugMode) {
logger.debug('Getting MAC auth profile', { profileName }, this);
}
const endpoint = `${MAC_AUTH_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in getMACAuth', error);
throw error;
}
}
/**
* Create a new MAC authentication profile
*/
async function createMACAuth() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting createMACAuth operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}');
const profileBody = parseProfileBody(profileBodyRaw);
if (debugMode) {
logger.debug('Creating MAC auth profile', { profileName, profileBody }, this);
}
const endpoint = `${MAC_AUTH_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, profileBody, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in createMACAuth', error);
throw error;
}
}
/**
* Update an existing MAC authentication profile
*/
async function updateMACAuth() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting updateMACAuth operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
const profileBodyRaw = this.getNodeParameter('profileBody', 0, '{}');
const profileBody = parseProfileBody(profileBodyRaw);
if (debugMode) {
logger.debug('Updating MAC auth profile', { profileName, profileBody }, this);
}
const endpoint = `${MAC_AUTH_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, profileBody, {});
return responseFormatter_1.formatResponse.call(this, response);
}
catch (error) {
logger.error('Error in updateMACAuth', error);
throw error;
}
}
/**
* Delete a MAC authentication profile
*/
async function deleteMACAuth() {
const debugMode = logger.isDebugMode(this);
if (debugMode) {
logger.debug('Starting deleteMACAuth operation', undefined, this);
}
try {
const profileName = this.getNodeParameter('profileName', 0);
if (debugMode) {
logger.debug('Deleting MAC auth profile', { profileName }, this);
}
const endpoint = `${MAC_AUTH_PATH}/${encodeURIComponent(profileName)}`;
const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, {});
return responseFormatter_1.formatResponse.call(this, response && Object.keys(response).length > 0
? response
: { success: true, profileName, message: 'MAC auth profile deleted successfully' });
}
catch (error) {
logger.error('Error in deleteMACAuth', error);
throw error;
}
}