Skip to content

Commit 2223308

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "If no password in env or command line, try prompting."
2 parents fd1b118 + 39da32b commit 2223308

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎openstackclient/shell.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Command-line interface to the OpenStack APIs
2020
"""
2121

22+
import getpass
2223
import logging
2324
import os
2425
import sys
@@ -149,9 +150,20 @@ def authenticate_user(self):
149150
" either --os-username or env[OS_USERNAME]")
150151

151152
if not self.options.os_password:
152-
raise exc.CommandError(
153-
"You must provide a password via"
154-
" either --os-password or env[OS_PASSWORD]")
153+
# No password, if we've got a tty, try prompting for it
154+
if hasattr(sys.stdin, 'isatty') and sys.stdin.isatty():
155+
# Check for Ctl-D
156+
try:
157+
self.options.os_password = getpass.getpass()
158+
except EOFError:
159+
pass
160+
# No password because we did't have a tty or the
161+
# user Ctl-D when prompted?
162+
if not self.options.os_password:
163+
raise exc.CommandError(
164+
"You must provide a password via"
165+
" either --os-password, or env[OS_PASSWORD], "
166+
" or prompted response")
155167

156168
if not (self.options.os_tenant_id or self.options.os_tenant_name):
157169
raise exc.CommandError(

0 commit comments

Comments
 (0)