On Mon, 2011-02-07 at 10:38 +0100, Jan Zelený wrote: > Martin Kosek <mko...@redhat.com> wrote: > > This patch adds a proper summary text to HBAC command which is > > then printed out in CLI. Now, HBAC plugin output is consistent > > with other plugins. > > > > https://fedorahosted.org/freeipa/ticket/596 > > I believe API.txt should be updated (you change hbacrule_enable and > hbacrule_disable return values), so NACK for now. > > Jan
Patch has been rebased, API.txt updated along with some minor changes to achieve consistency between HBAC plugins. All tests pass. Martin
>From 3094da14dff0efb628259ce04aadcb0890349517 Mon Sep 17 00:00:00 2001 From: Martin Kosek <mko...@redhat.com> Date: Fri, 4 Feb 2011 14:03:30 +0100 Subject: [PATCH] HBAC plugin inconsistent output This patch adds a proper summary text to HBAC command which is then printed out in CLI. Now, HBAC plugin output is consistent with other plugins. https://fedorahosted.org/freeipa/ticket/596 --- API.txt | 12 +++++--- ipalib/plugins/hbacrule.py | 37 ++++++++++++++++++------- ipalib/plugins/hbacsvc.py | 14 +++++++--- ipalib/plugins/hbacsvcgroup.py | 10 +++--- tests/test_xmlrpc/test_hbacsvcgroup_plugin.py | 12 ++++---- 5 files changed, 56 insertions(+), 29 deletions(-) diff --git a/API.txt b/API.txt index 22578e9927f36fc24d34150c62b79afb7bbbde3f..826944bc81cc97dd3b74e5471b1e54aa70ec34a9 100644 --- a/API.txt +++ b/API.txt @@ -988,13 +988,17 @@ output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), 'User-friendly output: Output('result', <type 'dict'>, 'list of deletions that failed') output: Output('value', <type 'unicode'>, "The primary_key value of the entry, e.g. 'jdoe' for a user") command: hbacrule_disable -args: 1,0,1 +args: 1,0,3 arg: Str('cn', attribute=True, cli_name='name', label=Gettext('Rule name', domain='ipa', localedir=None), multivalue=False, primary_key=True, query=True, required=True) -output: Output('result', None, None) +output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), 'User-friendly description of action performed') +output: Output('result', <type 'bool'>, 'True means the operation was successful') +output: Output('value', <type 'unicode'>, "The primary_key value of the entry, e.g. 'jdoe' for a user") command: hbacrule_enable -args: 1,0,1 +args: 1,0,3 arg: Str('cn', attribute=True, cli_name='name', label=Gettext('Rule name', domain='ipa', localedir=None), multivalue=False, primary_key=True, query=True, required=True) -output: Output('result', None, None) +output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), 'User-friendly description of action performed') +output: Output('result', <type 'bool'>, 'True means the operation was successful') +output: Output('value', <type 'unicode'>, "The primary_key value of the entry, e.g. 'jdoe' for a user") command: hbacrule_find args: 1,12,4 arg: Str('criteria?') diff --git a/ipalib/plugins/hbacrule.py b/ipalib/plugins/hbacrule.py index b834a141061a6a5b64dba97b24a32f77824ef0a4..cb4dbb4f3756272ce8b79f584af74c5e6b2b839d 100644 --- a/ipalib/plugins/hbacrule.py +++ b/ipalib/plugins/hbacrule.py @@ -211,6 +211,9 @@ class hbacrule_add(LDAPCreate): """ Create a new HBAC rule. """ + + msg_summary = _('Added HBAC rule "%(value)s"') + def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options): # HBAC rules are enabled by default entry_attrs['ipaenabledflag'] = 'TRUE' @@ -224,6 +227,8 @@ class hbacrule_del(LDAPDelete): Delete an HBAC rule. """ + msg_summary = _('Deleted HBAC rule "%(value)s"') + api.register(hbacrule_del) @@ -232,6 +237,8 @@ class hbacrule_mod(LDAPUpdate): Modify an HBAC rule. """ + msg_summary = _('Modified HBAC rule "%(value)s"') + def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options): try: (dn, entry_attrs) = ldap.get_entry(dn, attrs_list) @@ -256,6 +263,10 @@ class hbacrule_find(LDAPSearch): Search for HBAC rules. """ + msg_summary = ngettext( + '%(count)d HBAC rule matched', '%(count)d HBAC rules matched', 0 + ) + api.register(hbacrule_find) @@ -271,6 +282,10 @@ class hbacrule_enable(LDAPQuery): """ Enable an HBAC rule. """ + + msg_summary = _('Enabled HBAC rule "%(value)s"') + has_output = output.standard_value + def execute(self, cn): ldap = self.obj.backend @@ -284,11 +299,10 @@ class hbacrule_enable(LDAPQuery): except errors.NotFound: self.obj.handle_not_found(cn) - return dict(result=True) - - def output_for_cli(self, textui, result, cn): - textui.print_name(self.name) - textui.print_dashed('Enabled HBAC rule "%s".' % cn) + return dict( + result=True, + value=cn, + ) api.register(hbacrule_enable) @@ -297,6 +311,10 @@ class hbacrule_disable(LDAPQuery): """ Disable an HBAC rule. """ + + msg_summary = _('Disabled HBAC rule "%(value)s"') + has_output = output.standard_value + def execute(self, cn): ldap = self.obj.backend @@ -310,11 +328,10 @@ class hbacrule_disable(LDAPQuery): except errors.NotFound: self.obj.handle_not_found(cn) - return dict(result=True) - - def output_for_cli(self, textui, result, cn): - textui.print_name(self.name) - textui.print_dashed('Disabled HBAC rule "%s".' % cn) + return dict( + result=True, + value=cn, + ) api.register(hbacrule_disable) diff --git a/ipalib/plugins/hbacsvc.py b/ipalib/plugins/hbacsvc.py index 282f927ca573432d96025c3d07a3561cc15b362f..3fe9f0fb301256e70494cc7764071279fea7507c 100644 --- a/ipalib/plugins/hbacsvc.py +++ b/ipalib/plugins/hbacsvc.py @@ -64,14 +64,14 @@ class hbacsvc(LDAPObject): Str('cn', cli_name='service', label=_('Service name'), - doc=_('HBAC Service'), + doc=_('HBAC service'), primary_key=True, normalizer=lambda value: value.lower(), ), Str('description?', cli_name='desc', label=_('Description'), - doc=_('Description of service'), + doc=_('HBAC service description'), ), ) @@ -82,7 +82,7 @@ class hbacsvc_add(LDAPCreate): """ Add a new HBAC service. """ - msg_summary = _('Added service "%(value)s"') + msg_summary = _('Added HBAC service "%(value)s"') api.register(hbacsvc_add) @@ -91,7 +91,7 @@ class hbacsvc_del(LDAPDelete): """ Delete an existing HBAC service. """ - msg_summary = _('Deleted service "%(value)s"') + msg_summary = _('Deleted HBAC service "%(value)s"') api.register(hbacsvc_del) @@ -101,6 +101,8 @@ class hbacsvc_mod(LDAPUpdate): Modify an HBAC service. """ + msg_summary = _('Modified HBAC service "%(value)s"') + api.register(hbacsvc_mod) @@ -109,6 +111,10 @@ class hbacsvc_find(LDAPSearch): Search for HBAC services. """ + msg_summary = ngettext( + '%(count)d HBAC service matched', '%(count)d HBAC services matched', 0 + ) + api.register(hbacsvc_find) diff --git a/ipalib/plugins/hbacsvcgroup.py b/ipalib/plugins/hbacsvcgroup.py index e2568076f828527b1b01d0dc3fb7e21d9007467f..0a66697d9bdaf145c2c05823558ef761aa43a8fa 100644 --- a/ipalib/plugins/hbacsvcgroup.py +++ b/ipalib/plugins/hbacsvcgroup.py @@ -61,7 +61,7 @@ class hbacsvcgroup(LDAPObject): 'member': ['hbacsvc'], } - label = _('HBAC Service Groups') + label = _('HBAC service Groups') takes_params = ( Str('cn', @@ -84,7 +84,7 @@ class hbacsvcgroup_add(LDAPCreate): """ Add a new HBAC services group. """ - msg_summary = _('Added HBAC Service group "%(value)s"') + msg_summary = _('Added HBAC service group "%(value)s"') api.register(hbacsvcgroup_add) @@ -93,7 +93,7 @@ class hbacsvcgroup_del(LDAPDelete): """ Delete an HBAC services group. """ - msg_summary = _('Deleted HBAC Service group "%(value)s"') + msg_summary = _('Deleted HBAC service group "%(value)s"') api.register(hbacsvcgroup_del) @@ -102,7 +102,7 @@ class hbacsvcgroup_mod(LDAPUpdate): """ Modify an HBAC services group. """ - msg_summary = _('Modified HBAC Service group "%(value)s"') + msg_summary = _('Modified HBAC service group "%(value)s"') api.register(hbacsvcgroup_mod) @@ -112,7 +112,7 @@ class hbacsvcgroup_find(LDAPSearch): Search for an HBAC services group. """ msg_summary = ngettext( - '%(count)d group matched', '%(count)d groups matched', 0 + '%(count)d HBAC service group matched', '%(count)d HBAC service groups matched', 0 ) api.register(hbacsvcgroup_find) diff --git a/tests/test_xmlrpc/test_hbacsvcgroup_plugin.py b/tests/test_xmlrpc/test_hbacsvcgroup_plugin.py index c5c02f11c343e72f8af393a10fb4246f57b54d12..d2fa7cc8be408812a42b09f9b50ff21128963bb5 100644 --- a/tests/test_xmlrpc/test_hbacsvcgroup_plugin.py +++ b/tests/test_xmlrpc/test_hbacsvcgroup_plugin.py @@ -71,7 +71,7 @@ class test_hbacsvcgroup(Declarative): ), expected=dict( value=hbacsvcgroup1, - summary=u'Added HBAC Service group "testhbacsvcgroup1"', + summary=u'Added HBAC service group "testhbacsvcgroup1"', result=dict( dn=dn1, cn=[hbacsvcgroup1], @@ -101,7 +101,7 @@ class test_hbacsvcgroup(Declarative): ), expected=dict( value=hbacsvc1, - summary=u'Added service "%s"' % hbacsvc1, + summary=u'Added HBAC service "%s"' % hbacsvc1, result=dict( dn=hbacsvc_dn1, cn=[hbacsvc1], @@ -157,7 +157,7 @@ class test_hbacsvcgroup(Declarative): expected=dict( count=1, truncated=False, - summary=u'1 group matched', + summary=u'1 HBAC service group matched', result=[ { 'dn': dn1, @@ -177,7 +177,7 @@ class test_hbacsvcgroup(Declarative): ), expected=dict( value=hbacsvcgroup1, - summary=u'Modified HBAC Service group "testhbacsvcgroup1"', + summary=u'Modified HBAC service group "testhbacsvcgroup1"', result=dict( cn=[hbacsvcgroup1], description=[u'Updated hbacsvcgroup 1'], @@ -229,7 +229,7 @@ class test_hbacsvcgroup(Declarative): command=('hbacsvcgroup_del', [hbacsvcgroup1], {}), expected=dict( value=hbacsvcgroup1, - summary=u'Deleted HBAC Service group "testhbacsvcgroup1"', + summary=u'Deleted HBAC service group "testhbacsvcgroup1"', result=dict(failed=u''), ), ), @@ -240,7 +240,7 @@ class test_hbacsvcgroup(Declarative): command=('hbacsvc_del', [hbacsvc1], {}), expected=dict( value=hbacsvc1, - summary=u'Deleted service "%s"' % hbacsvc1, + summary=u'Deleted HBAC service "%s"' % hbacsvc1, result=dict(failed=u''), ), ) -- 1.7.4
_______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel