mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
read first file returned from s3
rather than looping through, just use `next`. We only expect to return one file, so this won't actually affect the code flow. If, for whatever reason, the file isn't on s3, whereas previously it would error when trying to return an uninstantiated variable, now it will raise a StopIteration
This commit is contained in:
@@ -135,14 +135,15 @@ def get_letter_pdf(notification):
|
||||
s3 = boto3.resource('s3')
|
||||
bucket = s3.Bucket(bucket_name)
|
||||
|
||||
for item in bucket.objects.filter(Prefix=get_bucket_prefix_for_notification(notification, is_test_letter)):
|
||||
obj = s3.Object(
|
||||
bucket_name=bucket_name,
|
||||
key=item.key
|
||||
)
|
||||
file_content = obj.get()["Body"].read()
|
||||
item = next(x for x in bucket.objects.filter(
|
||||
Prefix=get_bucket_prefix_for_notification(notification, is_test_letter)
|
||||
))
|
||||
|
||||
return file_content
|
||||
obj = s3.Object(
|
||||
bucket_name=bucket_name,
|
||||
key=item.key
|
||||
)
|
||||
return obj.get()["Body"].read()
|
||||
|
||||
|
||||
def _move_s3_object(source_bucket, source_filename, target_bucket, target_filename):
|
||||
|
||||
Reference in New Issue
Block a user