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
This commit is contained in:
Jamie Lennox 2016-07-07 10:06:52 +10:00
parent b2c8e247cd
commit 71d2e1ad77
5 changed files with 27 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -57,6 +57,8 @@ class Opt(object):
:param str metavar: The <metavar> 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 = []

View File

@ -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.