From db39763758e8cd0a7df2e50951bcaa66e514cffc Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 6 Apr 2017 10:22:20 +0100 Subject: [PATCH 1/5] Refactor s3upload. s3upload now calls into the common notifications-utils method to upload a s3 file. --- app/main/uploader.py | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/app/main/uploader.py b/app/main/uploader.py index cc1f708c3..4c00fbce5 100644 --- a/app/main/uploader.py +++ b/app/main/uploader.py @@ -2,37 +2,18 @@ import uuid import botocore from boto3 import resource from flask import current_app +from notifications_utils.s3 import s3upload as utils_s3upload FILE_LOCATION_STRUCTURE = 'service-{}-notify/{}.csv' def s3upload(service_id, filedata, region): - s3 = resource('s3') - bucket_name = current_app.config['CSV_UPLOAD_BUCKET_NAME'] - contents = filedata['data'] - - exists = True - try: - s3.meta.client.head_bucket( - Bucket=bucket_name) - except botocore.exceptions.ClientError as e: - error_code = int(e.response['Error']['Code']) - if error_code == 404: - exists = False - else: - current_app.logger.error( - "Unable to create s3 bucket {}".format(bucket_name)) - raise e - - if not exists: - 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') - + utils_s3upload(filedata=filedata['data'], + region=region, + bucket_name=current_app.config['CSV_UPLOAD_BUCKET_NAME'], + file_location=upload_file_name) return upload_id From b2088762c37717e69ca59ab6e45d9054390d772f Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 6 Apr 2017 10:24:23 +0100 Subject: [PATCH 2/5] Update requirements with notifications-utils version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f186ab97a..89858964c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,4 +31,4 @@ notifications-python-client>=3.1,<3.2 awscli>=1.11,<1.12 awscli-cwlogs>=1.4,<1.5 -git+https://github.com/alphagov/notifications-utils.git@14.0.0#egg=notifications-utils==14.0.0 +git+https://github.com/alphagov/notifications-utils.git@14.0.0#egg=notifications-utils==15.0.1 From faad2f5a0947b50f277b3b49f01ca53358ab6d2b Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Thu, 6 Apr 2017 10:26:31 +0100 Subject: [PATCH 3/5] correct version number in requirements. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 89858964c..a1642c343 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,4 +31,4 @@ notifications-python-client>=3.1,<3.2 awscli>=1.11,<1.12 awscli-cwlogs>=1.4,<1.5 -git+https://github.com/alphagov/notifications-utils.git@14.0.0#egg=notifications-utils==15.0.1 +git+https://github.com/alphagov/notifications-utils.git@15.0.1#egg=notifications-utils==15.0.1 From 80a82cfdab9eae0a17beb3de05a931be6d2e79f9 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 10 Apr 2017 11:43:45 +0100 Subject: [PATCH 4/5] Update notifications-utils to the latest version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a1642c343..3442d47e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,4 +31,4 @@ notifications-python-client>=3.1,<3.2 awscli>=1.11,<1.12 awscli-cwlogs>=1.4,<1.5 -git+https://github.com/alphagov/notifications-utils.git@15.0.1#egg=notifications-utils==15.0.1 +git+https://github.com/alphagov/notifications-utils.git@15.0.3#egg=notifications-utils==15.0.3 From c9a519dac771307f7bd911e425f7d412ddc6a1f8 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Mon, 10 Apr 2017 15:41:57 +0100 Subject: [PATCH 5/5] Update the version of notification-utils. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7b41e2bec..af173bd58 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,5 +31,5 @@ notifications-python-client>=3.1,<3.2 awscli>=1.11,<1.12 awscli-cwlogs>=1.4,<1.5 -git+https://github.com/alphagov/notifications-utils.git@15.0.3#egg=notifications-utils==15.0.3 +git+https://github.com/alphagov/notifications-utils.git@15.0.4#egg=notifications-utils==15.0.4