update ssu command to allow plugin configuration
This commit is contained in:
parent
92bed14927
commit
c897275714
2 changed files with 57 additions and 1 deletions
54
bin/ssu
54
bin/ssu
|
|
@ -8,6 +8,7 @@ var Promise = require('es6-promise')
|
|||
var pgp = require('pg-promise')({
|
||||
promiseLib: Promise
|
||||
})
|
||||
var inquirer = require('inquirer')
|
||||
|
||||
var fs = require('fs')
|
||||
|
||||
|
|
@ -21,6 +22,8 @@ function bail () {
|
|||
console.log('This will remotely reboot your lamassu-machine.')
|
||||
console.log('\nssu crypto <code> <ticker-plugin> <wallet-plugin> [<trader-plugin>]')
|
||||
console.log('This will configure a new cryptocurrency.')
|
||||
console.log('\nssu config <plugin> <key>')
|
||||
console.log('Configure a plugin setting.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +34,9 @@ switch (cmd) {
|
|||
case 'crypto':
|
||||
crypto()
|
||||
break
|
||||
case 'config':
|
||||
configure()
|
||||
break
|
||||
default:
|
||||
|
||||
}
|
||||
|
|
@ -153,3 +159,51 @@ function crypto () {
|
|||
pgp.end()
|
||||
})
|
||||
}
|
||||
|
||||
function configure () {
|
||||
var plugin = argv[1]
|
||||
var key = argv[2]
|
||||
|
||||
if (!plugin || !key) {
|
||||
console.log('\nssu config <plugin> <key>')
|
||||
console.log('Configure a plugin setting.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
inquirer.prompt([{
|
||||
type: 'password',
|
||||
name: 'value',
|
||||
message: 'Enter value for ' + key + ': ',
|
||||
validate: function (val) {
|
||||
return !val || val.length === 0
|
||||
? 'Please enter a value for ' + key
|
||||
: true
|
||||
}
|
||||
}]).then(function (result) {
|
||||
var value = result.value
|
||||
|
||||
var psqlUrl
|
||||
try {
|
||||
psqlUrl = process.env.DATABASE_URL || JSON.parse(fs.readFileSync('/etc/lamassu.json')).postgresql
|
||||
} catch (ex) {
|
||||
psqlUrl = 'psql://lamassu:lamassu@localhost/lamassu'
|
||||
}
|
||||
var db = pgp(psqlUrl)
|
||||
|
||||
return db.one('select data from user_config where type=$1', 'exchanges')
|
||||
.then(function (data) {
|
||||
var config = data.data
|
||||
config.exchanges.plugins.settings[plugin] = config.exchanges.plugins.settings[plugin] || {}
|
||||
config.exchanges.plugins.settings[plugin][key] = value
|
||||
return db.none('update user_config set data=$1 where type=$2', [config, 'exchanges'])
|
||||
})
|
||||
.then(function () {
|
||||
console.log('success')
|
||||
pgp.end()
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log(err.stack)
|
||||
pgp.end()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
"es6-promise": "^3.1.2",
|
||||
"ethereumjs-wallet": "^0.5.1",
|
||||
"express": "~3.4.7",
|
||||
"inquirer": "^0.8.0",
|
||||
"inquirer": "^1.0.0",
|
||||
"joi": "^5.1.0",
|
||||
"lamassu-bitcoinaverage": "~1.0.0",
|
||||
"lamassu-bitcoind": "^1.1.0",
|
||||
|
|
@ -37,6 +37,8 @@
|
|||
"node-uuid": "^1.4.2",
|
||||
"pg": "^4.5.1",
|
||||
"pg-promise": "^3.4.3",
|
||||
"prompt": "^1.0.0",
|
||||
"promptly": "^1.1.0",
|
||||
"web3": "^0.15.3",
|
||||
"wreck": "5.1.0"
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue