Skip to content

Commit 4a5a34d

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Support non-interactive user password update"
2 parents 9317df0 + 5cbecc1 commit 4a5a34d

3 files changed

Lines changed: 53 additions & 2 deletions

File tree

openstackclient/identity/v3/user.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,41 @@ def get_parser(self, prog_name):
392392
metavar='<new-password>',
393393
help='New user password'
394394
)
395+
parser.add_argument(
396+
'--original-password',
397+
metavar='<original-password>',
398+
help='Original user password'
399+
)
395400
return parser
396401

397402
@utils.log_method(log)
398403
def take_action(self, parsed_args):
399404
identity_client = self.app.client_manager.identity
400405

401-
current_password = utils.get_password(
402-
self.app.stdin, prompt="Current Password:", confirm=False)
406+
# FIXME(gyee): there are two scenarios:
407+
#
408+
# 1. user update password for himself
409+
# 2. admin update password on behalf of the user. This is an unlikely
410+
# scenario because that will require admin knowing the user's
411+
# original password which is forbidden under most security
412+
# policies.
413+
#
414+
# Of the two scenarios above, user either authenticate using its
415+
# original password or an authentication token. For scenario #1,
416+
# if user is authenticating with its original password (i.e. passing
417+
# --os-password argument), we can just make use of it instead of using
418+
# --original-password or prompting. For scenario #2, admin will need
419+
# to specify --original-password option or this won't work because
420+
# --os-password is the admin's own password. In the future if we stop
421+
# supporting scenario #2 then we can just do this.
422+
#
423+
# current_password = (parsed_args.original_password or
424+
# self.app.cloud.password)
425+
#
426+
current_password = parsed_args.original_password
427+
if current_password is None:
428+
current_password = utils.get_password(
429+
self.app.stdin, prompt="Current Password:", confirm=False)
403430

404431
password = parsed_args.password
405432
if password is None:

openstackclient/tests/identity/v3/test_user.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,25 @@ def test_user_create_password_prompt(self):
10951095
current_pass, new_pass
10961096
)
10971097

1098+
def test_user_password_change_no_prompt(self):
1099+
current_pass = 'old_pass'
1100+
new_pass = 'new_pass'
1101+
arglist = [
1102+
'--password', new_pass,
1103+
'--original-password', current_pass,
1104+
]
1105+
verifylist = [
1106+
('password', new_pass),
1107+
('original_password', current_pass),
1108+
]
1109+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1110+
1111+
self.cmd.take_action(parsed_args)
1112+
1113+
self.users_mock.update_password.assert_called_with(
1114+
current_pass, new_pass
1115+
)
1116+
10981117

10991118
class TestUserShow(TestUser):
11001119

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Support non-interactive user password update
5+
[Bug `1531360 <https://bugs.launchpad.net/bugs/1531360>`_]

0 commit comments

Comments
 (0)