summaryrefslogtreecommitdiff
path: root/server/src/leap
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/leap')
-rw-r--r--server/src/leap/soledad/server/_resource.py16
-rw-r--r--server/src/leap/soledad/server/_server_info.py41
-rw-r--r--server/src/leap/soledad/server/entrypoint.py7
3 files changed, 55 insertions, 9 deletions
diff --git a/server/src/leap/soledad/server/_resource.py b/server/src/leap/soledad/server/_resource.py
index 3e307e44..1c4edade 100644
--- a/server/src/leap/soledad/server/_resource.py
+++ b/server/src/leap/soledad/server/_resource.py
@@ -22,6 +22,7 @@ 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
@@ -34,26 +35,33 @@ class SoledadResource(Resource):
for the Soledad Server.
"""
- _conf = get_config()
-
def __init__(self, sync_pool=None):
sync_resource = get_sync_resource(sync_pool)
- self._blobs_enabled = self._conf['soledad-server']['blobs']
+ conf = get_config()
+ self._blobs_enabled = conf['soledad-server']['blobs']
+ server_info = ServerInfo(self._blobs_enabled)
self.children = {
+ '': server_info,
'sync': sync_resource,
'blobs': blobs_resource,
+ 'sync': sync_resource,
}
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['']
+
+ # 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']
- # rewind the path and serve the wsgi sync resource
+ # other requesta are routed to legacy sync resource
request.postpath.insert(0, request.prepath.pop())
return self.children['sync']
diff --git a/server/src/leap/soledad/server/_server_info.py b/server/src/leap/soledad/server/_server_info.py
new file mode 100644
index 00000000..a1dd3555
--- /dev/null
+++ b/server/src/leap/soledad/server/_server_info.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# _server_info.py
+# Copyright (C) 2017 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/>.
+"""
+Resource that announces information about the server.
+"""
+import json
+
+from twisted.web.resource import Resource
+
+
+__all__ = ['ServerInfo']
+
+
+class ServerInfo(Resource):
+ """
+ Return information about the server.
+ """
+
+ isLeaf = True
+
+ def __init__(self, blobs_enabled):
+ self._info = {
+ "blobs": blobs_enabled,
+ }
+
+ def render_GET(self, request):
+ return json.dumps(self._info)
diff --git a/server/src/leap/soledad/server/entrypoint.py b/server/src/leap/soledad/server/entrypoint.py
index 714490ae..cfc557a3 100644
--- a/server/src/leap/soledad/server/entrypoint.py
+++ b/server/src/leap/soledad/server/entrypoint.py
@@ -30,11 +30,8 @@ conf = get_config
class SoledadEntrypoint(SoledadSession):
- # 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
+ def __init__(self):
+ SoledadSession.__init__(self, conf)
# see the comments in application.py recarding why couch state has to be