Skip to content

Commit

Permalink
chore: add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
luislhl committed Apr 5, 2024
1 parent 91df166 commit 8f7126b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gateways/clients/s3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
from boto3.session import Session

from common.configuration import S3_ENDPOINT
from common.logging import get_logger


logger = get_logger()

class S3Client:
"""This is an abstraction for boto3 s3 client"""

def __init__(self) -> None:
session = Session()
self.log = logger.new()
if S3_ENDPOINT is None:
self.client = session.client("s3")
else:
Expand All @@ -29,8 +33,11 @@ def load_file(self, bucket: str, file: str) -> Union[str, None]:
response = self.client.get_object(Bucket=bucket, Key=file)
return response["Body"].read().decode()
except self.client.exceptions.NoSuchKey:
# TODO: Add log here
self.log.error("File not found in s3", bucket=bucket, file=file)
return None
except Exception as e:
self.log.error("Error loading file from s3", error=str(e))
raise e

def upload_file(self, bucket: str, file: str, content: str) -> dict:
"""Writes a string to a file in the storage.
Expand Down

0 comments on commit 8f7126b

Please sign in to comment.