Skip to content

Commit

Permalink
[S3] Support v4 signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
killing committed Nov 28, 2014
1 parent 58a4346 commit 4b4fe6a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 13 additions & 3 deletions seafobj/backends/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from boto.s3.key import Key

class S3Conf(object):
def __init__(self, key_id, key, bucket_name, host, port):
def __init__(self, key_id, key, bucket_name, host, port, use_v4_sig, aws_region):
self.key_id = key_id
self.key = key
self.bucket_name = bucket_name
self.host = host
self.port = port
self.use_v4_sig = use_v4_sig
self.aws_region = aws_region

class SeafS3Client(object):
'''Wraps a s3 connection and a bucket'''
Expand All @@ -21,7 +23,15 @@ def __init__(self, conf):

def do_connect(self):
if self.conf.host is None:
self.conn = boto.connect_s3(self.conf.key_id, self.conf.key)
# If version 4 signature is used, boto requires 'host' parameter
# Also there is a bug in AWS Frankfurt that causes boto doesn't work.
# The current work around is to give specific service address, like
# s3.eu-central-1.amazonaws.com instead of s3.amazonaws.com.
if self.conf.use_v4_sig:
self.conn = boto.connect_s3(self.conf.key_id, self.conf.key,
host='s3.%s.amazonaws.com' % self.conf.aws_region)
else:
self.conn = boto.connect_s3(self.conf.key_id, self.conf.key)
else:
self.conn = boto.connect_s3(
aws_access_key_id=self.conf.key_id,
Expand Down Expand Up @@ -52,4 +62,4 @@ def read_obj_raw(self, repo_id, version, obj_id):
return self.s3_client.read_object_content(real_obj_id)

def get_name(self):
return 'S3 storage backend'
return 'S3 storage backend'
12 changes: 11 additions & 1 deletion seafobj/objstore_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,18 @@ def get_s3_conf(cfg, section):
except ValueError:
raise InvalidConfigError('invalid s3 host %s' % addr)

use_v4_sig = False
if cfg.has_option(section, 'use_v4_signature'):
use_v4_sig = cfg.getboolean(section, 'use_v4_signature')

aws_region = None
if use_v4_sig:
if not cfg.has_option(section, 'aws_region'):
raise InvalidConfigError('aws_region is not configured')
aws_region = cfg.get(section, 'aws_region')

from seafobj.backends.s3 import S3Conf
conf = S3Conf(key_id, key, bucket, host, port)
conf = S3Conf(key_id, key, bucket, host, port, use_v4_sig, aws_region)

return conf

Expand Down

0 comments on commit 4b4fe6a

Please sign in to comment.