summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-02-22 06:00:18 +0000
committerGerrit Code Review <review@openstack.org>2014-02-22 06:00:18 +0000
commit034a9d158f27bb9bd1a7430c09d1826196215093 (patch)
treefc88f06a264bcc19847bedda75213846a4f65a75 /openstackclient/common
parent8b494f08b2d60b487b37de6603349db66496b955 (diff)
parent033f27fe4dc4455c2f07978a273fd65faa653b67 (diff)
downloadpython-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.py16
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.")