Skip to content

Commit

Permalink
improv: fix #48 for old agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Eywek committed May 24, 2018
1 parent 0645be7 commit 04e158f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/InteractorClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'))

Expand Down

0 comments on commit 04e158f

Please sign in to comment.