Make s3upload function return the UUID

Generating the UUID can be can be contained within this function,
thus any other part of the code using it doesn’t have to do the
ID-generating stuff itself.
This commit is contained in:
Chris Hill-Scott
2016-05-15 07:47:50 +01:00
parent b35f2d7e61
commit e84436d0e1
4 changed files with 25 additions and 16 deletions

View File

@@ -1,3 +1,4 @@
import uuid
import botocore
from boto3 import resource
from flask import current_app
@@ -5,7 +6,7 @@ from flask import current_app
FILE_LOCATION_STRUCTURE = 'service-{}-notify/{}.csv'
def s3upload(upload_id, service_id, filedata, region):
def s3upload(service_id, filedata, region):
s3 = resource('s3')
bucket_name = current_app.config['CSV_UPLOAD_BUCKET_NAME']
contents = filedata['data']
@@ -27,10 +28,13 @@ def s3upload(upload_id, service_id, filedata, region):
s3.create_bucket(Bucket=bucket_name,
CreateBucketConfiguration={'LocationConstraint': region})
upload_id = str(uuid.uuid4())
upload_file_name = FILE_LOCATION_STRUCTURE.format(service_id, upload_id)
key = s3.Object(bucket_name, upload_file_name)
key.put(Body=contents, ServerSideEncryption='AES256')
return upload_id
def s3download(service_id, upload_id):
contents = ''