[elbe-devel] [PATCH 3/7] soap: implement add_user action

Torben Hohn torben.hohn at linutronix.de
Fri Apr 13 14:43:12 CEST 2018


Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 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




More information about the elbe-devel mailing list