From 2df47d89999fde3e4821addc231243b07de1c64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sun, 25 Feb 2018 18:06:52 +0200 Subject: [PATCH] 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. --- .../Release-Notes/MaxScale-2.2.3-Release-Notes.md | 5 +++++ maxctrl/lib/common.js | 10 +++++++++- maxctrl/lib/core.js | 2 +- maxctrl/package.json | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md b/Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md index c7c1d4f58..2a129c12a 100644 --- a/Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md +++ b/Documentation/Release-Notes/MaxScale-2.2.3-Release-Notes.md @@ -24,6 +24,11 @@ error as scripts most often do not have an actual terminal that control the process. This means that passwords and other commands can be passed to MaxAdmin without a controlling terminal. +### MaxCtrl password input + +MaxCtrl can now query the password from the user. This allows passwords to be +given without giving them as process arguments. + ## Dropped Features ## New Features diff --git a/maxctrl/lib/common.js b/maxctrl/lib/common.js index 5f2ad151c..cab6d9057 100644 --- a/maxctrl/lib/common.js +++ b/maxctrl/lib/common.js @@ -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() { diff --git a/maxctrl/lib/core.js b/maxctrl/lib/core.js index 85391111c..c3bd62a1a 100644 --- a/maxctrl/lib/core.js +++ b/maxctrl/lib/core.js @@ -31,7 +31,7 @@ program }) .option('p', { alias: 'password', - describe: 'Password for the user', + describe: 'Password for the user. To input the password manually, give -p as the last argument or use --password=\'\'', default: 'mariadb', type: 'string' }) diff --git a/maxctrl/package.json b/maxctrl/package.json index 3ae3c241e..7e42d4a67 100644 --- a/maxctrl/package.json +++ b/maxctrl/package.json @@ -19,6 +19,7 @@ "cli-table": "^0.3.1", "lodash": "^4.17.4", "lodash-getpath": "^0.2.4", + "readline-sync": "^1.4.9", "request": "^2.81.0", "request-promise-native": "^1.0.3", "yargs": "^8.0.2"