Commit 4f30a0d4 authored by Elouan Martinet's avatar Elouan Martinet
Browse files

[storages] Move S3 key downloading in its own method

parent ace8dbcb3fe0
......@@ -52,9 +52,7 @@ class S3Storage(Storage):
"""
key = source.binary_to_str(value).decode('utf-8')
try:
result = self.s3cnx.get_object(Bucket=self.bucket, Key=key)
self.info('Downloaded %s/%s from S3', self.bucket, key)
return Binary(result['Body'].read())
return self.download(key)
except Exception as ex:
source.critical("can't retrieve S3 object %s: %s", value, ex)
return None
......@@ -68,8 +66,7 @@ class S3Storage(Storage):
if PY3:
key = key.decode('utf-8')
try:
return Binary(self.s3cnx.get_object(
Bucket=self.bucket, Key=key)['Body'].read())
return self.download(key)
except Exception:
return None
......@@ -162,6 +159,11 @@ class S3Storage(Storage):
def suffixed_key(self, key):
return key + self.suffix
def download(self, key):
result = self.s3cnx.get_object(Bucket=self.bucket, Key=key)
self.info('Downloaded %s/%s from S3', self.bucket, key)
return Binary(result['Body'].read())
class S3AddFileOp(DataOperationMixIn, LateOperation):
containercls = list
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment