[elbe-devel] [PATCH v2 03/10] soap: implement add_user action

Manuel Traut manuel.traut at linutronix.de
Wed Apr 18 16:45:39 CEST 2018


On Wed, Apr 18, 2018 at 04:42:22PM +0200, Manuel Traut wrote:
> On Tue, Apr 17, 2018 at 12:39:34PM +0200, Torben Hohn wrote:
> > Adding users is only possible via elbe db commands.
> > 
> > When we want to automate management of the initvm, and also
> > allow sharing of the initvm, its necessary to be able to create
> > a user via add_user.
> > 
> > This patch exposes ElbeDB.add_user via the soap interface.
> > add_user is only exposed to an Admin User (mainly root:root)
> > 
> > For our current usecase, we only want to make sure, the user exists.
> > So an Exception because of an already existing User is ignored, in
> > the client side code.
> > 
> > Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
> 
> please also implement a list_users that one can verify the status of available
> users before/after creating new ones.

forget it. it's already implemented. Sorry!

Reviewed-by: Manuel Traut <manut at linutronix.de>

and merged into devel/elbe-3.0

> > ---
> >  elbepack/daemons/soap/esoap.py |  6 ++++++
> >  elbepack/soapclient.py         | 32 ++++++++++++++++++++++++++++++++
> >  2 files changed, 38 insertions(+)
> > 
> > diff --git a/elbepack/daemons/soap/esoap.py b/elbepack/daemons/soap/esoap.py
> > index 03fcffc4..62e8e72d 100644
> > --- a/elbepack/daemons/soap/esoap.py
> > +++ b/elbepack/daemons/soap/esoap.py
> > @@ -68,6 +68,12 @@ class ESoap (ServiceBase):
> >      def list_users(ctx):
> >          return [u.name for u in ctx.app.pm.db.list_users()]
> >  
> > +    @rpc(String,String,String,String,Boolean)
> > +    @soap_faults
> > +    @authenticated_admin
> > +    def add_user(self, name, fullname, password, email, admin):
> > +        self.app.pm.db.add_user(name, fullname, password, email, admin)
> > +
> >      @rpc(_returns=Array(SoapProject))
> >      @soap_faults
> >      @authenticated_admin
> > diff --git a/elbepack/soapclient.py b/elbepack/soapclient.py
> > index f1fcf28f..785e217c 100644
> > --- a/elbepack/soapclient.py
> > +++ b/elbepack/soapclient.py
> > @@ -27,6 +27,7 @@ import fnmatch
> >  import deb822   # package for dealing with Debian related data
> >  
> >  from suds.client import Client
> > +from suds import WebFault
> >  from datetime import datetime
> >  from urllib2 import URLError
> >  from httplib import BadStatusLine
> > @@ -189,6 +190,37 @@ class ListUsersAction(ClientAction):
> >  
> >  ClientAction.register(ListUsersAction)
> >  
> > +class AddUserAction(ClientAction):
> > +    tag = 'add_user'
> > +
> > +    def __init__(self, node):
> > +        ClientAction.__init__(self, node)
> > +
> > +    def execute(self, client, opt, args):
> > +        if len(args) != 4:
> > +            print(
> > +                "usage: elbe control add_user <name> <fullname> <password> <email>",
> > +                file=sys.stderr)
> > +            sys.exit(20)
> > +
> > +        name     = args[0]
> > +        fullname = args[1]
> > +        password = args[2]
> > +        email    = args[3]
> > +
> > +        try:
> > +            client.service.add_user(name, fullname, password, email, False)
> > +        except WebFault as e:
> > +            if not hasattr(e.fault, 'faultstring'):
> > +                raise
> > +
> > +            if not e.fault.faultstring.endswith('already exists in the database'):
> > +                raise
> > +
> > +            # when we get here, the user we wanted to create already exists.
> > +            # that is fine, and we dont need to do anything now.
> > +
> > +ClientAction.register(AddUserAction)
> >  
> >  class CreateProjectAction(ClientAction):
> >  
> > -- 
> > 2.11.0
> > 
> > 
> > _______________________________________________
> > elbe-devel mailing list
> > elbe-devel at linutronix.de
> > https://lists.linutronix.de/mailman/listinfo/elbe-devel
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel



More information about the elbe-devel mailing list