diff options
author | drebs <drebs@leap.se> | 2017-01-27 20:30:02 -0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-02-09 17:41:54 +0100 |
commit | 53b5a6788ad8416f78b24cc9880d02da73c52d70 (patch) | |
tree | 7fe973bbaa783abbaa8cf2dde9d6b777e2f56cc1 /server | |
parent | 1f1a9847117d23a767e99fe80484baf232375d36 (diff) |
[refacor] make proper use of twisted web dyamic resources in server
Diffstat (limited to 'server')
-rw-r--r-- | server/src/leap/soledad/server/_resource.py | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/server/src/leap/soledad/server/_resource.py b/server/src/leap/soledad/server/_resource.py index 046e20d1..fec290a2 100644 --- a/server/src/leap/soledad/server/_resource.py +++ b/server/src/leap/soledad/server/_resource.py @@ -17,11 +17,9 @@ """ A twisted resource that serves the Soledad Server. """ -from twisted.web.error import Error from twisted.web.resource import Resource from ._blobs import blobs_resource -from ._config import get_config from ._server_info import ServerInfo from ._wsgi import get_sync_resource @@ -35,33 +33,25 @@ class SoledadResource(Resource): for the Soledad Server. """ - def __init__(self, sync_pool=None): - conf = get_config() - self._blobs_enabled = conf['soledad-server']['blobs'] - server_info = ServerInfo(self._blobs_enabled) - sync_resource = get_sync_resource(sync_pool) - self.children = { - '': server_info, - 'sync': sync_resource, - 'blobs': blobs_resource, - 'sync': sync_resource, - } + def __init__(self, conf, sync_pool=None): + Resource.__init__(self) + + blobs_enabled = conf['soledad-server']['blobs'] - def getChild(self, path, request): - """ - Decide which child resource to serve based on the given path. - """ # requests to / return server information - if path == '': - return self.children[''] + server_info = ServerInfo(blobs_enabled) + self.putChild('', server_info) # requests to /blobs will serve blobs if enabled - if path == 'blobs': - if not self._blobs_enabled: - msg = 'Blobs feature is disabled in this server.' - raise Error(403, message=msg) - return self.children['blobs'] + if blobs_enabled: + self.putChild('blobs', blobs_resource) - # other requesta are routed to legacy sync resource + # other requests are routed to legacy sync resource + self._sync_resource = get_sync_resource(sync_pool) + + def getChild(self, path, request): + """ + Route requests to legacy WSGI sync resource dynamically. + """ request.postpath.insert(0, request.prepath.pop()) - return self.children['sync'] + return self._sync_resource |