diff --git a/main.py b/main.py index b3a1040..fbd085c 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -import logging import os import tempfile import uuid @@ -8,6 +7,7 @@ from starlette.responses import JSONResponse from starlette.routing import Route from starlette.requests import Request from auth import login_required +from logger import root_logger as logger from settings import ( PORT, @@ -18,10 +18,13 @@ from settings import ( STORJ_END_POINT, ) -# Logging configuration -logging.basicConfig( - level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s" -) +async def create_s3_client(): + return aioboto3.Session().create_client( + "s3", + aws_access_key_id=STORJ_ACCESS_KEY, + aws_secret_access_key=STORJ_SECRET_KEY, + endpoint_url=STORJ_END_POINT, + ) @login_required @@ -38,12 +41,7 @@ async def upload_handler(request: Request): key = str(uuid.uuid4()) + file_extension logging.debug(f"Generated file key: {key}") - async with aioboto3.client( - "s3", - aws_access_key_id=STORJ_ACCESS_KEY, - aws_secret_access_key=STORJ_SECRET_KEY, - endpoint_url=STORJ_END_POINT, - ) as s3: + async with create_s3_client() as s3: with tempfile.NamedTemporaryFile() as tmp_file: while True: chunk = await file.read(8192)