Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and fix AWS secret manager invalid exception #24898

Merged
merged 3 commits into from
Jul 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions airflow/providers/amazon/aws/secrets/secrets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def _get_secret(self, path_prefix, secret_id: str) -> Optional[str]:
:param path_prefix: Prefix for the Path to get Secret
:param secret_id: Secret Key
"""
error_msg = "An error occurred when calling the get_secret_value operation"
if path_prefix:
secrets_path = self.build_path(path_prefix, secret_id, self.sep)
else:
Expand All @@ -257,15 +258,32 @@ def _get_secret(self, path_prefix, secret_id: str) -> Optional[str]:
return response.get('SecretString')
except self.client.exceptions.ResourceNotFoundException:
self.log.debug(
"An error occurred (ResourceNotFoundException) when calling the "
"get_secret_value operation: "
f"ResourceNotFoundException: {error_msg}: "
"Secret %s not found.",
secret_id,
)
return None
except self.client.exceptions.AccessDeniedException:
except self.client.exceptions.InvalidParameterException:
self.log.debug(
"An error occurred (AccessDeniedException) when calling the get_secret_value operation",
f"InvalidParameterException: {error_msg}",
exc_info=True,
)
return None
except self.client.exceptions.InvalidRequestException:
self.log.debug(
f"InvalidRequestException: {error_msg}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the the logging statements to use %-formatting instead of f-strings please? This makes sure that the string formatting is deferred until it cannot be avoided. This is a helpful reference which hopefully explains the practice here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josh-fell Finally I got to automate this check. I really do not like wasting mental capacity for things that can be automated during review :) #24910

exc_info=True,
)
return None
except self.client.exceptions.DecryptionFailure:
self.log.debug(
f"DecryptionFailure: {error_msg}",
exc_info=True,
)
return None
except self.client.exceptions.InternalServiceError:
self.log.debug(
f"InternalServiceError: {error_msg}",
exc_info=True,
)
return None