mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Started updated user_* commands to use textui
This commit is contained in:
parent
e7ec413158
commit
42bf555a3a
@ -209,9 +209,29 @@ class ldap(CrudBackend):
|
||||
|
||||
# The CRUD operations
|
||||
|
||||
def strip_none(self, kw):
|
||||
"""
|
||||
Remove any None values present in the LDAP attribute dict.
|
||||
"""
|
||||
for (key, value) in kw.iteritems():
|
||||
if value is None:
|
||||
continue
|
||||
if type(value) in (list, tuple):
|
||||
value = filter(
|
||||
lambda v: type(v) in (str, unicode, bool, int, float),
|
||||
value
|
||||
)
|
||||
if len(value) > 0:
|
||||
yield (key, value)
|
||||
else:
|
||||
assert type(value) in (str, unicode, bool, int, float)
|
||||
yield (key, value)
|
||||
|
||||
def create(self, **kw):
|
||||
if servercore.entry_exists(kw['dn']):
|
||||
raise errors.DuplicateEntry("entry already exists")
|
||||
kw = dict(self.strip_none(kw))
|
||||
|
||||
|
||||
entry = ipaldap.Entry(kw['dn'])
|
||||
|
||||
|
@ -198,6 +198,28 @@ class textui(backend.Backend):
|
||||
for (key, value) in rows:
|
||||
self.print_indented('%s = %r' % (key, value), indent)
|
||||
|
||||
def print_entry(self, entry, indent=1):
|
||||
"""
|
||||
Print an ldap entry dict.
|
||||
|
||||
For example:
|
||||
|
||||
>>> entry = dict(sn='Last', givenname='First', uid='flast')
|
||||
>>> ui = textui()
|
||||
>>> ui.print_entry(entry)
|
||||
givenname: 'First'
|
||||
sn: 'Last'
|
||||
uid: 'flast'
|
||||
"""
|
||||
assert type(entry) is dict
|
||||
for key in sorted(entry):
|
||||
value = entry[key]
|
||||
if type(value) in (list, tuple):
|
||||
value = ', '.join(repr(v) for v in value)
|
||||
else:
|
||||
value = repr(value)
|
||||
self.print_indented('%s: %s' % (key, value), indent)
|
||||
|
||||
def print_dashed(self, string, above=True, below=True):
|
||||
"""
|
||||
Print a string with a dashed line above and/or below.
|
||||
|
@ -191,18 +191,21 @@ class user_add(crud.Add):
|
||||
kw['objectClass'] = config.get('ipauserobjectclasses')
|
||||
|
||||
return ldap.create(**kw)
|
||||
def output_for_cli(self, ret):
|
||||
|
||||
def output_for_cli(self, textui, result, *args, **options):
|
||||
"""
|
||||
Output result of this command to command line interface.
|
||||
"""
|
||||
if ret:
|
||||
print "User added"
|
||||
textui.print_name(self.name)
|
||||
textui.print_entry(result)
|
||||
textui.print_dashed('Added user "%s"' % result['uid'])
|
||||
|
||||
api.register(user_add)
|
||||
|
||||
|
||||
class user_del(crud.Del):
|
||||
'Delete an existing user.'
|
||||
|
||||
def execute(self, uid, **kw):
|
||||
"""Delete a user. Not to be confused with inactivate_user. This
|
||||
makes the entry go away completely.
|
||||
@ -224,12 +227,12 @@ class user_del(crud.Del):
|
||||
ldap = self.api.Backend.ldap
|
||||
dn = ldap.find_entry_dn("uid", uid)
|
||||
return ldap.delete(dn)
|
||||
def output_for_cli(self, ret):
|
||||
|
||||
def output_for_cli(self, textui, result, uid):
|
||||
"""
|
||||
Output result of this command to command line interface.
|
||||
"""
|
||||
if ret:
|
||||
print "User deleted"
|
||||
textui.print_plain('Deleted user "%s"' % uid)
|
||||
|
||||
api.register(user_del)
|
||||
|
||||
@ -254,12 +257,13 @@ class user_mod(crud.Mod):
|
||||
dn = ldap.find_entry_dn("uid", uid)
|
||||
return ldap.update(dn, **kw)
|
||||
|
||||
def output_for_cli(self, ret):
|
||||
def output_for_cli(self, textui, result, uid, **options):
|
||||
"""
|
||||
Output result of this command to command line interface.
|
||||
"""
|
||||
if ret:
|
||||
print "User updated"
|
||||
textui.print_name(self.name)
|
||||
textui.print_entry(result)
|
||||
textui.print_dashed('Updated user "%s"' % result['uid'])
|
||||
|
||||
api.register(user_mod)
|
||||
|
||||
@ -330,9 +334,10 @@ class user_show(crud.Get):
|
||||
return ldap.retrieve(dn)
|
||||
else:
|
||||
return ldap.retrieve(dn, default_attributes)
|
||||
def output_for_cli(self, user):
|
||||
if user:
|
||||
display_user(user)
|
||||
|
||||
def output_for_cli(self, textui, result, uid, **options):
|
||||
if result:
|
||||
display_user(result)
|
||||
|
||||
api.register(user_show)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user