Forgot about --trust-secret. Here is an updated patch.

On Mon, Jul 21, 2014 at 2:31 AM, Jan Cholasta <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
>>>>
>>>> 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
>
From 3023813d41b416d3b0676e829a0f0f85a3c7c502 Mon Sep 17 00:00:00 2001
From: Gabe <redhatri...@gmail.com>
Date: Tue, 22 Jul 2014 16:49:55 -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 | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/ipalib/plugins/trust.py b/ipalib/plugins/trust.py
index fe1a76719b0e35136fb46d917bd998cdfd631695..94bb4767defc95689593cf2528c9c5b84bf6fefb 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,40 @@ 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.
+        """
+
+        def set_from_prompt(param):
+            value = self.prompt_param(self.params[param])
+            update = {param: value}
+            kw.update(update)
+
+        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:
+            set_from_prompt('trust_type')
+
+        if trust_secret is None:
+            if realm_admin is None:
+                set_from_prompt('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