summaryrefslogtreecommitdiff
path: root/src/leap/soledad/server
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-12-08 22:54:50 -0200
committerdrebs <drebs@leap.se>2017-12-13 13:49:27 -0200
commit8a1ab21e09632928be79fdf7473073ae363f8231 (patch)
treeea010923b79ecf0c97b51faa98e6f17697d325f0 /src/leap/soledad/server
parentd5a30f5909a17c7d8ba661d35f73c5c09a7c0dc6 (diff)
[refactor] make set_flags() return a deferred
Diffstat (limited to 'src/leap/soledad/server')
-rw-r--r--src/leap/soledad/server/_blobs.py28
-rw-r--r--src/leap/soledad/server/interfaces.py3
2 files changed, 22 insertions, 9 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py
index 5fe9c1b7..bfe95516 100644
--- a/src/leap/soledad/server/_blobs.py
+++ b/src/leap/soledad/server/_blobs.py
@@ -320,7 +320,8 @@ class BlobsResource(resource.Resource):
def catchBlobNotFound(failure):
failure.trap(BlobNotFound)
request.setResponseCode(404)
- return "Blob doesn't exists: %s" % blob_id
+ request.write("Blob doesn't exists: %s" % blob_id)
+ request.finish()
d = self._handler.delete_blob(user, blob_id, namespace=namespace)
d.addCallback(lambda _: request.finish())
@@ -357,17 +358,26 @@ class BlobsResource(resource.Resource):
user, blob_id, namespace = self._validate(request)
raw_flags = request.content.read()
flags = json.loads(raw_flags)
- try:
- self._handler.set_flags(user, blob_id, flags, namespace=namespace)
- except BlobNotFound:
- # 404 - Not Found
+
+ def catchBlobNotFound(failure):
+ failure.trap(BlobNotFound)
request.setResponseCode(404)
- return "Blob doesn't exists: %s" % blob_id
- except InvalidFlag as e:
+ request.write("Blob doesn't exists: %s" % blob_id)
+ request.finish()
+
+ def catchInvalidFlag(failure):
+ e = failure.trap(InvalidFlag)
request.setResponseCode(406)
flag = e.message
- return "Invalid flag: %s" % str(flag)
- return ''
+ request.write("Invalid flag: %s" % str(flag))
+ request.finish()
+
+ d = self._handler.set_flags(user, blob_id, flags, namespace=namespace)
+ d.addCallback(lambda _: request.write(''))
+ d.addCallback(lambda _: request.finish())
+ d.addErrback(catchBlobNotFound)
+ d.addErrback(catchInvalidFlag)
+ return NOT_DONE_YET
def _error(self, e, request):
logger.error('Error processing request: %s' % e.getErrorMessage())
diff --git a/src/leap/soledad/server/interfaces.py b/src/leap/soledad/server/interfaces.py
index bd804573..358a0d62 100644
--- a/src/leap/soledad/server/interfaces.py
+++ b/src/leap/soledad/server/interfaces.py
@@ -189,4 +189,7 @@ class IBlobsBackend(Interface):
:type flags: list of str
:param namespace: An optional namespace for the blob.
:type namespace: str
+
+ :return: A deferred that fires when the flags have been set.
+ :rtype: twisted.internet.defer.Deferred
"""