UNPKG

n8n-nodes-arubacentralnextgen

Version:

n8n community node for Aruba Central NextGen API integration with modern monitoring and management capabilities

206 lines (205 loc) 9.78 kB
"use strict"; // methods/system/configAssignment/configAssignment.methods.ts // Config Assignment Operations for Aruba Central NextGen API 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.listConfigAssignments = listConfigAssignments; exports.getConfigAssignment = getConfigAssignment; exports.createConfigAssignment = createConfigAssignment; exports.deleteConfigAssignment = deleteConfigAssignment; const apiRequest_1 = require("../../../helpers/apiRequest"); const responseFormatter_1 = require("../../../helpers/responseFormatter"); const logger = __importStar(require("../../../helpers/logger")); /** * Config Assignment Methods * Maps configuration profiles to scopes and device functions. * * API Reference: https://developer.arubanetworks.com/new-central-config/reference/readconfigassignments * Base Path: /network-config/v1alpha1/config-assignments * * Operations: * - listConfigAssignments: GET /network-config/v1alpha1/config-assignments * - getConfigAssignment: GET /network-config/v1alpha1/config-assignments/{scope-id}/{device-function}/{profile-type}/{profile-instance} * - createConfigAssignment: POST /network-config/v1alpha1/config-assignments/{scope-id}/{device-function}/{profile-type}/{profile-instance} * - deleteConfigAssignment: DELETE /network-config/v1alpha1/config-assignments/{scope-id}/{device-function}/{profile-type}/{profile-instance} */ const BASE_PATH = '/network-config/v1alpha1/config-assignments'; /** * List Config Assignments * Returns all config assignments, optionally filtered by scope, device function, and type. */ async function listConfigAssignments() { const debugMode = logger.isDebugMode(this); if (debugMode) logger.debug('Starting listConfigAssignments operation', undefined, this); try { const additionalFields = this.getNodeParameter('additionalFields', 0, {}); 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.deviceFunction) queryParams['device-function'] = additionalFields.deviceFunction; 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; if (debugMode) { logger.debug('listConfigAssignments parameters', { queryParams }, this); } const response = await apiRequest_1.apiRequest.call(this, 'GET', BASE_PATH, {}, queryParams); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in listConfigAssignments', error); throw error; } } /** * Get Config Assignment * Returns a specific config assignment by its full key (scope-id, device-function, profile-type, profile-instance). */ async function getConfigAssignment() { const debugMode = logger.isDebugMode(this); if (debugMode) logger.debug('Starting getConfigAssignment operation', undefined, this); try { const scopeId = this.getNodeParameter('scopeId', 0); const deviceFunction = this.getNodeParameter('deviceFunction', 0); const profileType = this.getNodeParameter('profileType', 0); const profileInstance = this.getNodeParameter('profileInstance', 0); const additionalFields = this.getNodeParameter('additionalFields', 0, {}); const endpoint = `${BASE_PATH}/${encodeURIComponent(scopeId)}/${encodeURIComponent(deviceFunction)}/${encodeURIComponent(profileType)}/${encodeURIComponent(profileInstance)}`; const queryParams = {}; if (additionalFields.effective !== undefined) queryParams.effective = additionalFields.effective; if (additionalFields.detailed !== undefined) queryParams.detailed = additionalFields.detailed; if (debugMode) { logger.debug('getConfigAssignment parameters', { scopeId, deviceFunction, profileType, profileInstance, queryParams }, this); } const response = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, queryParams); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in getConfigAssignment', error); throw error; } } /** * Create Config Assignment * Creates a new config assignment mapping a profile to a scope and device function. * POST body: { "config-assignment": [{ "scope-id", "device-function", "profile-type", "profile-instance" }] } */ async function createConfigAssignment() { const debugMode = logger.isDebugMode(this); if (debugMode) logger.debug('Starting createConfigAssignment operation', undefined, this); try { const scopeId = this.getNodeParameter('scopeId', 0); const deviceFunction = this.getNodeParameter('deviceFunction', 0); const profileType = this.getNodeParameter('profileType', 0); const profileInstance = this.getNodeParameter('profileInstance', 0); const body = { 'config-assignment': [ { 'scope-id': String(scopeId), 'device-function': String(deviceFunction), 'profile-type': String(profileType), 'profile-instance': String(profileInstance), }, ], }; if (debugMode) { logger.debug('createConfigAssignment parameters', { scopeId, deviceFunction, profileType, profileInstance }, this); } const response = await apiRequest_1.apiRequest.call(this, 'POST', BASE_PATH, body, {}); return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in createConfigAssignment', error); throw error; } } /** * Delete Config Assignment * Deletes a specific config assignment by its full key. */ async function deleteConfigAssignment() { const debugMode = logger.isDebugMode(this); if (debugMode) logger.debug('Starting deleteConfigAssignment operation', undefined, this); try { const scopeId = this.getNodeParameter('scopeId', 0); const deviceFunction = this.getNodeParameter('deviceFunction', 0); const profileType = this.getNodeParameter('profileType', 0); const profileInstance = this.getNodeParameter('profileInstance', 0); const additionalFields = this.getNodeParameter('additionalFields', 0, {}); const endpoint = `${BASE_PATH}/${encodeURIComponent(scopeId)}/${encodeURIComponent(deviceFunction)}/${encodeURIComponent(profileType)}/${encodeURIComponent(profileInstance)}`; const queryParams = {}; if (additionalFields.objectType) queryParams['object-type'] = additionalFields.objectType; if (additionalFields.overrideScopeId) queryParams['scope-id'] = additionalFields.overrideScopeId; if (additionalFields.overrideDeviceFunction) queryParams['device-function'] = additionalFields.overrideDeviceFunction; if (debugMode) { logger.debug('deleteConfigAssignment parameters', { scopeId, deviceFunction, profileType, profileInstance, queryParams }, this); } const response = await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint, {}, queryParams); // DELETE returns empty body on success if (!response || Object.keys(response).length === 0) { return responseFormatter_1.formatResponse.call(this, { success: true, scopeId, deviceFunction, profileType, profileInstance, }); } return responseFormatter_1.formatResponse.call(this, response); } catch (error) { logger.error('Error in deleteConfigAssignment', error); throw error; } }