n8n-nodes-arubaclearpass
Version:
n8n community node for Aruba ClearPass API integration with comprehensive identity, policy, and enforcement profile management
408 lines (407 loc) • 15.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listLocalUsers = listLocalUsers;
exports.getLocalUser = getLocalUser;
exports.getLocalUserByUserId = getLocalUserByUserId;
exports.createLocalUser = createLocalUser;
exports.updateLocalUser = updateLocalUser;
exports.updateLocalUserByUserId = updateLocalUserByUserId;
exports.replaceLocalUser = replaceLocalUser;
exports.replaceLocalUserByUserId = replaceLocalUserByUserId;
exports.deleteLocalUser = deleteLocalUser;
exports.deleteLocalUserByUserId = deleteLocalUserByUserId;
// methods/Identities/LocalUser.methods.ts
const n8n_workflow_1 = require("n8n-workflow");
const apiRequest_1 = require("../../helpers/apiRequest");
const responseFormatter_1 = require("../../helpers/responseFormatter");
/**
* Get a list of all local users
*/
async function listLocalUsers() {
try {
const returnAll = this.getNodeParameter('returnAll', 0);
const filters = this.getNodeParameter('filters', 0, {});
const endpoint = '/local-user';
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) {
const errorObject = {};
if (error instanceof Error) {
errorObject.message = error.message;
if (error.stack) {
errorObject.stackTrace = error.stack;
}
}
else {
errorObject.message = 'Unknown error in listLocalUsers';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Get a local user by ID
*/
async function getLocalUser() {
try {
const localUserId = this.getNodeParameter('localUserId', 0);
const endpoint = `/local-user/${localUserId}`;
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 getLocalUser';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Get a local user by User ID
*/
async function getLocalUserByUserId() {
try {
const userId = this.getNodeParameter('userId', 0);
const endpoint = `/local-user/user-id/${encodeURIComponent(userId)}`;
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 getLocalUserByUserId';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Create a new local user
*/
async function createLocalUser() {
try {
const body = {};
// Add required fields
body.user_id = this.getNodeParameter('userId', 0);
body.password = this.getNodeParameter('password', 0);
body.username = this.getNodeParameter('username', 0);
body.role_name = this.getNodeParameter('roleName', 0);
// Add optional fields from additionalFields
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
if (additionalFields.enabled !== undefined) {
body.enabled = additionalFields.enabled;
}
if (additionalFields.change_pwd_next_login !== undefined) {
body.change_pwd_next_login = additionalFields.change_pwd_next_login;
}
if (additionalFields.attributes) {
try {
const attributesJson = additionalFields.attributes;
body.attributes = JSON.parse(attributesJson);
}
catch (jsonError) {
const errorObject = {};
errorObject.message = `Invalid JSON in attributes: ${jsonError.message}`;
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
const endpoint = '/local-user';
const responseData = await apiRequest_1.apiRequest.call(this, 'POST', endpoint, body);
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 createLocalUser';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Update a local user
*/
async function updateLocalUser() {
try {
const localUserId = this.getNodeParameter('localUserId', 0);
const body = {};
// Get update fields
const updateFields = this.getNodeParameter('updateFields', 0, {});
// Map update fields to body
if (updateFields.user_id)
body.user_id = updateFields.user_id;
if (updateFields.password)
body.password = updateFields.password;
if (updateFields.username)
body.username = updateFields.username;
if (updateFields.role_name)
body.role_name = updateFields.role_name;
// Add optional fields from additionalFields
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
if (additionalFields.enabled !== undefined) {
body.enabled = additionalFields.enabled;
}
if (additionalFields.change_pwd_next_login !== undefined) {
body.change_pwd_next_login = additionalFields.change_pwd_next_login;
}
if (additionalFields.attributes) {
try {
const attributesJson = additionalFields.attributes;
body.attributes = JSON.parse(attributesJson);
}
catch (jsonError) {
const errorObject = {};
errorObject.message = `Invalid JSON in attributes: ${jsonError.message}`;
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
const endpoint = `/local-user/${localUserId}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body);
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 updateLocalUser';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Update a local user by User ID
*/
async function updateLocalUserByUserId() {
try {
const userId = this.getNodeParameter('userId', 0);
const body = {};
// Get update fields
const updateFields = this.getNodeParameter('updateFields', 0, {});
// Map update fields to body
if (updateFields.user_id)
body.user_id = updateFields.user_id;
if (updateFields.password)
body.password = updateFields.password;
if (updateFields.username)
body.username = updateFields.username;
if (updateFields.role_name)
body.role_name = updateFields.role_name;
// Add optional fields from additionalFields
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
if (additionalFields.enabled !== undefined) {
body.enabled = additionalFields.enabled;
}
if (additionalFields.change_pwd_next_login !== undefined) {
body.change_pwd_next_login = additionalFields.change_pwd_next_login;
}
if (additionalFields.attributes) {
try {
const attributesJson = additionalFields.attributes;
body.attributes = JSON.parse(attributesJson);
}
catch (jsonError) {
const errorObject = {};
errorObject.message = `Invalid JSON in attributes: ${jsonError.message}`;
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
const endpoint = `/local-user/user-id/${encodeURIComponent(userId)}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'PATCH', endpoint, body);
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 updateLocalUserByUserId';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Replace a local user
*/
async function replaceLocalUser() {
try {
const localUserId = this.getNodeParameter('localUserId', 0);
const body = {};
// Add required fields
body.user_id = this.getNodeParameter('userId', 0);
body.password = this.getNodeParameter('password', 0);
body.username = this.getNodeParameter('username', 0);
body.role_name = this.getNodeParameter('roleName', 0);
// Add optional fields from additionalFields
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
if (additionalFields.enabled !== undefined) {
body.enabled = additionalFields.enabled;
}
if (additionalFields.change_pwd_next_login !== undefined) {
body.change_pwd_next_login = additionalFields.change_pwd_next_login;
}
if (additionalFields.attributes) {
try {
const attributesJson = additionalFields.attributes;
body.attributes = JSON.parse(attributesJson);
}
catch (jsonError) {
const errorObject = {};
errorObject.message = `Invalid JSON in attributes: ${jsonError.message}`;
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
const endpoint = `/local-user/${localUserId}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'PUT', endpoint, body);
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 replaceLocalUser';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Replace a local user by User ID
*/
async function replaceLocalUserByUserId() {
try {
const userId = this.getNodeParameter('userId', 0);
const body = {};
// Add required fields
body.user_id = this.getNodeParameter('userId', 0);
body.password = this.getNodeParameter('password', 0);
body.username = this.getNodeParameter('username', 0);
body.role_name = this.getNodeParameter('roleName', 0);
// Add optional fields from additionalFields
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
if (additionalFields.enabled !== undefined) {
body.enabled = additionalFields.enabled;
}
if (additionalFields.change_pwd_next_login !== undefined) {
body.change_pwd_next_login = additionalFields.change_pwd_next_login;
}
if (additionalFields.attributes) {
try {
const attributesJson = additionalFields.attributes;
body.attributes = JSON.parse(attributesJson);
}
catch (jsonError) {
const errorObject = {};
errorObject.message = `Invalid JSON in attributes: ${jsonError.message}`;
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
const endpoint = `/local-user/user-id/${encodeURIComponent(userId)}`;
const responseData = await apiRequest_1.apiRequest.call(this, 'PUT', endpoint, body);
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 replaceLocalUserByUserId';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Delete a local user
*/
async function deleteLocalUser() {
try {
const localUserId = this.getNodeParameter('localUserId', 0);
const endpoint = `/local-user/${localUserId}`;
await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint);
return [
{ json: { success: true, message: `Local User with ID ${localUserId} has been deleted` } },
];
}
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 deleteLocalUser';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}
/**
* Delete a local user by User ID
*/
async function deleteLocalUserByUserId() {
try {
const userId = this.getNodeParameter('userId', 0);
const endpoint = `/local-user/user-id/${encodeURIComponent(userId)}`;
await apiRequest_1.apiRequest.call(this, 'DELETE', endpoint);
return [
{ json: { success: true, message: `Local User with User ID ${userId} has been deleted` } },
];
}
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 deleteLocalUserByUserId';
}
throw new n8n_workflow_1.NodeApiError(this.getNode(), errorObject);
}
}