From 033f27fe4dc4455c2f07978a273fd65faa653b67 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Wed, 19 Feb 2014 19:30:56 -0700 Subject: Add ability to prompt for passwords for user create and set * Add get_password method to the utilities * Add --password-prompt option * Call the get_password method if a prompt is requested * Various tests Change-Id: I1786ad531e2a2fbcc21b8bc86aac0ccd7985995a Closes-Bug: 1100116 --- openstackclient/common/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'openstackclient/common') diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 94ea2225..7cd877ef 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -15,6 +15,7 @@ """Common client utilities""" +import getpass import logging import os import six @@ -229,3 +230,18 @@ def get_effective_log_level(): for handler in root_log.handlers: min_log_lvl = min(min_log_lvl, handler.level) return min_log_lvl + + +def get_password(stdin): + if hasattr(stdin, 'isatty') and stdin.isatty(): + try: + while True: + first_pass = getpass.getpass("User password: ") + second_pass = getpass.getpass("Repeat user password: ") + if first_pass == second_pass: + return first_pass + print("The passwords entered were not the same") + except EOFError: # Ctl-D + raise exceptions.CommandError("Error reading password.") + raise exceptions.CommandError("There was a request to be prompted for a" + " password and a terminal was not detected.") -- cgit v1.2.1