Use SSL to talk to S3, and tweak send_file

Note: We're now dependent upon Boto 2.0.
This commit is contained in:
Ryan Tucker 2011-09-21 20:39:15 -04:00
parent 7bd57300cf
commit 3892037351

View file

@ -83,7 +83,7 @@ def encrypt_file(filename, key, compress='/bin/cat'):
raise Exception raise Exception
def open_s3(accesskey, sharedkey, host): def open_s3(accesskey, sharedkey, host):
conn = S3Connection(accesskey, sharedkey, is_secure=False) conn = S3Connection(accesskey, sharedkey, is_secure=True)
mybucketname = (accesskey + '-bkup-' + host).lower() mybucketname = (accesskey + '-bkup-' + host).lower()
try: try:
bucket = conn.get_bucket(mybucketname) bucket = conn.get_bucket(mybucketname)
@ -98,14 +98,14 @@ def handle_progress(transmitted, pending):
def send_file(bucket, filename): def send_file(bucket, filename):
basefilename = os.path.basename(filename) basefilename = os.path.basename(filename)
if bucket.get_key(basefilename): logger.info('Uploading %s...' % basefilename)
logger.error('Duplicate filename %s! I hope that is OK.' % basefilename)
k = Key(bucket) k = Key(bucket)
k.key = basefilename k.key = basefilename
logger.info('Uploading %s...' % basefilename) if k.exists():
fd = open(name=filename, mode='rb') logger.warning('Duplicate filename %s! I hope that is OK.' % basefilename)
putHeaders = {'x-amz-storage-class': 'REDUCED_REDUNDANCY'} k.set_contents_from_filename(filename, cb=handle_progress, reduced_redundancy=True)
k.set_contents_from_file(fd, headers=putHeaders, cb=handle_progress)
return k return k
def encryption_worker(in_q, out_q): def encryption_worker(in_q, out_q):