Nope. Somehow in my head it felt cleaner. Updated patched attached.

On Wed, Jul 23, 2014 at 1:18 AM, Jan Cholasta <jchol...@redhat.com> wrote:

> On 23.7.2014 01:01, Gabe Alford wrote:
>
>> Forgot about --trust-secret. Here is an updated patch.
>>
>>
>> On Mon, Jul 21, 2014 at 2:31 AM, Jan Cholasta <jchol...@redhat.com
>> <mailto:jchol...@redhat.com>> wrote:
>>
>>     On 21.7.2014 10:28, Martin Kosek wrote:
>>
>>         On 07/21/2014 09:56 AM, Jan Cholasta wrote:
>>
>>             Hi,
>>
>>             On 16.7.2014 05:48, Gabe Alford wrote:
>>
>>                 Hello,
>>
>>                 Adds AD admin and password to interactive commands.
>>                 https://fedorahosted.org/__freeipa/ticket/3034
>>
>>                 <https://fedorahosted.org/freeipa/ticket/3034>
>>
>>                 Thanks,
>>
>>                 Gabe
>>
>>
>>             I think that instead of making the parameters mandatory, you
>>             should instead set
>>             alwaysask=True on them.
>>
>>             Honza
>>
>>
>>         Trust can be established either with user+password options OR with
>>         --trust-secret option - i.e. you cannot use mandatory options
>>         nor alwaysask.
>>
>>
>>     Ah, right.
>>
>>
>>
>>         This would rather lead to interactive_prompt_callback checking
>>         if any of
>>         authentication method is passed and asking for them if they
>> aren't.
>>
>>
>>     +1
>>
>>
>>         Martin
>>
>>
>>
>>     --
>>     Jan Cholasta
>>
>>
>>
> I don't think using an extra function to update a value in a dictionary is
> very beneficial, is there a reason not to use "kw[X] =
> self.prompt_param(self.params[X])" directly?
>
> --
> Jan Cholasta
>
From cae886c1d3810d89feb3a2f26afcb6a38319005f Mon Sep 17 00:00:00 2001
From: Gabe <redhatri...@gmail.com>
Date: Wed, 23 Jul 2014 16:12:25 -0600
Subject: [PATCH] ipa trust-add command should be interactive

- Make ipa trust-add command interactive for realm_admin and realm_passwd
- Fix 'Active directory' typo to 'Active Directory'

https://fedorahosted.org/freeipa/ticket/3034
---
 ipalib/plugins/trust.py | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/ipalib/plugins/trust.py b/ipalib/plugins/trust.py
index fe1a76719b0e35136fb46d917bd998cdfd631695..7153253167001cca05c87d199c0843112d5333bd 100644
--- a/ipalib/plugins/trust.py
+++ b/ipalib/plugins/trust.py
@@ -435,7 +435,7 @@ sides.
         ),
         Password('realm_passwd?',
             cli_name='password',
-            label=_("Active directory domain administrator's password"),
+            label=_("Active Directory domain administrator's password"),
             confirm=False,
         ),
         Str('realm_server?',
@@ -511,6 +511,37 @@ sides.
 
         return result
 
+    def interactive_prompt_callback(self, kw):
+        """
+        Ensure that trust_type is prompted for if any reason there is no
+        default.
+
+        Also ensure that realm_admin is prompted for if --admin or
+        --trust-secret is not specified when 'ipa trust-add' is run on the
+        system.
+
+        Also ensure that realm_passwd is prompted for if --password or
+        --trust-secret is not specified when 'ipa trust-add' is run on the
+        system.
+        """
+
+        trust_secret = kw.get('trust_secret')
+        trust_type = kw.get('trust_type')
+        realm_admin = kw.get('realm_admin')
+        realm_passwd = kw.get('realm_passwd')
+
+        if trust_type is None:
+            kw['trust_type'] = self.prompt_param(self.params['trust_type'])
+
+        if trust_secret is None:
+            if realm_admin is None:
+                kw['realm_admin'] = self.prompt_param(
+                           self.params['realm_admin'])
+
+            if realm_passwd is None:
+                kw['realm_passwd'] = self.Backend.textui.prompt_password(
+                           self.params['realm_passwd'].label, confirm=False)
+
     def validate_options(self, *keys, **options):
         if not _bindings_installed:
             raise errors.NotFound(
-- 
2.0.0

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to