summaryrefslogtreecommitdiff
path: root/openstackclient/common/utils.py
diff options
context:
space:
mode:
authorTerry Howe <terrylhowe@gmail.com>2014-02-19 19:30:56 -0700
committerTerry Howe <terrylhowe@gmail.com>2014-02-21 14:42:22 -0700
commit033f27fe4dc4455c2f07978a273fd65faa653b67 (patch)
tree56126c4cd1a4d0aebbab6d0b7cfa6507ca3d195a /openstackclient/common/utils.py
parent2f5e8232aa07a9031231ad7b4678b7c52c1effc4 (diff)
downloadpython-openstackclient-033f27fe4dc4455c2f07978a273fd65faa653b67.tar.gz
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
Diffstat (limited to 'openstackclient/common/utils.py')
-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.")