add better auth

This commit is contained in:
2025-03-25 11:45:09 -03:00
parent 2218a6f867
commit 317c79cee2
11 changed files with 912 additions and 46 deletions

29
http-api/middlewares.py Normal file
View File

@@ -0,0 +1,29 @@
from aws_lambda_powertools.event_handler.api_gateway import (
APIGatewayHttpResolver,
Response,
)
from aws_lambda_powertools.event_handler.middlewares import (
BaseMiddlewareHandler,
NextMiddleware,
)
class CorrelationIdMiddleware(BaseMiddlewareHandler):
def __init__(self, header: str):
super().__init__()
self.header = header
def handler(
self, app: APIGatewayHttpResolver, next_middleware: NextMiddleware
) -> Response:
# BEFORE logic
request_id = app.current_event.request_context.request_id
correlation_id = app.current_event.headers.get(self.header, request_id)
# Call next middleware or route handler ('/todos')
response = next_middleware(app)
# AFTER logic
response.headers[self.header] = correlation_id
return response