From aca3d65bbba6187a0730e6a102158f999985f85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 17 Apr 2019 09:34:01 +0300 Subject: [PATCH] MXS-2381: Add `alter user` The `alter user` command makes password changes easier and keeps the usage consistent across types in MaxScale. --- maxctrl/lib/alter.js | 22 ++++++++++++++++++++++ maxctrl/test/alter.js | 12 ++++++++++++ 2 files changed, 34 insertions(+) diff --git a/maxctrl/lib/alter.js b/maxctrl/lib/alter.js index 2c6294e26..88bd3eee8 100644 --- a/maxctrl/lib/alter.js +++ b/maxctrl/lib/alter.js @@ -135,6 +135,28 @@ exports.builder = function(yargs) { return updateValue(host, 'maxscale', 'data.attributes.parameters.' + argv.key, argv.value) }) }) + .command('user ', 'Alter admin user passwords', function(yargs) { + return yargs.epilog('Changes the password for a user. To change the user type, destroy the user and then create it again.') + .usage('Usage: alter user ') + }, function(argv) { + maxctrl(argv, function(host) { + + var user = { + 'data': { + 'id': argv.name, + 'type': 'inet', + 'attributes': { + 'password': argv.password + } + } + } + + return getJson(host, 'users/inet/' + argv.name) + .then((res) => user.data.attributes.account = res.data.attributes.account) + .then(() => doRequest(host, 'users/inet/' + argv.name, null, {method: 'DELETE'})) + .then(() => doRequest(host, 'users/inet', null, {method: 'POST', body: user})) + }) + }) .usage('Usage: alter ') .help() .command('*', 'the default command', {}, function(argv) { diff --git a/maxctrl/test/alter.js b/maxctrl/test/alter.js index a0d45b3f5..14fcf62df 100644 --- a/maxctrl/test/alter.js +++ b/maxctrl/test/alter.js @@ -108,5 +108,17 @@ describe("Alter Commands", function() { .should.be.rejected }) + it('creates user', function() { + return verifyCommand('create user testuser test', 'users/inet/testuser') + }) + + it('alters the password of a user', function() { + return verifyCommand('alter user testuser test2', 'users/inet/testuser') + }) + + it('destroys the altered user', function() { + return doCommand('destroy user testuser') + }) + after(stopMaxScale) });