mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Add --all option to show/find, add default attrs to show, cleanup output
This commit is contained in:
parent
5ce4631041
commit
fb3f86f703
@ -23,7 +23,7 @@ Frontend plugins for group (Identity).
|
|||||||
|
|
||||||
from ipalib import api, crud, errors, errors2
|
from ipalib import api, crud, errors, errors2
|
||||||
from ipalib import Object, Command # Plugin base classes
|
from ipalib import Object, Command # Plugin base classes
|
||||||
from ipalib import Str, Int # Parameter types
|
from ipalib import Str, Int, Flag # Parameter types
|
||||||
|
|
||||||
|
|
||||||
def get_members(members):
|
def get_members(members):
|
||||||
@ -39,6 +39,8 @@ def get_members(members):
|
|||||||
|
|
||||||
return members
|
return members
|
||||||
|
|
||||||
|
default_attributes = ['cn','description','gidnumber', 'member']
|
||||||
|
|
||||||
class group(Object):
|
class group(Object):
|
||||||
"""
|
"""
|
||||||
Group object.
|
Group object.
|
||||||
@ -213,6 +215,9 @@ api.register(group_find)
|
|||||||
|
|
||||||
class group_show(crud.Get):
|
class group_show(crud.Get):
|
||||||
'Examine an existing group.'
|
'Examine an existing group.'
|
||||||
|
takes_options = (
|
||||||
|
Flag('all', doc='Retrieve all attributes'),
|
||||||
|
)
|
||||||
def execute(self, cn, **kw):
|
def execute(self, cn, **kw):
|
||||||
"""
|
"""
|
||||||
Execute the group-show operation.
|
Execute the group-show operation.
|
||||||
@ -227,27 +232,15 @@ class group_show(crud.Get):
|
|||||||
"""
|
"""
|
||||||
ldap = self.api.Backend.ldap
|
ldap = self.api.Backend.ldap
|
||||||
dn = ldap.find_entry_dn("cn", cn, "posixGroup")
|
dn = ldap.find_entry_dn("cn", cn, "posixGroup")
|
||||||
|
|
||||||
# FIXME: should kw contain the list of attributes to display?
|
# FIXME: should kw contain the list of attributes to display?
|
||||||
return ldap.retrieve(dn)
|
if kw.get('all', False):
|
||||||
|
return ldap.retrieve(dn)
|
||||||
|
else:
|
||||||
|
return ldap.retrieve(dn, default_attributes)
|
||||||
|
|
||||||
def output_for_cli(self, textui, result, *args, **options):
|
def output_for_cli(self, textui, result, *args, **options):
|
||||||
counter = result[0]
|
textui.print_entry(result)
|
||||||
groups = result[1:]
|
|
||||||
if counter == 0 or len(groups) == 0:
|
|
||||||
textui.print_plain("No entries found")
|
|
||||||
return
|
|
||||||
if len(groups) == 1:
|
|
||||||
textui.print_entry(groups[0])
|
|
||||||
return
|
|
||||||
textui.print_name(self.name)
|
|
||||||
for u in groups:
|
|
||||||
textui.print_plain('%(givenname)s %(sn)s:' % u)
|
|
||||||
textui.print_entry(u)
|
|
||||||
textui.print_plain('')
|
|
||||||
if counter == -1:
|
|
||||||
textui.print_plain('These results are truncated.')
|
|
||||||
textui.print_plain('Please refine your search and try again.')
|
|
||||||
textui.print_count(groups, '%d groups matched')
|
|
||||||
|
|
||||||
api.register(group_show)
|
api.register(group_show)
|
||||||
|
|
||||||
|
@ -139,6 +139,7 @@ class host_add(crud.Add):
|
|||||||
|
|
||||||
if 'krbprincipalaux' not in kw.get('objectclass'):
|
if 'krbprincipalaux' not in kw.get('objectclass'):
|
||||||
kw['objectclass'].append('krbprincipalaux')
|
kw['objectclass'].append('krbprincipalaux')
|
||||||
|
kw['objectclass'].append('krbprincipal')
|
||||||
else:
|
else:
|
||||||
if 'krbprincipalaux' in kw.get('objectclass'):
|
if 'krbprincipalaux' in kw.get('objectclass'):
|
||||||
kw['objectclass'].remove('krbprincipalaux')
|
kw['objectclass'].remove('krbprincipalaux')
|
||||||
|
@ -26,6 +26,7 @@ from ipalib import api, crud, errors2
|
|||||||
from ipalib import Object # Plugin base classes
|
from ipalib import Object # Plugin base classes
|
||||||
from ipalib import Str, Flag # Parameter types
|
from ipalib import Str, Flag # Parameter types
|
||||||
|
|
||||||
|
default_attributes = ['krbprincipalname']
|
||||||
|
|
||||||
class service(Object):
|
class service(Object):
|
||||||
"""
|
"""
|
||||||
@ -149,6 +150,9 @@ api.register(service_del)
|
|||||||
|
|
||||||
class service_find(crud.Find):
|
class service_find(crud.Find):
|
||||||
'Search the existing services.'
|
'Search the existing services.'
|
||||||
|
takes_options = (
|
||||||
|
Flag('all', doc='Retrieve all attributes'),
|
||||||
|
)
|
||||||
def execute(self, principal, **kw):
|
def execute(self, principal, **kw):
|
||||||
ldap = self.api.Backend.ldap
|
ldap = self.api.Backend.ldap
|
||||||
|
|
||||||
@ -160,6 +164,11 @@ class service_find(crud.Find):
|
|||||||
if object_type and not kw.get('objectclass'):
|
if object_type and not kw.get('objectclass'):
|
||||||
search_kw['objectclass'] = object_type
|
search_kw['objectclass'] = object_type
|
||||||
|
|
||||||
|
if kw.get('all', False):
|
||||||
|
search_kw['attributes'] = ['*']
|
||||||
|
else:
|
||||||
|
search_kw['attributes'] = default_attributes
|
||||||
|
|
||||||
return ldap.search(**search_kw)
|
return ldap.search(**search_kw)
|
||||||
|
|
||||||
def output_for_cli(self, textui, result, *args, **options):
|
def output_for_cli(self, textui, result, *args, **options):
|
||||||
@ -182,6 +191,9 @@ api.register(service_find)
|
|||||||
|
|
||||||
class service_show(crud.Get):
|
class service_show(crud.Get):
|
||||||
'Examine an existing service.'
|
'Examine an existing service.'
|
||||||
|
takes_options = (
|
||||||
|
Flag('all', doc='Display all service attributes'),
|
||||||
|
)
|
||||||
def execute(self, principal, **kw):
|
def execute(self, principal, **kw):
|
||||||
"""
|
"""
|
||||||
Execute the service-show operation.
|
Execute the service-show operation.
|
||||||
@ -197,7 +209,13 @@ class service_show(crud.Get):
|
|||||||
ldap = self.api.Backend.ldap
|
ldap = self.api.Backend.ldap
|
||||||
dn = ldap.find_entry_dn("krbprincipalname", principal)
|
dn = ldap.find_entry_dn("krbprincipalname", principal)
|
||||||
# FIXME: should kw contain the list of attributes to display?
|
# FIXME: should kw contain the list of attributes to display?
|
||||||
return ldap.retrieve(dn)
|
if kw.get('all', False):
|
||||||
|
return ldap.retrieve(dn)
|
||||||
|
else:
|
||||||
|
value = ldap.retrieve(dn, default_attributes)
|
||||||
|
del value['dn']
|
||||||
|
return value
|
||||||
|
|
||||||
def output_for_cli(self, textui, result, *args, **options):
|
def output_for_cli(self, textui, result, *args, **options):
|
||||||
textui.print_entry(result)
|
textui.print_entry(result)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user