From 71d2e1ad7782520362919a579ec1b459fe4c5238 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Thu, 7 Jul 2016 10:06:52 +1000 Subject: [PATCH] Add prompt parameter to Opt The prompt parameter is supposed to provide both an indication to loaders that it is ok to prompt the user for input for an option and also an appropriate message that can be used. It would be up to the loader whether it wanted to use that message or something it generated. This will allow os-client-config and openstackclient better control over the loading of sensitive authentication options. Related-Bug: #1519202 Change-Id: I7c39f25b78404950af6f6eaf21739be1c1ef9c6a --- keystoneauth1/loading/_plugins/identity/generic.py | 5 ++++- keystoneauth1/loading/_plugins/identity/v2.py | 5 ++++- keystoneauth1/loading/_plugins/identity/v3.py | 5 ++++- keystoneauth1/loading/opts.py | 6 +++++- .../notes/add-prompt-to-opt-d083acc357a7f07b.yaml | 10 ++++++++++ 5 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/add-prompt-to-opt-d083acc357a7f07b.yaml diff --git a/keystoneauth1/loading/_plugins/identity/generic.py b/keystoneauth1/loading/_plugins/identity/generic.py index e35acc1b..ab9b547e 100644 --- a/keystoneauth1/loading/_plugins/identity/generic.py +++ b/keystoneauth1/loading/_plugins/identity/generic.py @@ -46,6 +46,9 @@ class Password(loading.BaseGenericLoader): deprecated=[loading.Opt('user-name')]), loading.Opt('user-domain-id', help="User's domain id"), loading.Opt('user-domain-name', help="User's domain name"), - loading.Opt('password', secret=True, help="User's password"), + loading.Opt('password', + secret=True, + prompt='Password: ', + help="User's password"), ]) return options diff --git a/keystoneauth1/loading/_plugins/identity/v2.py b/keystoneauth1/loading/_plugins/identity/v2.py index 4b510f8f..aaacd153 100644 --- a/keystoneauth1/loading/_plugins/identity/v2.py +++ b/keystoneauth1/loading/_plugins/identity/v2.py @@ -44,7 +44,10 @@ class Password(loading.BaseV2Loader): deprecated=[loading.Opt('user-name')], help='Username to login with'), loading.Opt('user-id', help='User ID to login with'), - loading.Opt('password', secret=True, help='Password to use'), + loading.Opt('password', + secret=True, + prompt='Password: ', + help='Password to use'), ]) return options diff --git a/keystoneauth1/loading/_plugins/identity/v3.py b/keystoneauth1/loading/_plugins/identity/v3.py index 75e3d366..d48a2b94 100644 --- a/keystoneauth1/loading/_plugins/identity/v3.py +++ b/keystoneauth1/loading/_plugins/identity/v3.py @@ -47,7 +47,10 @@ class Password(loading.BaseV3Loader): _add_common_identity_options(options) options.extend([ - loading.Opt('password', secret=True, help="User's password"), + loading.Opt('password', + secret=True, + prompt='Password: ', + help="User's password"), ]) return options diff --git a/keystoneauth1/loading/opts.py b/keystoneauth1/loading/opts.py index 2220040f..a88e669c 100644 --- a/keystoneauth1/loading/opts.py +++ b/keystoneauth1/loading/opts.py @@ -57,6 +57,8 @@ class Opt(object): :param str metavar: The that should be printed in CLI help text. :param bool required: If the option is required to load the plugin. If a required option is not present loading should fail. + :param str prompt: If the option can be requested via a prompt (where + appropriate) set the string that should be used to prompt with. """ @positional() @@ -69,7 +71,8 @@ class Opt(object): deprecated=None, default=None, metavar=None, - required=False): + required=False, + prompt=None): if not callable(type): raise TypeError('type must be callable') @@ -85,6 +88,7 @@ class Opt(object): self.deprecated = [] if deprecated is None else deprecated self.default = default self.metavar = metavar + self.prompt = prompt # These are for oslo.config compat self.deprecated_opts = self.deprecated self.deprecated_for_removal = [] diff --git a/releasenotes/notes/add-prompt-to-opt-d083acc357a7f07b.yaml b/releasenotes/notes/add-prompt-to-opt-d083acc357a7f07b.yaml new file mode 100644 index 00000000..72bc114d --- /dev/null +++ b/releasenotes/notes/add-prompt-to-opt-d083acc357a7f07b.yaml @@ -0,0 +1,10 @@ +--- +prelude: > + Add the prompt parameter to loader Opts +features: + - The prompt parameter was added to the Opts provided by auth plugins. The + presence of the prompt parameter on an Option will indicate to plugin + loaders that it is ok to prompt the user for input for this parameter if + none is provided initially. Actual implementation of this prompting + mechanism will be handled by the individual loaders such as + os-client-config.