mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 00:33:58 -04:00
Merge pull request #157 from alphagov/s3-errors
In case there are problems reading back the csv file from
This commit is contained in:
@@ -2,9 +2,12 @@ import botocore
|
|||||||
from boto3 import resource
|
from boto3 import resource
|
||||||
|
|
||||||
|
|
||||||
|
BUCKET_NAME = 'service-{}-notify'
|
||||||
|
|
||||||
|
|
||||||
def s3upload(upload_id, service_id, filedata, region):
|
def s3upload(upload_id, service_id, filedata, region):
|
||||||
s3 = resource('s3')
|
s3 = resource('s3')
|
||||||
bucket_name = 'service-{}-notify'.format(service_id)
|
bucket_name = BUCKET_NAME.format(service_id)
|
||||||
contents = '\n'.join(filedata['data'])
|
contents = '\n'.join(filedata['data'])
|
||||||
|
|
||||||
exists = True
|
exists = True
|
||||||
@@ -25,9 +28,17 @@ def s3upload(upload_id, service_id, filedata, region):
|
|||||||
|
|
||||||
|
|
||||||
def s3download(service_id, upload_id):
|
def s3download(service_id, upload_id):
|
||||||
s3 = resource('s3')
|
contents = ''
|
||||||
bucket_name = 'service-{}-notify'.format(service_id)
|
try:
|
||||||
upload_file_name = "{}.csv".format(upload_id)
|
s3 = resource('s3')
|
||||||
key = s3.Object(bucket_name, upload_file_name)
|
bucket_name = BUCKET_NAME.format(service_id)
|
||||||
contents = key.get()['Body'].read().decode('utf-8')
|
upload_file_name = "{}.csv".format(upload_id)
|
||||||
|
key = s3.Object(bucket_name, upload_file_name)
|
||||||
|
contents = key.get()['Body'].read().decode('utf-8')
|
||||||
|
except botocore.exceptions.ClientError as e:
|
||||||
|
err = e.response['Error']
|
||||||
|
if err['Code'] == 'NoSuchBucket':
|
||||||
|
err_msg = '{}:{}'.format(err['BucketName'], err['Message'])
|
||||||
|
# TODO properly log error
|
||||||
|
print(err_msg)
|
||||||
return contents
|
return contents
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import csv
|
import csv
|
||||||
import uuid
|
import uuid
|
||||||
|
import botocore
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
@@ -88,7 +89,10 @@ def send_sms(service_id, template_id):
|
|||||||
def check_sms(service_id, upload_id):
|
def check_sms(service_id, upload_id):
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
|
||||||
contents = s3download(service_id, upload_id)
|
contents = s3download(service_id, upload_id)
|
||||||
|
if not contents:
|
||||||
|
flash('There was a problem reading your upload file')
|
||||||
upload_result = _get_numbers(contents)
|
upload_result = _get_numbers(contents)
|
||||||
upload_data = session['upload_data']
|
upload_data = session['upload_data']
|
||||||
original_file_name = upload_data.get('original_file_name')
|
original_file_name = upload_data.get('original_file_name')
|
||||||
|
|||||||
Reference in New Issue
Block a user