summaryrefslogtreecommitdiff
path: root/server/src/leap
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-01-26 19:18:15 -0200
committerKali Kaneko <kali@leap.se>2017-02-09 17:41:45 +0100
commit47858d88ca4ca10ac363c71550b1bafe50f8f4ce (patch)
treeb5bffe1b526e55c3279498851bd1c2628d83291b /server/src/leap
parent47c357213b4e39c6ced818de7eeb401e52bf92b9 (diff)
[refactor] allow passing threadpool pool for server sync resource
Conflicts: server/src/leap/soledad/server/_resource.py testing/tests/server/test__resource.py
Diffstat (limited to 'server/src/leap')
-rw-r--r--server/src/leap/soledad/server/_resource.py5
-rw-r--r--server/src/leap/soledad/server/_wsgi.py13
-rw-r--r--server/src/leap/soledad/server/auth.py13
-rw-r--r--server/src/leap/soledad/server/entrypoint.py11
4 files changed, 28 insertions, 14 deletions
diff --git a/server/src/leap/soledad/server/_resource.py b/server/src/leap/soledad/server/_resource.py
index 89e252d6..4070d786 100644
--- a/server/src/leap/soledad/server/_resource.py
+++ b/server/src/leap/soledad/server/_resource.py
@@ -19,7 +19,7 @@ A twisted resource that serves the Soledad Server.
"""
from twisted.web.resource import Resource
-from ._wsgi import sync_resource
+from ._wsgi import get_sync_resource
__all__ = ['SoledadResource']
@@ -31,7 +31,8 @@ class SoledadResource(Resource):
for the Soledad Server.
"""
- def __init__(self):
+ def __init__(self, sync_pool=None):
+ sync_resource = get_sync_resource(sync_pool)
self.children = {'': sync_resource}
def getChild(self, path, request):
diff --git a/server/src/leap/soledad/server/_wsgi.py b/server/src/leap/soledad/server/_wsgi.py
index 13c8d13b..3e30d560 100644
--- a/server/src/leap/soledad/server/_wsgi.py
+++ b/server/src/leap/soledad/server/_wsgi.py
@@ -33,7 +33,7 @@ from leap.soledad.common.couch.state import CouchServerState
from leap.soledad.common.log import getLogger
-__all__ = ['init_couch_state', 'sync_resource']
+__all__ = ['init_couch_state', 'get_sync_resource']
_config = None
@@ -76,8 +76,9 @@ def init_couch_state(_app):
reactor.stop()
-# setup a wsgi resource with its own threadpool
-pool = threadpool.ThreadPool()
-reactor.callWhenRunning(pool.start)
-reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
-sync_resource = WSGIResource(reactor, pool, wsgi_application)
+def get_sync_resource(pool=None):
+ if not pool:
+ pool = threadpool.ThreadPool()
+ reactor.callWhenRunning(pool.start)
+ reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
+ return WSGIResource(reactor, pool, wsgi_application)
diff --git a/server/src/leap/soledad/server/auth.py b/server/src/leap/soledad/server/auth.py
index e616a94f..a5d90c46 100644
--- a/server/src/leap/soledad/server/auth.py
+++ b/server/src/leap/soledad/server/auth.py
@@ -42,9 +42,13 @@ from ._wsgi import get_config
@implementer(IRealm)
class SoledadRealm(object):
+ def __init__(self, sync_pool=None):
+ self._sync_pool = sync_pool
+
def requestAvatar(self, avatarId, mind, *interfaces):
if IResource in interfaces:
- return (IResource, SoledadResource(), lambda: None)
+ resource = SoledadResource(sync_pool=self._sync_pool)
+ return (IResource, resource, lambda: None)
raise NotImplementedError()
@@ -127,5 +131,10 @@ class TokenCredentialFactory(object):
raise error.LoginFailed('Invalid credentials')
-get_portal = lambda: Portal(SoledadRealm(), [TokenChecker()])
+def get_portal(sync_pool=None):
+ realm = SoledadRealm(sync_pool=sync_pool)
+ checker = TokenChecker()
+ return Portal(realm, [checker])
+
+
credentialFactory = TokenCredentialFactory()
diff --git a/server/src/leap/soledad/server/entrypoint.py b/server/src/leap/soledad/server/entrypoint.py
index df2b8934..7501a447 100644
--- a/server/src/leap/soledad/server/entrypoint.py
+++ b/server/src/leap/soledad/server/entrypoint.py
@@ -20,7 +20,7 @@ The entrypoint for Soledad server.
from twisted.internet import reactor
from .config import load_configuration
-from ._resource import SoledadResource
+from ._session import SoledadSession
from ._wsgi import init_couch_state
@@ -28,10 +28,13 @@ from ._wsgi import init_couch_state
conf = load_configuration('/etc/soledad/soledad-server.conf')
-class SoledadEntrypoint(SoledadResource):
+class SoledadEntrypoint(SoledadSession):
- def __init__(self):
- SoledadResource.__init__(self, conf)
+ # the purpose of the entrypoint is to avoid trying to load the
+ # configuration file during tests. This class will be more useful when we
+ # add the blobs feature toggle. For now, the whole entrypoint
+
+ pass
# see the comments in application.py recarding why couch state has to be