diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/leap/soledad/server/_wsgi.py | 8 | ||||
-rw-r--r-- | server/src/leap/soledad/server/auth.py | 7 | ||||
-rw-r--r-- | server/src/leap/soledad/server/entrypoint.py | 10 | ||||
-rw-r--r-- | server/src/leap/soledad/server/session.py | 6 |
4 files changed, 14 insertions, 17 deletions
diff --git a/server/src/leap/soledad/server/_wsgi.py b/server/src/leap/soledad/server/_wsgi.py index a719aacb..f6ff6b26 100644 --- a/server/src/leap/soledad/server/_wsgi.py +++ b/server/src/leap/soledad/server/_wsgi.py @@ -18,7 +18,6 @@ A WSGI application that serves Soledad synchronization. """ from twisted.internet import reactor -from twisted.python import threadpool from twisted.web.wsgi import WSGIResource from leap.soledad.server import SoledadApp @@ -62,10 +61,5 @@ def init_couch_state(conf): reactor.stop() -def get_sync_resource(pool=None): - if not pool: - log.warn("NO POOL PASSED, CREATING----------") - pool = threadpool.ThreadPool() - reactor.callWhenRunning(pool.start) - reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) +def get_sync_resource(pool): 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 e064341b..b5744fe9 100644 --- a/server/src/leap/soledad/server/auth.py +++ b/server/src/leap/soledad/server/auth.py @@ -48,8 +48,9 @@ log = Logger() @implementer(IRealm) class SoledadRealm(object): - def __init__(self, conf=None, sync_pool=None): - if not conf: + def __init__(self, sync_pool, conf=None): + assert sync_pool is not None + if conf is None: conf = get_config() blobs = conf['blobs'] self.anon_resource = SoledadAnonResource( @@ -160,7 +161,7 @@ class TokenCredentialFactory(object): raise error.LoginFailed('Invalid credentials') -def portalFactory(sync_pool=None): +def portalFactory(sync_pool): realm = SoledadRealm(sync_pool=sync_pool) checker = TokenChecker() return Portal(realm, [checker]) diff --git a/server/src/leap/soledad/server/entrypoint.py b/server/src/leap/soledad/server/entrypoint.py index 8078a54a..c06b740e 100644 --- a/server/src/leap/soledad/server/entrypoint.py +++ b/server/src/leap/soledad/server/entrypoint.py @@ -22,10 +22,12 @@ or the systemd script. """ from twisted.internet import reactor +from twisted.python import threadpool +from .auth import portalFactory +from .session import SoledadSession from ._config import get_config from ._wsgi import init_couch_state -from .session import SoledadSession # load configuration from file @@ -35,7 +37,11 @@ conf = get_config() class SoledadEntrypoint(SoledadSession): def __init__(self): - SoledadSession.__init__(self) + pool = threadpool.ThreadPool(name='wsgi') + reactor.callWhenRunning(pool.start) + reactor.addSystemEventTrigger('after', 'shutdown', pool.stop) + portal = portalFactory(pool) + SoledadSession.__init__(self, portal) # see the comments in application.py recarding why couch state has to be diff --git a/server/src/leap/soledad/server/session.py b/server/src/leap/soledad/server/session.py index c1ceb340..1c1b5345 100644 --- a/server/src/leap/soledad/server/session.py +++ b/server/src/leap/soledad/server/session.py @@ -28,7 +28,6 @@ from twisted.web.guard import HTTPAuthSessionWrapper from twisted.web.resource import ErrorPage from twisted.web.resource import IResource -from leap.soledad.server.auth import get_portal from leap.soledad.server.auth import credentialFactory from leap.soledad.server.url_mapper import URLMapper @@ -53,10 +52,7 @@ class UnauthorizedResource(wrapper.UnauthorizedResource): @implementer(IResource) class SoledadSession(HTTPAuthSessionWrapper): - def __init__(self, portal=None): - if portal is None: - portal = get_portal() - + def __init__(self, portal): self._mapper = URLMapper() self._portal = portal self._credentialFactory = credentialFactory |