diff options
| author | Jenkins <jenkins@review.openstack.org> | 2014-02-22 06:00:18 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2014-02-22 06:00:18 +0000 |
| commit | 034a9d158f27bb9bd1a7430c09d1826196215093 (patch) | |
| tree | fc88f06a264bcc19847bedda75213846a4f65a75 /openstackclient/common | |
| parent | 8b494f08b2d60b487b37de6603349db66496b955 (diff) | |
| parent | 033f27fe4dc4455c2f07978a273fd65faa653b67 (diff) | |
| download | python-openstackclient-034a9d158f27bb9bd1a7430c09d1826196215093.tar.gz | |
Merge "Add ability to prompt for passwords for user create and set"
Diffstat (limited to 'openstackclient/common')
| -rw-r--r-- | openstackclient/common/utils.py | 16 |
1 files changed, 16 insertions, 0 deletions
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.") |
