[Freeipa-devel] [PATCH] 0133 Use standard_list_of_entries for trust-resolve
Alexander Bokovoy
abokovoy at redhat.com
Wed Jan 15 17:24:00 UTC 2014
On Wed, 15 Jan 2014, Alexander Bokovoy wrote:
> Hi!
>
> When looking into https://fedorahosted.org/freeipa/ticket/4113, I
> decided to use output.standard_list_of_entries instead of a locally
> defined list of entries. This solves the problem with wrong exit code in
> CLI when non-resolvable SID is given, but only for a single SID. If
> multiple SID specified and some of them were not resolved, the exit code
> will still be 0 (success) but truncated flag will be set. This
> corresponds to the framework behavior in other cases.
Thanks to Sumit, here is updated patch because I forgot to run makeapi
;(
:)
--
/ Alexander Bokovoy
-------------- next part --------------
>From 972afcc0a23f067249c505824377581c28812733 Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <abokovoy at redhat.com>
Date: Wed, 15 Jan 2014 17:51:25 +0200
Subject: [PATCH 2/2] trust-resolve: improve output by using
standard_list_of_entries
Use output.standard_list_of_entries instead of own output format
gives benefit of returning proper process exit code in CLI.
https://fedorahosted.org/freeipa/ticket/4113
---
API.txt | 5 ++++-
ipalib/plugins/trust.py | 12 +++++++-----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/API.txt b/API.txt
index a6c3aed..fc5cbc6 100644
--- a/API.txt
+++ b/API.txt
@@ -3666,12 +3666,15 @@ output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an LDA
output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
output: Output('value', <type 'unicode'>, None)
command: trust_resolve
-args: 0,4,1
+args: 0,4,4
option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui')
option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui')
option: Str('sids+', csv=True)
option: Str('version?', exclude='webui')
+output: Output('count', <type 'int'>, None)
output: ListOfEntries('result', (<type 'list'>, <type 'tuple'>), Gettext('A list of LDAP entries', domain='ipa', localedir=None))
+output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), None)
+output: Output('truncated', <type 'bool'>, None)
command: trust_show
args: 1,4,3
arg: Str('cn', attribute=True, cli_name='realm', multivalue=False, primary_key=True, query=True, required=True)
diff --git a/ipalib/plugins/trust.py b/ipalib/plugins/trust.py
index 3d412c9..3809f8b 100644
--- a/ipalib/plugins/trust.py
+++ b/ipalib/plugins/trust.py
@@ -992,14 +992,13 @@ class trust_resolve(Command):
Str('sid', label= _('SID')),
)
- has_output = (
- output.ListOfEntries('result'),
- )
+ has_output = output.standard_list_of_entries
+ msg_summary = _('Resolved %(count)d security identifiers')
def execute(self, *keys, **options):
result = list()
if not _nss_idmap_installed:
- return dict(result=result)
+ return dict(result=result, count=0, truncated=True)
try:
sids = map(lambda x: str(x), options['sids'])
xlate = pysss_nss_idmap.getnamebysid(sids)
@@ -1012,7 +1011,10 @@ class trust_resolve(Command):
except ValueError, e:
pass
- return dict(result=result)
+ len_sids = len(options['sids'])
+ len_result = len(result)
+ truncated = len_sids != len_result
+ return dict(result=result, count=len_result, truncated=truncated)
api.register(trust_resolve)
--
1.8.4.2
More information about the Freeipa-devel
mailing list