Blob Blame History Raw
From c7b4c108ddd76d5ac02e2242a7eccb3acf3efce5 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jcholast@redhat.com>
Date: Mon, 8 Aug 2016 13:09:39 +0200
Subject: [PATCH] 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>
---
 ipaclient/remote_plugins/schema.py | 2 +-
 ipalib/parameters.py               | 6 ++----
 ipaserver/plugins/otptoken.py      | 4 ----
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py
index cd1d5d607978899254325f634ccec91d2c92f59b..0301e54127dc236ebc14e1409484626f1427800d 100644
--- a/ipaclient/remote_plugins/schema.py
+++ b/ipaclient/remote_plugins/schema.py
@@ -155,7 +155,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
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 1581b7dcac5259e5c4a127e2a38e13335002b204..6917c8d4fc117b47bddc11fbf3ea379e3c537ea4 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -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
diff --git a/ipaserver/plugins/otptoken.py b/ipaserver/plugins/otptoken.py
index 56b8c911b3492de9342946cd3e47681e99a5abef..39012e2f9106c33c520e19f14331fc440333015a 100644
--- a/ipaserver/plugins/otptoken.py
+++ b/ipaserver/plugins/otptoken.py
@@ -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
-- 
2.7.4