diff options
author | Jamie Lennox <jamielennox@redhat.com> | 2015-04-15 09:36:10 +1000 |
---|---|---|
committer | Jamie Lennox <jamielennox@redhat.com> | 2015-05-02 14:09:22 +1000 |
commit | 17d51f771ea9b6210c00c946d16d94fedc3f9cc1 (patch) | |
tree | 10dac3e662baefd330520103143e2061084c289f /keystoneclient/auth | |
parent | 39b7f963f595ba3517c7e5540981bce356ec0e1b (diff) | |
download | python-keystoneclient-17d51f771ea9b6210c00c946d16d94fedc3f9cc1.tar.gz |
Prompt for password on CLI if not provided
load_from_argparse_arguments is very specifically for use with argparse.
We can therefore safely prompt for a password from the user if none is
provided and it won't affect config options or other loading mechanisms.
Change-Id: Ib76743b768c5f0eef756184f1da49613423298f0
Diffstat (limited to 'keystoneclient/auth')
-rw-r--r-- | keystoneclient/auth/identity/generic/password.py | 8 | ||||
-rw-r--r-- | keystoneclient/auth/identity/v2.py | 8 | ||||
-rw-r--r-- | keystoneclient/auth/identity/v3/password.py | 9 |
3 files changed, 25 insertions, 0 deletions
diff --git a/keystoneclient/auth/identity/generic/password.py b/keystoneclient/auth/identity/generic/password.py index 6790fe2..f1c8aa6 100644 --- a/keystoneclient/auth/identity/generic/password.py +++ b/keystoneclient/auth/identity/generic/password.py @@ -82,3 +82,11 @@ class Password(base.BaseGenericPlugin): options = super(Password, cls).get_options() options.extend(get_options()) return options + + @classmethod + def load_from_argparse_arguments(cls, namespace, **kwargs): + if not (kwargs.get('password') or namespace.os_password): + kwargs['password'] = utils.prompt_user_password() + + return super(Password, cls).load_from_argparse_arguments(namespace, + **kwargs) diff --git a/keystoneclient/auth/identity/v2.py b/keystoneclient/auth/identity/v2.py index 8eaa9c5..bed958b 100644 --- a/keystoneclient/auth/identity/v2.py +++ b/keystoneclient/auth/identity/v2.py @@ -145,6 +145,14 @@ class Password(Auth): return {'passwordCredentials': auth} @classmethod + def load_from_argparse_arguments(cls, namespace, **kwargs): + if not (kwargs.get('password') or namespace.os_password): + kwargs['password'] = utils.prompt_user_password() + + return super(Password, cls).load_from_argparse_arguments(namespace, + **kwargs) + + @classmethod def get_options(cls): options = super(Password, cls).get_options() diff --git a/keystoneclient/auth/identity/v3/password.py b/keystoneclient/auth/identity/v3/password.py index 7e432fa..d9cfa4a 100644 --- a/keystoneclient/auth/identity/v3/password.py +++ b/keystoneclient/auth/identity/v3/password.py @@ -13,6 +13,7 @@ from oslo_config import cfg from keystoneclient.auth.identity.v3 import base +from keystoneclient import utils __all__ = ['PasswordMethod', 'Password'] @@ -86,3 +87,11 @@ class Password(base.AuthConstructor): ]) return options + + @classmethod + def load_from_argparse_arguments(cls, namespace, **kwargs): + if not (kwargs.get('password') or namespace.os_password): + kwargs['password'] = utils.prompt_user_password() + + return super(Password, cls).load_from_argparse_arguments(namespace, + **kwargs) |