From 04e158fab8a062f59557fe02860dd464a23e2c5f Mon Sep 17 00:00:00 2001 From: Eywek Date: Thu, 24 May 2018 15:11:48 +0200 Subject: [PATCH] improv: fix #48 for old agent --- src/InteractorClient.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/InteractorClient.js b/src/InteractorClient.js index b704b2b..0e1d017 100644 --- a/src/InteractorClient.js +++ b/src/InteractorClient.js @@ -324,7 +324,20 @@ module.exports = class InteractorDaemonizer { // Try loading configuration file on FS try { - confFS = JSON.parse(fs.readFileSync(cst.INTERACTION_CONF)) + let fileContent = fs.readFileSync(cst.INTERACTION_CONF).toString() + // Handle old configuration with json5 + if (fileContent.indexOf('secret_key:') > -1) { + fileContent = fileContent.replace('secret_key:', '"secret_key":') + fileContent = fileContent.replace('version_management:', '"version_management":') + fileContent = fileContent.replace('machine_name:', '"machine_name":') + fileContent = fileContent.replace('public_key:', '"public_key":') + fileContent = fileContent.replace('reverse_interact:', '"reverse_interact":') + fileContent = fileContent.replace('info_node:', '"info_node":') + fileContent = fileContent.replace('active:', '"active":') + fileContent = fileContent.replace('password:', '"password":') + } + // parse + confFS = JSON.parse(fileContent) if (confFS.version_management) { configuration.version_management.active = confFS.version_management.active @@ -347,6 +360,9 @@ module.exports = class InteractorDaemonizer { configuration.agent_transport_websocket = process.env.AGENT_TRANSPORT_WEBSOCKET || infos.agent_transport_websocket || confFS.agent_transport_websocket || 'false' configuration.agent_transport_axon = process.env.AGENT_TRANSPORT_AXON || infos.agent_transport_axon || confFS.agent_transport_axon || 'true' + if (configuration.info_node.indexOf('http') === -1) { // handle old file + configuration.info_node = `https://${configuration.info_node}` + } if (!configuration.secret_key) return cb(new Error('secret key is not defined')) if (!configuration.public_key) return cb(new Error('public key is not defined'))