mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-06 09:58:24 -04:00
notify-api-412 use black to enforce python coding style
This commit is contained in:
@@ -8,9 +8,9 @@ AWS_CLIENT_CONFIG = Config(
|
||||
# endpoints. See https://aws.amazon.com/compliance/fips/ for more
|
||||
# information.
|
||||
s3={
|
||||
'addressing_style': 'virtual',
|
||||
"addressing_style": "virtual",
|
||||
},
|
||||
use_fips_endpoint=True
|
||||
use_fips_endpoint=True,
|
||||
)
|
||||
|
||||
|
||||
@@ -25,38 +25,40 @@ def get_s3_object(
|
||||
session = Session(
|
||||
aws_access_key_id=access_key,
|
||||
aws_secret_access_key=secret_key,
|
||||
region_name=region
|
||||
region_name=region,
|
||||
)
|
||||
s3 = session.resource('s3', config=AWS_CLIENT_CONFIG)
|
||||
s3 = session.resource("s3", config=AWS_CLIENT_CONFIG)
|
||||
obj = s3.Object(bucket_name, filename)
|
||||
return obj
|
||||
|
||||
|
||||
def get_s3_metadata(obj):
|
||||
try:
|
||||
return obj.get()['Metadata']
|
||||
return obj.get()["Metadata"]
|
||||
except botocore.exceptions.ClientError as client_error:
|
||||
current_app.logger.error(f"Unable to download s3 file {obj.bucket_name}/{obj.key}")
|
||||
current_app.logger.error(
|
||||
f"Unable to download s3 file {obj.bucket_name}/{obj.key}"
|
||||
)
|
||||
raise client_error
|
||||
|
||||
|
||||
def set_s3_metadata(obj, **kwargs):
|
||||
copy_from_object_result = obj.copy_from(
|
||||
CopySource=f"{obj.bucket_name}/{obj.key}",
|
||||
ServerSideEncryption='AES256',
|
||||
Metadata={
|
||||
key: str(value) for key, value in kwargs.items()
|
||||
},
|
||||
MetadataDirective='REPLACE',
|
||||
ServerSideEncryption="AES256",
|
||||
Metadata={key: str(value) for key, value in kwargs.items()},
|
||||
MetadataDirective="REPLACE",
|
||||
)
|
||||
return copy_from_object_result
|
||||
|
||||
|
||||
def get_s3_contents(obj):
|
||||
contents = ''
|
||||
contents = ""
|
||||
try:
|
||||
contents = obj.get()['Body'].read().decode('utf-8')
|
||||
contents = obj.get()["Body"].read().decode("utf-8")
|
||||
except botocore.exceptions.ClientError as client_error:
|
||||
current_app.logger.error(f"Unable to download s3 file {obj.bucket_name}/{obj.key}")
|
||||
current_app.logger.error(
|
||||
f"Unable to download s3 file {obj.bucket_name}/{obj.key}"
|
||||
)
|
||||
raise client_error
|
||||
return contents
|
||||
|
||||
Reference in New Issue
Block a user