mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-13 09:41:55 -06:00
Started roughing out user_add() using api.Backend.ldap; added Command.output_for_cli() to take care of formatting print output
This commit is contained in:
parent
20fa90cfb6
commit
1480224724
@ -302,7 +302,7 @@ class CLI(object):
|
|||||||
break
|
break
|
||||||
except errors.ValidationError, e:
|
except errors.ValidationError, e:
|
||||||
error = e.error
|
error = e.error
|
||||||
cmd(**kw)
|
cmd.output_for_cli(cmd(**kw))
|
||||||
|
|
||||||
def parse(self, cmd, argv):
|
def parse(self, cmd, argv):
|
||||||
parser = self.build_parser(cmd)
|
parser = self.build_parser(cmd)
|
||||||
|
@ -486,6 +486,7 @@ class Command(plugable.Plugin):
|
|||||||
'params',
|
'params',
|
||||||
'args_to_kw',
|
'args_to_kw',
|
||||||
'kw_to_args',
|
'kw_to_args',
|
||||||
|
'output_for_cli',
|
||||||
))
|
))
|
||||||
takes_options = tuple()
|
takes_options = tuple()
|
||||||
takes_args = tuple()
|
takes_args = tuple()
|
||||||
@ -741,6 +742,14 @@ class Command(plugable.Plugin):
|
|||||||
multivalue = True
|
multivalue = True
|
||||||
yield arg
|
yield arg
|
||||||
|
|
||||||
|
def output_for_cli(self, ret):
|
||||||
|
"""
|
||||||
|
Output result of this command to command line interface.
|
||||||
|
"""
|
||||||
|
assert type(ret) is dict, 'base output_for_cli() only works with dict'
|
||||||
|
for key in sorted(ret):
|
||||||
|
print '%s = %r' % (key, ret[key])
|
||||||
|
|
||||||
|
|
||||||
class Object(plugable.Plugin):
|
class Object(plugable.Plugin):
|
||||||
__public__ = frozenset((
|
__public__ = frozenset((
|
||||||
|
@ -75,12 +75,26 @@ api.register(user)
|
|||||||
|
|
||||||
class user_add(crud.Add):
|
class user_add(crud.Add):
|
||||||
'Add a new user.'
|
'Add a new user.'
|
||||||
def execute(self, *args, **kw):
|
|
||||||
"""args[0] = uid of the user to add
|
def execute(self, uid, **kw):
|
||||||
kw{container} is the location in the DIT to add the user, not
|
|
||||||
required
|
|
||||||
kw otherwise contains all the attributes
|
|
||||||
"""
|
"""
|
||||||
|
Execute the user-add operation.
|
||||||
|
|
||||||
|
The dn should not be passed as a keyword argument as it is constructed
|
||||||
|
by this method.
|
||||||
|
|
||||||
|
Returns the entry as it will be created in LDAP.
|
||||||
|
|
||||||
|
:param uid: The login name of the user being added.
|
||||||
|
:param kw: Keyword arguments for the other LDAP attributes.
|
||||||
|
"""
|
||||||
|
assert 'uid' not in kw
|
||||||
|
assert 'dn' not in kw
|
||||||
|
kw['uid'] = uid
|
||||||
|
kw['dn'] = self.api.Backend.ldap.get_user_dn(uid)
|
||||||
|
|
||||||
|
return kw
|
||||||
|
|
||||||
# FIXME: ug, really?
|
# FIXME: ug, really?
|
||||||
if not kw.get('container'):
|
if not kw.get('container'):
|
||||||
user_container = servercore.DefaultUserContainer
|
user_container = servercore.DefaultUserContainer
|
||||||
@ -162,10 +176,6 @@ class user_add(crud.Add):
|
|||||||
|
|
||||||
result = servercore.add_entry(entry)
|
result = servercore.add_entry(entry)
|
||||||
return result
|
return result
|
||||||
def forward(self, *args, **kw):
|
|
||||||
result = super(crud.Add, self).forward(*args, **kw)
|
|
||||||
if result:
|
|
||||||
print "User %s added" % args[0]
|
|
||||||
|
|
||||||
api.register(user_add)
|
api.register(user_add)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user