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
This commit is contained in:
Martin Kosek 2011-02-04 14:03:30 +01:00 committed by Rob Crittenden
parent a9dc175bc5
commit e5d57d237b
5 changed files with 56 additions and 29 deletions

12
API.txt
View File

@ -1035,13 +1035,17 @@ output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), 'User-friendly
output: Output('result', <type 'dict'>, 'list of deletions that failed') 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") output: Output('value', <type 'unicode'>, "The primary_key value of the entry, e.g. 'jdoe' for a user")
command: hbacrule_disable 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) 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 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) 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 command: hbacrule_find
args: 1,12,4 args: 1,12,4
arg: Str('criteria?') arg: Str('criteria?')

View File

@ -211,6 +211,9 @@ class hbacrule_add(LDAPCreate):
""" """
Create a new HBAC rule. Create a new HBAC rule.
""" """
msg_summary = _('Added HBAC rule "%(value)s"')
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options): def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
# HBAC rules are enabled by default # HBAC rules are enabled by default
entry_attrs['ipaenabledflag'] = 'TRUE' entry_attrs['ipaenabledflag'] = 'TRUE'
@ -224,6 +227,8 @@ class hbacrule_del(LDAPDelete):
Delete an HBAC rule. Delete an HBAC rule.
""" """
msg_summary = _('Deleted HBAC rule "%(value)s"')
api.register(hbacrule_del) api.register(hbacrule_del)
@ -232,6 +237,8 @@ class hbacrule_mod(LDAPUpdate):
Modify an HBAC rule. Modify an HBAC rule.
""" """
msg_summary = _('Modified HBAC rule "%(value)s"')
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options): def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
try: try:
(dn, entry_attrs) = ldap.get_entry(dn, attrs_list) (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
@ -256,6 +263,10 @@ class hbacrule_find(LDAPSearch):
Search for HBAC rules. Search for HBAC rules.
""" """
msg_summary = ngettext(
'%(count)d HBAC rule matched', '%(count)d HBAC rules matched', 0
)
api.register(hbacrule_find) api.register(hbacrule_find)
@ -271,6 +282,10 @@ class hbacrule_enable(LDAPQuery):
""" """
Enable an HBAC rule. Enable an HBAC rule.
""" """
msg_summary = _('Enabled HBAC rule "%(value)s"')
has_output = output.standard_value
def execute(self, cn): def execute(self, cn):
ldap = self.obj.backend ldap = self.obj.backend
@ -284,11 +299,10 @@ class hbacrule_enable(LDAPQuery):
except errors.NotFound: except errors.NotFound:
self.obj.handle_not_found(cn) self.obj.handle_not_found(cn)
return dict(result=True) return dict(
result=True,
def output_for_cli(self, textui, result, cn): value=cn,
textui.print_name(self.name) )
textui.print_dashed('Enabled HBAC rule "%s".' % cn)
api.register(hbacrule_enable) api.register(hbacrule_enable)
@ -297,6 +311,10 @@ class hbacrule_disable(LDAPQuery):
""" """
Disable an HBAC rule. Disable an HBAC rule.
""" """
msg_summary = _('Disabled HBAC rule "%(value)s"')
has_output = output.standard_value
def execute(self, cn): def execute(self, cn):
ldap = self.obj.backend ldap = self.obj.backend
@ -310,11 +328,10 @@ class hbacrule_disable(LDAPQuery):
except errors.NotFound: except errors.NotFound:
self.obj.handle_not_found(cn) self.obj.handle_not_found(cn)
return dict(result=True) return dict(
result=True,
def output_for_cli(self, textui, result, cn): value=cn,
textui.print_name(self.name) )
textui.print_dashed('Disabled HBAC rule "%s".' % cn)
api.register(hbacrule_disable) api.register(hbacrule_disable)

View File

@ -64,14 +64,14 @@ class hbacsvc(LDAPObject):
Str('cn', Str('cn',
cli_name='service', cli_name='service',
label=_('Service name'), label=_('Service name'),
doc=_('HBAC Service'), doc=_('HBAC service'),
primary_key=True, primary_key=True,
normalizer=lambda value: value.lower(), normalizer=lambda value: value.lower(),
), ),
Str('description?', Str('description?',
cli_name='desc', cli_name='desc',
label=_('Description'), label=_('Description'),
doc=_('Description of service'), doc=_('HBAC service description'),
), ),
) )
@ -82,7 +82,7 @@ class hbacsvc_add(LDAPCreate):
""" """
Add a new HBAC service. Add a new HBAC service.
""" """
msg_summary = _('Added service "%(value)s"') msg_summary = _('Added HBAC service "%(value)s"')
api.register(hbacsvc_add) api.register(hbacsvc_add)
@ -91,7 +91,7 @@ class hbacsvc_del(LDAPDelete):
""" """
Delete an existing HBAC service. Delete an existing HBAC service.
""" """
msg_summary = _('Deleted service "%(value)s"') msg_summary = _('Deleted HBAC service "%(value)s"')
api.register(hbacsvc_del) api.register(hbacsvc_del)
@ -101,6 +101,8 @@ class hbacsvc_mod(LDAPUpdate):
Modify an HBAC service. Modify an HBAC service.
""" """
msg_summary = _('Modified HBAC service "%(value)s"')
api.register(hbacsvc_mod) api.register(hbacsvc_mod)
@ -109,6 +111,10 @@ class hbacsvc_find(LDAPSearch):
Search for HBAC services. Search for HBAC services.
""" """
msg_summary = ngettext(
'%(count)d HBAC service matched', '%(count)d HBAC services matched', 0
)
api.register(hbacsvc_find) api.register(hbacsvc_find)

View File

@ -61,7 +61,7 @@ class hbacsvcgroup(LDAPObject):
'member': ['hbacsvc'], 'member': ['hbacsvc'],
} }
label = _('HBAC Service Groups') label = _('HBAC service Groups')
takes_params = ( takes_params = (
Str('cn', Str('cn',
@ -84,7 +84,7 @@ class hbacsvcgroup_add(LDAPCreate):
""" """
Add a new HBAC services group. 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) api.register(hbacsvcgroup_add)
@ -93,7 +93,7 @@ class hbacsvcgroup_del(LDAPDelete):
""" """
Delete an HBAC services group. 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) api.register(hbacsvcgroup_del)
@ -102,7 +102,7 @@ class hbacsvcgroup_mod(LDAPUpdate):
""" """
Modify an HBAC services group. 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) api.register(hbacsvcgroup_mod)
@ -112,7 +112,7 @@ class hbacsvcgroup_find(LDAPSearch):
Search for an HBAC services group. Search for an HBAC services group.
""" """
msg_summary = ngettext( 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) api.register(hbacsvcgroup_find)

View File

@ -71,7 +71,7 @@ class test_hbacsvcgroup(Declarative):
), ),
expected=dict( expected=dict(
value=hbacsvcgroup1, value=hbacsvcgroup1,
summary=u'Added HBAC Service group "testhbacsvcgroup1"', summary=u'Added HBAC service group "testhbacsvcgroup1"',
result=dict( result=dict(
dn=dn1, dn=dn1,
cn=[hbacsvcgroup1], cn=[hbacsvcgroup1],
@ -101,7 +101,7 @@ class test_hbacsvcgroup(Declarative):
), ),
expected=dict( expected=dict(
value=hbacsvc1, value=hbacsvc1,
summary=u'Added service "%s"' % hbacsvc1, summary=u'Added HBAC service "%s"' % hbacsvc1,
result=dict( result=dict(
dn=hbacsvc_dn1, dn=hbacsvc_dn1,
cn=[hbacsvc1], cn=[hbacsvc1],
@ -157,7 +157,7 @@ class test_hbacsvcgroup(Declarative):
expected=dict( expected=dict(
count=1, count=1,
truncated=False, truncated=False,
summary=u'1 group matched', summary=u'1 HBAC service group matched',
result=[ result=[
{ {
'dn': dn1, 'dn': dn1,
@ -177,7 +177,7 @@ class test_hbacsvcgroup(Declarative):
), ),
expected=dict( expected=dict(
value=hbacsvcgroup1, value=hbacsvcgroup1,
summary=u'Modified HBAC Service group "testhbacsvcgroup1"', summary=u'Modified HBAC service group "testhbacsvcgroup1"',
result=dict( result=dict(
cn=[hbacsvcgroup1], cn=[hbacsvcgroup1],
description=[u'Updated hbacsvcgroup 1'], description=[u'Updated hbacsvcgroup 1'],
@ -229,7 +229,7 @@ class test_hbacsvcgroup(Declarative):
command=('hbacsvcgroup_del', [hbacsvcgroup1], {}), command=('hbacsvcgroup_del', [hbacsvcgroup1], {}),
expected=dict( expected=dict(
value=hbacsvcgroup1, value=hbacsvcgroup1,
summary=u'Deleted HBAC Service group "testhbacsvcgroup1"', summary=u'Deleted HBAC service group "testhbacsvcgroup1"',
result=dict(failed=u''), result=dict(failed=u''),
), ),
), ),
@ -240,7 +240,7 @@ class test_hbacsvcgroup(Declarative):
command=('hbacsvc_del', [hbacsvc1], {}), command=('hbacsvc_del', [hbacsvc1], {}),
expected=dict( expected=dict(
value=hbacsvc1, value=hbacsvc1,
summary=u'Deleted service "%s"' % hbacsvc1, summary=u'Deleted HBAC service "%s"' % hbacsvc1,
result=dict(failed=u''), result=dict(failed=u''),
), ),
) )