[s3_bucket] access the bucket encryption response gracefully (#59826)

Signed-off-by: Jakob Ackermann <das7pad@outlook.com>
pull/59959/head
Jakob Ackermann 5 years ago committed by Jill R
parent 6838a8209b
commit 20b5ff5ab7

@ -419,12 +419,14 @@ def put_bucket_versioning(s3_client, bucket_name, required_versioning):
def get_bucket_encryption(s3_client, bucket_name):
try:
result = s3_client.get_bucket_encryption(Bucket=bucket_name)
return result.get('ServerSideEncryptionConfiguration').get('Rules')[0].get('ApplyServerSideEncryptionByDefault')
return result.get('ServerSideEncryptionConfiguration', {}).get('Rules', [])[0].get('ApplyServerSideEncryptionByDefault')
except ClientError as e:
if e.response['Error']['Code'] == 'ServerSideEncryptionConfigurationNotFoundError':
return None
else:
raise e
except (IndexError, KeyError):
return None
@AWSRetry.exponential_backoff(max_delay=120, catch_extra_error_codes=['NoSuchBucket'])

Loading…
Cancel
Save