2016-02-24 17:12:30 +00:00
|
|
|
from boto3 import resource
|
2016-04-07 13:44:04 +01:00
|
|
|
from flask import current_app
|
2016-02-24 17:12:30 +00:00
|
|
|
|
2016-04-07 13:44:04 +01:00
|
|
|
FILE_LOCATION_STRUCTURE = 'service-{}-notify/{}.csv'
|
2016-02-24 17:12:30 +00:00
|
|
|
|
2016-04-07 13:44:04 +01:00
|
|
|
|
2017-05-12 17:39:15 +01:00
|
|
|
def get_s3_file(bucket_name, file_location):
|
|
|
|
|
s3_file = get_s3_object(bucket_name, file_location)
|
|
|
|
|
return s3_file.get()['Body'].read().decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_s3_object(bucket_name, file_location):
|
2016-02-24 17:12:30 +00:00
|
|
|
s3 = resource('s3')
|
2017-05-12 17:21:07 +01:00
|
|
|
return s3.Object(bucket_name, file_location)
|
2016-04-05 14:28:19 +01:00
|
|
|
|
|
|
|
|
|
2016-04-07 13:44:04 +01:00
|
|
|
def get_job_from_s3(service_id, job_id):
|
2017-05-12 17:21:07 +01:00
|
|
|
bucket_name = current_app.config['CSV_UPLOAD_BUCKET_NAME']
|
|
|
|
|
file_location = FILE_LOCATION_STRUCTURE.format(service_id, job_id)
|
2017-05-12 17:39:15 +01:00
|
|
|
obj = get_s3_object(bucket_name, file_location)
|
2017-05-12 17:21:07 +01:00
|
|
|
return obj.get()['Body'].read().decode('utf-8')
|
2016-04-05 14:28:19 +01:00
|
|
|
|
|
|
|
|
|
2016-04-07 13:44:04 +01:00
|
|
|
def remove_job_from_s3(service_id, job_id):
|
|
|
|
|
bucket_name = current_app.config['CSV_UPLOAD_BUCKET_NAME']
|
|
|
|
|
file_location = FILE_LOCATION_STRUCTURE.format(service_id, job_id)
|
2017-05-12 17:39:15 +01:00
|
|
|
obj = get_s3_object(bucket_name, file_location)
|
2017-05-12 17:21:07 +01:00
|
|
|
return obj.delete()
|
2017-06-07 16:31:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_transformed_dvla_file(job_id):
|
|
|
|
|
bucket_name = current_app.config['DVLA_UPLOAD_BUCKET_NAME']
|
|
|
|
|
file_location = '{}-dvla-job.text'.format(job_id)
|
|
|
|
|
obj = get_s3_object(bucket_name, file_location)
|
|
|
|
|
return obj.delete()
|