summaryrefslogtreecommitdiff
path: root/glanceclient/shell.py
diff options
context:
space:
mode:
authorJohn Trowbridge <trown@redhat.com>2014-08-15 17:04:27 -0400
committerJohn Trowbridge <trown@redhat.com>2014-10-23 18:31:36 +0000
commit751e064761e878a10007541dfec00def9037c5e9 (patch)
tree981bbc1349e4a1544fd5a4219c68b85d3160257d /glanceclient/shell.py
parentcfe06235207d50d6d36b3d8b3e87608412038c80 (diff)
downloadpython-glanceclient-751e064761e878a10007541dfec00def9037c5e9.tar.gz
Adds tty password entry for glanceclient
Added functionality from keystoneclient to fallback to the tty for password entry if no password is given via the environment or the --os-password option. Change-Id: I096e81b61d7f499cbda300abdc14430928d18491 Closes-Bug: 1357549
Diffstat (limited to 'glanceclient/shell.py')
-rw-r--r--glanceclient/shell.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/glanceclient/shell.py b/glanceclient/shell.py
index 92de22e..01743e2 100644
--- a/glanceclient/shell.py
+++ b/glanceclient/shell.py
@@ -21,6 +21,7 @@ from __future__ import print_function
import argparse
import copy
+import getpass
import json
import logging
import os
@@ -439,10 +440,21 @@ class OpenStackImagesShell(object):
"env[OS_USERNAME]"))
if not args.os_password:
- raise exc.CommandError(
- _("You must provide a password via"
- " either --os-password or "
- "env[OS_PASSWORD]"))
+ # No password, If we've got a tty, try prompting for it
+ if hasattr(sys.stdin, 'isatty') and sys.stdin.isatty():
+ # Check for Ctl-D
+ try:
+ args.os_password = getpass.getpass('OS Password: ')
+ except EOFError:
+ pass
+ # No password because we didn't have a tty or the
+ # user Ctl-D when prompted.
+ if not args.os_password:
+ raise exc.CommandError(
+ _("You must provide a password via "
+ "either --os-password, "
+ "env[OS_PASSWORD], "
+ "or prompted response"))
# Validate password flow auth
project_info = (args.os_tenant_name or