parameters: move the confirm kwarg to Param

Whether a parameter is treated like password is determined by the
`password` class attribute defined in the Param class. Whether the CLI will
asks for confirmation of a password parameter depends on the value of the
`confirm` kwarg of the Password class.

Move the `confirm` kwarg from the Password class to the Param class, so
that it can be used by any Param subclass which has the `password` class
attribute set to True.

This fixes confirmation of the --key option of otptoken-add, which is a
Bytes subclass with `password` set to True.

https://fedorahosted.org/freeipa/ticket/6174

Reviewed-By: Martin Basti <mbasti@redhat.com>
Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
Jan Cholasta
2016-08-08 13:09:39 +02:00
committed by David Kupka
parent 771dea5c6b
commit e9c1d21b9f
3 changed files with 3 additions and 9 deletions

View File

@@ -167,7 +167,7 @@ class _SchemaPlugin(object):
elif key in ('cli_metavar',
'cli_name'):
kwargs[key] = str(value)
elif key == 'confirm' and issubclass(cls, Password):
elif key == 'confirm':
kwargs[key] = value
elif key == 'default':
default = value

View File

@@ -377,6 +377,7 @@ class Param(ReadOnly):
parameter is not `required`
- sortorder: used to sort a list of parameters for Command. See
`Command.finalize()` for further information
- confirm: if password, ask for confirmation
"""
# This is a dummy type so that most of the functionality of Param can be
@@ -418,6 +419,7 @@ class Param(ReadOnly):
('cli_metavar', str, None),
('no_convert', bool, False),
('deprecated', bool, False),
('confirm', bool, True),
# The 'default' kwarg gets appended in Param.__init__():
# ('default', self.type, None),
@@ -1511,10 +1513,6 @@ class Password(Str):
password = True
kwargs = Str.kwargs + (
('confirm', bool, True),
)
def _convert_scalar(self, value, index=None):
if isinstance(value, (tuple, list)) and len(value) == 2:
(p1, p2) = value

View File

@@ -79,10 +79,6 @@ class OTPTokenKey(Bytes):
password = True
kwargs = Bytes.kwargs + (
('confirm', bool, True),
)
def _convert_scalar(self, value, index=None):
if isinstance(value, (tuple, list)) and len(value) == 2:
(p1, p2) = value