-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored project structure and enabled Secrets Manager token for We…
…bHook
- Loading branch information
1 parent
f987f44
commit 598505e
Showing
14 changed files
with
380 additions
and
232 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Built-in imports | ||
import json | ||
import boto3 | ||
from typing import Union | ||
|
||
# External imports | ||
from botocore.exceptions import ClientError | ||
|
||
# Own imports | ||
from common.logger import custom_logger | ||
|
||
logger = custom_logger() | ||
|
||
|
||
class SecretsHelper: | ||
"""Custom Secrets Manager Helper for simplifying secret's retrieval.""" | ||
|
||
def __init__(self, secret_name: str) -> None: | ||
""" | ||
:param secret_name (str): Name of the secret to fetch. | ||
""" | ||
self.secret_name = secret_name | ||
self.client_sm = boto3.client("secretsmanager") | ||
|
||
def get_secret_value(self, key_name: str) -> Union[str, None]: | ||
""" | ||
Obtain the AWS Secret value based on a given key. | ||
:param key_name (str): Key name to fetch from the JSON secret. | ||
""" | ||
try: | ||
secret_value = self.client_sm.get_secret_value(SecretId=self.secret_name) | ||
logger.info(f"Successfully retrieved the AWS Secret: {self.secret_name}") | ||
self.secret_string = json.loads(secret_value["SecretString"]) | ||
logger.debug("Successfully obtained the SecretString value.") | ||
# Return value or intentional KeyError if the key is not present | ||
return self.secret_string[key_name] | ||
except ClientError as e: | ||
logger.exception(f"Error in pulling the AWS Secret: {self.secret_name}") | ||
logger.exception(f"Error details: {str(e)}") | ||
raise e |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
backend/common/text_message_model.py → backend/common/models/text_message_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.