summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-12-06 18:01:31 -0200
committerdrebs <drebs@leap.se>2017-12-13 13:43:47 -0200
commit87413812397c24db807643c99ce0c42803cc7e43 (patch)
tree48bb11fe8cb602b7e041e78c2d293bbba43b5784 /src/leap
parent40258d7bfa57b4d73c10592c13c5a11aaf792446 (diff)
[refactor] make blobs backend get_tag() agnostic of twisted.web requests
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/soledad/server/_blobs.py16
-rw-r--r--src/leap/soledad/server/interfaces.py11
2 files changed, 15 insertions, 12 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py
index 3113e12c..8393d5bf 100644
--- a/src/leap/soledad/server/_blobs.py
+++ b/src/leap/soledad/server/_blobs.py
@@ -197,16 +197,14 @@ class FilesystemBlobsBackend(object):
def get_total_storage(self, user):
return self._get_disk_usage(self._get_path(user))
- def add_tag_header(self, user, blob_id, request, namespace=''):
+ def get_tag(self, user, blob_id, namespace=''):
blob_path = self._get_path(user, blob_id, namespace)
if not os.path.isfile(blob_path):
- # 404 - Not Found
- request.setResponseCode(404)
- return "Blob doesn't exists: %s" % blob_id
+ raise BlobNotFound
with open(blob_path) as doc_file:
doc_file.seek(-16, 2)
tag = base64.urlsafe_b64encode(doc_file.read())
- request.responseHeaders.setRawHeaders('Tag', [tag])
+ return tag
@defer.inlineCallbacks
def _get_disk_usage(self, start_path):
@@ -290,7 +288,13 @@ class BlobsResource(resource.Resource):
only_flags = request.args.get('only_flags', [False])[0]
if only_flags:
return self._handler.get_flags(user, blob_id, request, namespace)
- self._handler.add_tag_header(user, blob_id, request, namespace)
+ try:
+ tag = self._handler.get_tag(user, blob_id, namespace)
+ except BlobNotFound:
+ # 404 - Not Found
+ request.setResponseCode(404)
+ return "Blob doesn't exists: %s" % blob_id
+ request.responseHeaders.setRawHeaders('Tag', [tag])
return self._handler.read_blob(user, blob_id, request, namespace)
def render_DELETE(self, request):
diff --git a/src/leap/soledad/server/interfaces.py b/src/leap/soledad/server/interfaces.py
index 674fd8e6..15603047 100644
--- a/src/leap/soledad/server/interfaces.py
+++ b/src/leap/soledad/server/interfaces.py
@@ -157,18 +157,17 @@ class IBlobsBackend(Interface):
:rtype: int
"""
- def add_tag_header(user, blob_id, request, namespace=''):
+ def get_tag(user, blob_id, namespace=''):
"""
- Add a ``Tag`` HTTP header to the passed request containing the tag of
- a blob.
+ Get the tag of a blob.
:param blob_id: The id of the blob.
:type blob_id: str
- :param request: A representation of all of the information about the
- request that is being made.
- :type request: twisted.web.server.Request
:param namespace: An optional namespace for the blob.
:type namespace: str
+
+ :return: The tag of the blob.
+ :rtype: str
"""
def get_flags(user, blob_id, request, namespace=''):