summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2016-12-17 10:56:22 -0200
committerdrebs <drebs@leap.se>2016-12-17 14:54:03 -0200
commitfeb14a1eadb894f16fcfd09ee6d229d6dfb35569 (patch)
treea77272b582b01581f2ed7e98196000ec5a9fe6fd /server
parent086fc21058314e0a3b13b06af3905ca5c3ee311e (diff)
[pkg] use a twisted resource as server entrypoint
Diffstat (limited to 'server')
-rw-r--r--server/pkg/soledad-server4
-rw-r--r--server/src/leap/soledad/server/resource.py53
2 files changed, 55 insertions, 2 deletions
diff --git a/server/pkg/soledad-server b/server/pkg/soledad-server
index d9dab040..753a260b 100644
--- a/server/pkg/soledad-server
+++ b/server/pkg/soledad-server
@@ -11,7 +11,7 @@
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PIDFILE=/var/run/soledad.pid
-OBJ=leap.soledad.server.application.wsgi_application
+RESOURCE_CLASS=leap.soledad.server.resource.SoledadResource
HTTPS_PORT=2424
CONFDIR=/etc/soledad
CERT_PATH="${CONFDIR}/soledad-server.pem"
@@ -39,7 +39,7 @@ case "${1}" in
--syslog \
--prefix=soledad-server \
web \
- --wsgi=${OBJ} \
+ --class=${RESOURCE_CLASS} \
--port=ssl:${HTTPS_PORT}:privateKey=${PRIVKEY_PATH}:certKey=${CERT_PATH}:sslmethod=${SSL_METHOD}
echo "."
;;
diff --git a/server/src/leap/soledad/server/resource.py b/server/src/leap/soledad/server/resource.py
new file mode 100644
index 00000000..dbb91b0a
--- /dev/null
+++ b/server/src/leap/soledad/server/resource.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+# resource.py
+# Copyright (C) 2016 LEAP
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+A twisted resource that serves the Soledad Server.
+"""
+
+from twisted.web.resource import Resource
+from twisted.web.wsgi import WSGIResource
+from twisted.internet import reactor
+from twisted.python import threadpool
+
+from leap.soledad.server.application import wsgi_application
+
+
+__all__ = ['SoledadResource']
+
+
+# setup a wsgi resource with its own threadpool
+pool = threadpool.ThreadPool()
+reactor.callWhenRunning(pool.start)
+reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
+wsgi_resource = WSGIResource(reactor, pool, wsgi_application)
+
+
+class SoledadResource(Resource):
+ """
+ This is a dummy twisted resource, used only to allow different entry points
+ for the Soledad Server.
+ """
+
+ def __init__(self):
+ self.children = {'': wsgi_resource}
+
+ def getChild(self, path, request):
+ # for now, just "rewind" the path and serve the wsgi resource for all
+ # requests. In the future, we might look into the request path to
+ # decide which child resources should serve each request.
+ request.postpath.insert(0, request.prepath.pop())
+ return self.children['']