diff options
author | drebs <drebs@leap.se> | 2017-12-06 18:16:33 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2017-12-13 13:43:47 -0200 |
commit | 9f07826cd98448b38646b2c731f82f99ee37f7c4 (patch) | |
tree | e96c16f54c4933dad380cfb63278c3a26a6dd2d3 /src/leap | |
parent | 6f29df7d0a8c68fb5aaf4de38d68b8c3de1a4aaa (diff) |
[refactor] make blobs backend get_flags() agnostic of twisted.web requests
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/soledad/server/_blobs.py | 20 | ||||
-rw-r--r-- | src/leap/soledad/server/interfaces.py | 9 |
2 files changed, 13 insertions, 16 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py index 8e9d9524..89c5927e 100644 --- a/src/leap/soledad/server/_blobs.py +++ b/src/leap/soledad/server/_blobs.py @@ -85,16 +85,14 @@ class FilesystemBlobsBackend(object): _file = static.File(path, defaultType='application/octet-stream') return _file.render_GET(request) - def get_flags(self, user, blob_id, request, namespace=''): + def get_flags(self, user, blob_id, namespace=''): path = self._get_path(user, blob_id, namespace) if not os.path.isfile(path): - # 404 - Not Found - request.setResponseCode(404) - return "Blob doesn't exists: %s" % blob_id + raise BlobNotFound if not os.path.isfile(path + '.flags'): - return '[]' + return [] with open(path + '.flags', 'r') as flags_file: - return flags_file.read() + return json.loads(flags_file.read()) def set_flags(self, user, blob_id, request, namespace=''): path = self._get_path(user, blob_id, namespace) @@ -286,16 +284,18 @@ class BlobsResource(resource.Resource): order_by=order, deleted=deleted, filter_flag=filter_flag) only_flags = request.args.get('only_flags', [False])[0] - if only_flags: - return self._handler.get_flags(user, blob_id, request, namespace) try: + if only_flags: + flags = self._handler.get_flags(user, blob_id, namespace) + return json.dumps(flags) tag = self._handler.get_tag(user, blob_id, namespace) + request.responseHeaders.setRawHeaders('Tag', [tag]) 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) + return self._handler.read_blob(user, blob_id, request, + namespace=namespace) def render_DELETE(self, request): logger.info("http put: %s" % request.path) diff --git a/src/leap/soledad/server/interfaces.py b/src/leap/soledad/server/interfaces.py index d19a0adc..f9cc96c4 100644 --- a/src/leap/soledad/server/interfaces.py +++ b/src/leap/soledad/server/interfaces.py @@ -167,7 +167,7 @@ class IBlobsBackend(Interface): :rtype: str """ - def get_flags(user, blob_id, request, namespace=''): + def get_flags(user, blob_id, namespace=''): """ Get the flags for a blob. @@ -175,14 +175,11 @@ class IBlobsBackend(Interface): :type user: str :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: a JSON encoded string with a list of flags. - :rtype: str + :return: a list of flags. + :rtype: list of str """ def set_flags(user, blob_id, request, namespace=''): |