403b09
From b18c50fb6f596896b35b80178368762d8b9d4a56 Mon Sep 17 00:00:00 2001
403b09
From: Martin Babinsky <mbabinsk@redhat.com>
403b09
Date: Fri, 15 Jul 2016 12:38:00 +0200
403b09
Subject: [PATCH] trust-add: handle `--all/--raw` options properly
403b09
403b09
`trust-add` command did not handle these options correctly often resulting in
403b09
internal errors or mangled output. This patch implements a behavior which is
403b09
more in-line with the rest of the API commands.
403b09
403b09
https://fedorahosted.org/freeipa/ticket/6059
403b09
403b09
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
403b09
---
403b09
 ipaserver/plugins/trust.py | 41 +++++++++++++++++++++++++++--------------
403b09
 1 file changed, 27 insertions(+), 14 deletions(-)
403b09
403b09
diff --git a/ipaserver/plugins/trust.py b/ipaserver/plugins/trust.py
403b09
index d4676bd57054043edd07da5ec3321d755babf35c..f2e0b1ee4b261ddc4f29477f46b7f4027af18892 100644
403b09
--- a/ipaserver/plugins/trust.py
403b09
+++ b/ipaserver/plugins/trust.py
403b09
@@ -710,6 +710,25 @@ sides.
403b09
     msg_summary = _('Added Active Directory trust for realm "%(value)s"')
403b09
     msg_summary_existing = _('Re-established trust to domain "%(value)s"')
403b09
 
403b09
+    def _format_trust_attrs(self, result, **options):
403b09
+
403b09
+        # Format the output into human-readable values
403b09
+        attributes = int(result['result'].get('ipanttrustattributes', [0])[0])
403b09
+
403b09
+        if not options.get('raw', False):
403b09
+            result['result']['trusttype'] = [trust_type_string(
403b09
+                result['result']['ipanttrusttype'][0], attributes)]
403b09
+            result['result']['trustdirection'] = [trust_direction_string(
403b09
+                result['result']['ipanttrustdirection'][0])]
403b09
+            result['result']['truststatus'] = [trust_status_string(
403b09
+                result['verified'])]
403b09
+
403b09
+        if attributes:
403b09
+            result['result'].pop('ipanttrustattributes', None)
403b09
+
403b09
+        result['result'].pop('ipanttrustauthoutgoing', None)
403b09
+        result['result'].pop('ipanttrustauthincoming', None)
403b09
+
403b09
     def execute(self, *keys, **options):
403b09
         ldap = self.obj.backend
403b09
 
403b09
@@ -729,10 +748,15 @@ sides.
403b09
         else:
403b09
             created_range_type = old_range['result']['iparangetype'][0]
403b09
 
403b09
+        attrs_list = self.obj.default_attributes
403b09
+        if options.get('all', False):
403b09
+            attrs_list.append('*')
403b09
+
403b09
         trust_filter = "cn=%s" % result['value']
403b09
         (trusts, truncated) = ldap.find_entries(
403b09
                          base_dn=DN(self.api.env.container_trusts, self.api.env.basedn),
403b09
-                         filter=trust_filter)
403b09
+                         filter=trust_filter,
403b09
+                         attrs_list=attrs_list)
403b09
 
403b09
         result['result'] = entry_to_dict(trusts[0], **options)
403b09
 
403b09
@@ -761,20 +785,9 @@ sides.
403b09
                 # add_new_domains_from_trust() on its own.
403b09
                 fetch_trusted_domains_over_dbus(self.api, self.log, result['value'])
403b09
 
403b09
-        # Format the output into human-readable values
403b09
-        attributes = int(result['result'].get('ipanttrustattributes', [0])[0])
403b09
-        result['result']['trusttype'] = [trust_type_string(
403b09
-            result['result']['ipanttrusttype'][0], attributes)]
403b09
-        result['result']['trustdirection'] = [trust_direction_string(
403b09
-            result['result']['ipanttrustdirection'][0])]
403b09
-        result['result']['truststatus'] = [trust_status_string(
403b09
-            result['verified'])]
403b09
-        if attributes:
403b09
-            result['result'].pop('ipanttrustattributes', None)
403b09
-
403b09
+        # Format the output into human-readable values unless `--raw` is given
403b09
+        self._format_trust_attrs(result, **options)
403b09
         del result['verified']
403b09
-        result['result'].pop('ipanttrustauthoutgoing', None)
403b09
-        result['result'].pop('ipanttrustauthincoming', None)
403b09
 
403b09
         return result
403b09
 
403b09
-- 
403b09
2.7.4
403b09