Read MaxCtrl password from stdin when none provided

When the -p parameter is given without an argument, the password is read
from the command line. This allows passwords to be given to MaxCtrl in a
safer manner.
This commit is contained in:
Markus Mäkelä
2018-02-25 18:06:52 +02:00
parent b8df0dfc02
commit 2df47d8999
4 changed files with 16 additions and 2 deletions

View File

@ -17,6 +17,7 @@ var Table = require('cli-table');
var consoleLib = require('console')
var os = require('os')
var fs = require('fs')
var readlineSync = require('readline-sync')
module.exports = function() {
@ -27,6 +28,13 @@ module.exports = function() {
// servers.
this.maxctrl = function(argv, cb) {
// No password given, ask it from the command line
if (argv.p == '') {
argv.p = readlineSync.question('Enter password: ', {
hideEchoBack: true
})
}
// Split the hostnames, separated by commas
argv.hosts = argv.hosts.split(',')
@ -209,7 +217,7 @@ module.exports = function() {
base = 'https://'
}
return base + argv.user + ':' + argv.password + '@' + host + '/v1/' + endpoint
return base + argv.u + ':' + argv.p + '@' + host + '/v1/' + endpoint
}
this.OK = function() {