summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2008-10-23 14:36:24 -0400
committerRob Crittenden <rcritten@redhat.com>2008-10-23 14:36:24 -0400
commitd2b46f176e5dbc40b67ebd90e6953498c5d6249a (patch)
treeaa9744362ceef772890d5ccaf5d70ea283f68387
parent43ad16676f21629d399c41ef0b51a666eba4c219 (diff)
downloadfreeipa-d2b46f176e5dbc40b67ebd90e6953498c5d6249a.tar.gz
freeipa-d2b46f176e5dbc40b67ebd90e6953498c5d6249a.tar.xz
freeipa-d2b46f176e5dbc40b67ebd90e6953498c5d6249a.zip
Use common display function for user-show and user-find.
Add --all option to user-find Fix command-line help to make sense on searches as well
-rw-r--r--ipa_server/plugins/b_ldap.py9
-rw-r--r--ipalib/crud.py2
-rw-r--r--ipalib/plugins/f_user.py48
3 files changed, 45 insertions, 14 deletions
diff --git a/ipa_server/plugins/b_ldap.py b/ipa_server/plugins/b_ldap.py
index 2e9c9e9fd..a7a3c8b35 100644
--- a/ipa_server/plugins/b_ldap.py
+++ b/ipa_server/plugins/b_ldap.py
@@ -213,6 +213,11 @@ class ldap(CrudBackend):
def search(self, **kw):
objectclass = kw.get('objectclass')
sfilter = kw.get('filter')
+ attributes = kw.get('attributes')
+ if attributes:
+ del kw['attributes']
+ else:
+ attributes = ['*']
if objectclass:
del kw['objectclass']
if sfilter:
@@ -228,13 +233,13 @@ class ldap(CrudBackend):
search_base = "%s, %s" % (self.api.env.container_accounts, self.api.env.basedn)
try:
exact_results = servercore.search(search_base,
- exact_match_filter, ["*"])
+ exact_match_filter, attributes)
except errors.NotFound:
exact_results = [0]
try:
partial_results = servercore.search(search_base,
- partial_match_filter, ["*"])
+ partial_match_filter, attributes)
except errors.NotFound:
partial_results = [0]
diff --git a/ipalib/crud.py b/ipalib/crud.py
index ba4d57187..6194b3fa7 100644
--- a/ipalib/crud.py
+++ b/ipalib/crud.py
@@ -63,6 +63,8 @@ class Find(frontend.Method):
def get_options(self):
for param in self.obj.params_minus_pk():
yield param.__clone__(required=False)
+ for option in self.takes_options:
+ yield option
class CrudBackend(backend.Backend):
diff --git a/ipalib/plugins/f_user.py b/ipalib/plugins/f_user.py
index 70952b29f..d8bb49e20 100644
--- a/ipalib/plugins/f_user.py
+++ b/ipalib/plugins/f_user.py
@@ -47,6 +47,24 @@ class envtest(frontend.Command):
return {}
api.register(envtest)
+def display_user(user):
+ # FIXME: for now delete dn here. In the future pass in the kw to
+ # output_for_cli()
+ attr = sorted(user.keys())
+ # Always have sn following givenname
+ try:
+ l = attr.index('givenname')
+ attr.remove('sn')
+ attr.insert(l+1, 'sn')
+ except ValueError:
+ pass
+
+ for a in attr:
+ if a != 'dn':
+ print "%s: %s" % (a, user[a])
+
+default_attributes = ['uid','givenname','sn','homeDirectory','loginshell']
+
class user(frontend.Object):
"""
@@ -68,30 +86,30 @@ class user(frontend.Object):
normalize=lambda value: value.lower(),
),
Param('gecos?',
- doc='Set the GECOS field',
+ doc='GECOS field',
default_from=lambda uid: uid,
),
Param('homedirectory?',
cli_name='home',
- doc='Set the User\'s home directory',
+ doc='User\'s home directory',
default_from=lambda uid: '/home/%s' % uid,
),
Param('loginshell?',
cli_name='shell',
default=u'/bin/sh',
- doc='Set User\'s Login shell',
+ doc='User\'s Login shell',
),
Param('krbprincipalname?', cli_name='principal',
- doc='Set User\'s Kerberos Principal name',
+ doc='User\'s Kerberos Principal name',
default_from=lambda uid: '%s@%s' % (uid, api.env.realm),
),
Param('mailaddress?',
cli_name='mail',
- doc='Set User\'s e-mail address',
+ doc='User\'s e-mail address',
),
Param('userpassword?',
cli_name='password',
- doc='Set User\'s password',
+ doc='User\'s password',
),
Param('groups?',
doc='Add account to one or more groups (comma-separated)',
@@ -248,6 +266,9 @@ api.register(user_mod)
class user_find(crud.Find):
'Search the users.'
+ takes_options = (
+ Param('all?', type=ipa_types.Bool(), doc='Retrieve all user attributes'),
+ )
def execute(self, term, **kw):
ldap = self.api.Backend.ldap
@@ -262,6 +283,10 @@ class user_find(crud.Find):
object_type = ldap.get_object_type("uid")
if object_type and not kw.get('objectclass'):
kw['objectclass'] = object_type
+ if kw.get('all', False):
+ kw['attributes'] = ['*']
+ else:
+ kw['attributes'] = default_attributes
return ldap.search(**kw)
def output_for_cli(self, users):
if not users:
@@ -276,15 +301,15 @@ class user_find(crud.Find):
print "Please refine your search and try again."
for u in users:
- for a in u.keys():
- print "%s: %s" % (a, u[a])
+ display_user(u)
+ print ""
api.register(user_find)
class user_show(crud.Get):
'Examine an existing user.'
takes_options = (
- Param('all?', type=ipa_types.Bool(), doc='Display all user attributes'),
+ Param('all?', type=ipa_types.Bool(), doc='Retrieve all user attributes'),
)
def execute(self, uid, **kw):
"""
@@ -304,11 +329,10 @@ class user_show(crud.Get):
if kw.get('all', False):
return ldap.retrieve(dn)
else:
- return ldap.retrieve(dn, ['uid','givenname','sn','homeDirectory','loginshell'])
+ return ldap.retrieve(dn, default_attributes)
def output_for_cli(self, user):
if user:
- for a in user.keys():
- print "%s: %s" % (a, user[a])
+ display_user(user)
api.register(user_show)