From 810d929b47715f2424eb7686be68babda63b4e09 Mon Sep 17 00:00:00 2001 From: Duc Anh Date: Mon, 3 Jul 2017 07:58:27 +0000 Subject: [PATCH 1/2] allow custom s3-equivalent storage service --- inbox/util/blockstore.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/inbox/util/blockstore.py b/inbox/util/blockstore.py index e8bb794ec..c8d6b8d6d 100644 --- a/inbox/util/blockstore.py +++ b/inbox/util/blockstore.py @@ -11,7 +11,7 @@ STORE_MSG_ON_S3 = config.get('STORE_MESSAGES_ON_S3', None) if STORE_MSG_ON_S3: - from boto.s3.connection import S3Connection + from boto.s3.connection import S3Connection, OrdinaryCallingFormat from boto.s3.key import Key else: from inbox.util.file import mkdirp @@ -56,8 +56,13 @@ def _save_to_s3_bucket(data_sha256, bucket_name, data): start = time.time() # Boto pools connections at the class level - conn = S3Connection(config.get('AWS_ACCESS_KEY_ID'), - config.get('AWS_SECRET_ACCESS_KEY')) + conn = S3Connection(host=config.get('CUSTOM_S3_HOST', None), + port=config.get('CUSTOM_S3_PORT', None), + is_secure=config.get('CUSTOM_S3_SSL', True) + aws_access_key_id=config.get('AWS_ACCESS_KEY_ID'), + aws_secret_access_key=config.get('AWS_SECRET_ACCESS_KEY'), + calling_format=OrdinaryCallingFormat()) + bucket = conn.get_bucket(bucket_name, validate=False) # See if it already exists; if so, don't recreate. @@ -117,8 +122,13 @@ def _get_from_s3_bucket(data_sha256, bucket_name): if not data_sha256: return None - conn = S3Connection(config.get('AWS_ACCESS_KEY_ID'), - config.get('AWS_SECRET_ACCESS_KEY')) + conn = S3Connection(host=config.get('CUSTOM_S3_HOST', None), + port=config.get('CUSTOM_S3_PORT', None), + is_secure=config.get('CUSTOM_S3_SSL', True) + aws_access_key_id=config.get('AWS_ACCESS_KEY_ID'), + aws_secret_access_key=config.get('AWS_SECRET_ACCESS_KEY'), + calling_format=OrdinaryCallingFormat()) + bucket = conn.get_bucket(bucket_name, validate=False) key = bucket.get_key(data_sha256) From 3a6bf7ae7a602578c1b783a747d4dbbdcf810069 Mon Sep 17 00:00:00 2001 From: Duc Anh Date: Wed, 5 Jul 2017 04:10:02 +0000 Subject: [PATCH 2/2] fix missing comma in argument list --- inbox/util/blockstore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inbox/util/blockstore.py b/inbox/util/blockstore.py index c8d6b8d6d..800df558b 100644 --- a/inbox/util/blockstore.py +++ b/inbox/util/blockstore.py @@ -58,7 +58,7 @@ def _save_to_s3_bucket(data_sha256, bucket_name, data): # Boto pools connections at the class level conn = S3Connection(host=config.get('CUSTOM_S3_HOST', None), port=config.get('CUSTOM_S3_PORT', None), - is_secure=config.get('CUSTOM_S3_SSL', True) + is_secure=config.get('CUSTOM_S3_SSL', True), aws_access_key_id=config.get('AWS_ACCESS_KEY_ID'), aws_secret_access_key=config.get('AWS_SECRET_ACCESS_KEY'), calling_format=OrdinaryCallingFormat()) @@ -124,7 +124,7 @@ def _get_from_s3_bucket(data_sha256, bucket_name): conn = S3Connection(host=config.get('CUSTOM_S3_HOST', None), port=config.get('CUSTOM_S3_PORT', None), - is_secure=config.get('CUSTOM_S3_SSL', True) + is_secure=config.get('CUSTOM_S3_SSL', True), aws_access_key_id=config.get('AWS_ACCESS_KEY_ID'), aws_secret_access_key=config.get('AWS_SECRET_ACCESS_KEY'), calling_format=OrdinaryCallingFormat())