The Password parameter was set up to take passwords for users where you would want to confirm the entered password. There is a case in the entitlement plugin where we want to prompt for a password to an external service, so prompt just once. This adds a new option to Password, confirm, to decide what to do.

rob
>From 8e7a9c78b4dc3f5c37572c845ea69da3d1b7a33f Mon Sep 17 00:00:00 2001
From: Rob Crittenden <[email protected]>
Date: Wed, 24 Aug 2011 18:10:22 -0400
Subject: [PATCH] Add option to only prompt once for passwords, use in entitle_register

A Password param always prompted to confirm the entered password.
This doesn't make sense if you want to prompt for a password to another
system like we do with entitlements. This adds a new boolean option to
control the Password prompt parameter.

https://fedorahosted.org/freeipa/ticket/1695
---
 ipalib/cli.py             |   10 ++++++----
 ipalib/parameters.py      |    4 ++++
 ipalib/plugins/entitle.py |    1 +
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/ipalib/cli.py b/ipalib/cli.py
index 5e1365d..536fe2e 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -536,7 +536,7 @@ class textui(backend.Backend):
 
         If Default parameter is not None, user can enter an empty input instead
         of Yes/No answer. Value passed to Default is returned in that case.
-        
+
         If Default parameter is None, user is asked for Yes/No answer until
         a correct answer is provided. Answer is then returned.
 
@@ -568,7 +568,7 @@ class textui(backend.Backend):
             elif default is not None and data == u'':
                 return default
 
-    def prompt_password(self, label):
+    def prompt_password(self, label, confirm=True):
         """
         Prompt user for a password or read it in via stdin depending
         on whether there is a tty or not.
@@ -577,6 +577,8 @@ class textui(backend.Backend):
             if sys.stdin.isatty():
                 while True:
                     pw1 = getpass.getpass(u'%s: ' % unicode(label))
+                    if not confirm:
+                        return self.decode(pw1)
                     pw2 = getpass.getpass(
                         unicode(_('Enter %(label)s again to verify: ') % dict(label=label))
                     )
@@ -1050,7 +1052,7 @@ class cli(backend.Executioner):
                 (param.alwaysask and honor_alwaysask) or self.env.prompt_all:
                 if param.password:
                     kw[param.name] = self.Backend.textui.prompt_password(
-                        param.label
+                        param.label, param.confirm
                     )
                 elif param.autofill:
                     kw[param.name] = param.get_default(**kw)
@@ -1070,7 +1072,7 @@ class cli(backend.Executioner):
                             error = e.error
             elif param.password and kw.get(param.name, False) is True:
                 kw[param.name] = self.Backend.textui.prompt_password(
-                    param.label
+                    param.label, param.confirm
                 )
 
         for callback in getattr(cmd, 'INTERACTIVE_PROMPT_CALLBACKS', []):
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index e1c0b09..e7e7578 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -1369,6 +1369,10 @@ class Password(Str):
     A parameter for passwords (stored in the ``unicode`` type).
     """
 
+    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/ipalib/plugins/entitle.py b/ipalib/plugins/entitle.py
index 1c1b708..0543b0f 100644
--- a/ipalib/plugins/entitle.py
+++ b/ipalib/plugins/entitle.py
@@ -494,6 +494,7 @@ class entitle_register(LDAPCreate):
         Password('password',
             label=_('Password'),
             doc=_('Registration password'),
+            confirm=False,
         ),
     )
 
-- 
1.7.4

_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to