Add defensive config handling for multi-node settings

This commit is contained in:
Cosimo Ricciardi 2026-05-14 11:51:10 +02:00 committed by Suheb
parent bd0f515a6e
commit df52b9b77f
4 changed files with 36 additions and 36 deletions

View file

@ -197,26 +197,26 @@ export const getConfig = (req, res, next) => {
export const updateNodeSettings = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Node Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index));
if (node && node.settings) {
node.settings = { ...node.settings, ...req.body.settings };
if (node.authentication && req.body.authentication) {
if (req.body.authentication.boltzMacaroonPath) {
node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
}
else {
delete node.authentication.boltzMacaroonPath;
}
if (req.body.authentication.swapMacaroonPath) {
node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
}
else {
delete node.authentication.swapMacaroonPath;
try {
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index));
if (node && node.settings) {
node.settings = { ...node.settings, ...req.body.settings };
if (node.authentication && req.body.authentication) {
if (req.body.authentication.boltzMacaroonPath) {
node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
}
else {
delete node.authentication.boltzMacaroonPath;
}
if (req.body.authentication.swapMacaroonPath) {
node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
}
else {
delete node.authentication.swapMacaroonPath;
}
}
}
}
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
const selectedNode = common.findNode(req.session.selectedNode.index);
if (selectedNode && selectedNode.settings) {

View file

@ -70,7 +70,7 @@ export class CommonService {
config.secret2FA = this.appConfig.secret2FA;
}
const appConfigNodes = new Map(this.appConfig.nodes?.map((node) => [node.index, node]));
config.nodes.forEach((node) => {
config.nodes?.forEach((node) => {
const appConfigNode = appConfigNodes.get(node.index);
if (appConfigNode?.authentication) {
if (appConfigNode.authentication.macaroonPath) {

View file

@ -201,24 +201,24 @@ export const getConfig = (req, res, next) => {
export const updateNodeSettings = (req, res, next) => {
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Updating Node Settings..' });
const RTLConfFile = common.appConfig.rtlConfFilePath + sep + 'RTL-Config.json';
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index));
if (node && node.settings) {
node.settings = { ...node.settings, ...req.body.settings };
if (node.authentication && req.body.authentication) {
if (req.body.authentication.boltzMacaroonPath) {
node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
} else {
delete node.authentication.boltzMacaroonPath;
}
if (req.body.authentication.swapMacaroonPath) {
node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
} else {
delete node.authentication.swapMacaroonPath;
try {
const config = JSON.parse(fs.readFileSync(RTLConfFile, 'utf-8'));
const node = config.nodes.find((node) => (node.index === req.session.selectedNode.index));
if (node && node.settings) {
node.settings = { ...node.settings, ...req.body.settings };
if (node.authentication && req.body.authentication) {
if (req.body.authentication.boltzMacaroonPath) {
node.authentication.boltzMacaroonPath = req.body.authentication.boltzMacaroonPath;
} else {
delete node.authentication.boltzMacaroonPath;
}
if (req.body.authentication.swapMacaroonPath) {
node.authentication.swapMacaroonPath = req.body.authentication.swapMacaroonPath;
} else {
delete node.authentication.swapMacaroonPath;
}
}
}
}
try {
fs.writeFileSync(RTLConfFile, JSON.stringify(config, null, 2), 'utf-8');
const selectedNode = common.findNode(req.session.selectedNode.index);
if (selectedNode && selectedNode.settings) {

View file

@ -79,7 +79,7 @@ export class CommonService {
config.secret2FA = this.appConfig.secret2FA;
}
const appConfigNodes = new Map(this.appConfig.nodes?.map((node) => [node.index, node]));
config.nodes.forEach((node) => {
config.nodes?.forEach((node) => {
const appConfigNode = appConfigNodes.get(node.index);
if (appConfigNode?.authentication) {
if (appConfigNode.authentication.macaroonPath) {