403b09
From 829e708bf22e80373f1af167fbfb3e6b6bf8655e Mon Sep 17 00:00:00 2001
403b09
From: Martin Babinsky <mbabinsk@redhat.com>
403b09
Date: Mon, 18 Jul 2016 13:18:44 +0200
403b09
Subject: [PATCH] allow 'value' output param in commands without primary key
403b09
403b09
`PrimaryKey` output param works only for API objects that have primary keys,
403b09
otherwise it expects None (nothing is associated with this param). Since the
403b09
validation of command output was tightened durng thin client effort, some
403b09
commands not honoring this contract began to fail output validation.
403b09
403b09
A custom output was implemented for them to restore their functionality. It
403b09
should however be considered as a fix for broken commands and not used
403b09
further.
403b09
403b09
https://fedorahosted.org/freeipa/ticket/6037
403b09
https://fedorahosted.org/freeipa/ticket/6061
403b09
403b09
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
403b09
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
403b09
---
403b09
 API.txt                         | 10 +++++-----
403b09
 VERSION                         |  4 ++--
403b09
 ipalib/output.py                | 10 ++++++++++
403b09
 ipaserver/plugins/automember.py |  3 +++
403b09
 ipaserver/plugins/trust.py      |  2 ++
403b09
 5 files changed, 22 insertions(+), 7 deletions(-)
403b09
403b09
diff --git a/API.txt b/API.txt
403b09
index eb33c1fb7f94f5af45ec0b38fc7e45e484a1044e..535d8ec9a4990395207e2455a09a8c1bdef5529a 100644
403b09
--- a/API.txt
403b09
+++ b/API.txt
403b09
@@ -144,7 +144,7 @@ option: StrEnum('type', values=[u'group', u'hostgroup'])
403b09
 option: Str('version?')
403b09
 output: Entry('result')
403b09
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
403b09
-output: PrimaryKey('value')
403b09
+output: Output('value', type=[<type 'unicode'>])
403b09
 command: automember_default_group_set/1
403b09
 args: 0,6,3
403b09
 option: Flag('all', autofill=True, cli_name='all', default=False)
403b09
@@ -155,7 +155,7 @@ option: StrEnum('type', values=[u'group', u'hostgroup'])
403b09
 option: Str('version?')
403b09
 output: Entry('result')
403b09
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
403b09
-output: PrimaryKey('value')
403b09
+output: Output('value', type=[<type 'unicode'>])
403b09
 command: automember_default_group_show/1
403b09
 args: 0,4,3
403b09
 option: Flag('all', autofill=True, cli_name='all', default=False)
403b09
@@ -164,7 +164,7 @@ option: StrEnum('type', values=[u'group', u'hostgroup'])
403b09
 option: Str('version?')
403b09
 output: Entry('result')
403b09
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
403b09
-output: PrimaryKey('value')
403b09
+output: Output('value', type=[<type 'unicode'>])
403b09
 command: automember_del/1
403b09
 args: 1,2,3
403b09
 arg: Str('cn+', cli_name='automember_rule')
403b09
@@ -5574,7 +5574,7 @@ option: StrEnum('trust_type', autofill=True, cli_name='type', default=u'ad', val
403b09
 option: Str('version?')
403b09
 output: Entry('result')
403b09
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
403b09
-output: PrimaryKey('value')
403b09
+output: Output('value', type=[<type 'unicode'>])
403b09
 command: trustconfig_show/1
403b09
 args: 0,5,3
403b09
 option: Flag('all', autofill=True, cli_name='all', default=False)
403b09
@@ -5584,7 +5584,7 @@ option: StrEnum('trust_type', autofill=True, cli_name='type', default=u'ad', val
403b09
 option: Str('version?')
403b09
 output: Entry('result')
403b09
 output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
403b09
-output: PrimaryKey('value')
403b09
+output: Output('value', type=[<type 'unicode'>])
403b09
 command: trustdomain_add/1
403b09
 args: 2,8,3
403b09
 arg: Str('trustcn', cli_name='trust')
403b09
diff --git a/VERSION b/VERSION
403b09
index 0559741451a858dd0adfa99a8bf653261d771601..ca489965050f32d2d8987dfd251ec2b2a0ba1768 100644
403b09
--- a/VERSION
403b09
+++ b/VERSION
403b09
@@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000
403b09
 #                                                      #
403b09
 ########################################################
403b09
 IPA_API_VERSION_MAJOR=2
403b09
-IPA_API_VERSION_MINOR=210
403b09
-# Last change: Add --ca option to cert-status
403b09
+IPA_API_VERSION_MINOR=211
403b09
+# Last change: mbabinsk: allow 'value' output param in commands without primary key
403b09
diff --git a/ipalib/output.py b/ipalib/output.py
403b09
index 19dd9adadeb8521caf9f0dc52981ce57a7f0c8b6..b104584631629f33280164dd1d23922d21ddea49 100644
403b09
--- a/ipalib/output.py
403b09
+++ b/ipalib/output.py
403b09
@@ -217,3 +217,13 @@ simple_value = (
403b09
     Output('result', bool, _('True means the operation was successful')),
403b09
     Output('value', unicode, flags=['no_display']),
403b09
 )
403b09
+
403b09
+# custom shim for commands like `trustconfig-show`,
403b09
+# `automember-default-group-*` which put stuff into output['value'] despite not
403b09
+# having primary key themselves. Designing commands like this is not a very
403b09
+# good practice, so please do not use this for new code.
403b09
+simple_entry = (
403b09
+    summary,
403b09
+    Entry('result'),
403b09
+    Output('value', unicode, flags=['no_display']),
403b09
+)
403b09
diff --git a/ipaserver/plugins/automember.py b/ipaserver/plugins/automember.py
403b09
index dfa8498a6bd44352d854bff7f8eedaba8f731eef..8e9356a9d30c98b7c72735ffb9ac05c672546a0d 100644
403b09
--- a/ipaserver/plugins/automember.py
403b09
+++ b/ipaserver/plugins/automember.py
403b09
@@ -586,6 +586,7 @@ class automember_default_group_set(LDAPUpdate):
403b09
         ),
403b09
     ) + group_type
403b09
     msg_summary = _('Set default (fallback) group for automember "%(value)s"')
403b09
+    has_output = output.simple_entry
403b09
 
403b09
     def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
403b09
         dn = DN(('cn', options['type']), api.env.container_automember,
403b09
@@ -609,6 +610,7 @@ class automember_default_group_remove(LDAPUpdate):
403b09
 
403b09
     takes_options = group_type
403b09
     msg_summary = _('Removed default (fallback) group for automember "%(value)s"')
403b09
+    has_output = output.simple_entry
403b09
 
403b09
     def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
403b09
         dn = DN(('cn', options['type']), api.env.container_automember,
403b09
@@ -644,6 +646,7 @@ class automember_default_group_show(LDAPRetrieve):
403b09
     obj_name = 'automember_default_group'
403b09
 
403b09
     takes_options = group_type
403b09
+    has_output = output.simple_entry
403b09
 
403b09
     def pre_callback(self, ldap, dn, attrs_list, *keys, **options):
403b09
         dn = DN(('cn', options['type']), api.env.container_automember,
403b09
diff --git a/ipaserver/plugins/trust.py b/ipaserver/plugins/trust.py
403b09
index 8536202b9b785507bd27b3c7b1896b721f8c5927..d4676bd57054043edd07da5ec3321d755babf35c 100644
403b09
--- a/ipaserver/plugins/trust.py
403b09
+++ b/ipaserver/plugins/trust.py
403b09
@@ -1288,6 +1288,7 @@ class trustconfig_mod(LDAPUpdate):
403b09
 
403b09
     takes_options = LDAPUpdate.takes_options + (_trust_type_option,)
403b09
     msg_summary = _('Modified "%(value)s" trust configuration')
403b09
+    has_output = output.simple_entry
403b09
 
403b09
     def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
403b09
         self.obj._normalize_groupdn(entry_attrs)
403b09
@@ -1310,6 +1311,7 @@ class trustconfig_show(LDAPRetrieve):
403b09
     __doc__ = _('Show global trust configuration.')
403b09
 
403b09
     takes_options = LDAPRetrieve.takes_options + (_trust_type_option,)
403b09
+    has_output = output.simple_entry
403b09
 
403b09
     def execute(self, *keys, **options):
403b09
         result = super(trustconfig_show, self).execute(*keys, **options)
403b09
-- 
403b09
2.7.4
403b09