This commit is contained in:
2025-05-19 09:04:19 -03:00
parent 26b1e618b6
commit 7f4fec6e1e
33 changed files with 4728 additions and 542 deletions

View File

@@ -82,8 +82,8 @@ class AuditLogMiddleware(BaseMiddlewareHandler):
self.collect.put_item(
key=KeyPair(
# Post-migration: remove `delimiter` and update prefix from `log` to `logs`
# in ComposeKey.
# Post-migration: remove `delimiter` and update prefix
# from `log` to `logs` in ComposeKey.
pk=ComposeKey(user.id, prefix='log', delimiter=':'),
sk=now_.isoformat(),
),

View File

@@ -1,4 +1,3 @@
from auth import AuthFlowType
from aws_lambda_powertools.event_handler.api_gateway import (
APIGatewayHttpResolver,
Response,
@@ -9,6 +8,9 @@ from aws_lambda_powertools.event_handler.middlewares import (
)
from pydantic import UUID4, BaseModel, EmailStr, Field
from auth import AuthFlowType
class User(BaseModel):
id: str
name: str
@@ -22,8 +24,9 @@ class CognitoUser(User):
class AuthenticationMiddleware(BaseMiddlewareHandler):
"""This middleware extracts user authentication details from the Lambda authorizer context
and makes them available in the application context."""
"""This middleware extracts user authentication details from
the Lambda authorizer context and makes them available in the application context.
"""
def handler(
self,

View File

@@ -1,6 +1,5 @@
from http import HTTPStatus
from auth import AuthFlowType
from aws_lambda_powertools.event_handler.api_gateway import (
APIGatewayHttpResolver,
Response,
@@ -17,23 +16,30 @@ from aws_lambda_powertools.event_handler.middlewares import (
from layercake.dynamodb import ComposeKey, DynamoDBCollection, KeyPair
from pydantic import UUID4, BaseModel
from auth import AuthFlowType
from .authentication_middleware import User
class Tenant(BaseModel):
id: UUID4 | str
name: str
class TenantMiddleware(BaseMiddlewareHandler):
"""Middleware that associates a Tenant instance with the request context based on the authentication flow.
"""Middleware that associates a Tenant instance with the request context
based on the authentication flow.
For API authentication (`AuthFlowType.API_AUTH`), it assigns tenant information directly from the authorizer context.
For user authentication (`AuthFlowType.USER_AUTH`), it gets the Tenant ID from the specified request header.
For API authentication (`AuthFlowType.API_AUTH`), it assigns tenant information
directly from the authorizer context.
For user authentication (`AuthFlowType.USER_AUTH`), it gets the Tenant ID
from the specified request header.
Parameters
----------
collect : DynamoDBCollection
The DynamoDB collection used to validate user access and retrieve tenant information.
The DynamoDB collection used to validate user access and retrieve
tenant information.
header : str, optional
The request header name containing the tenant ID. Defaults to `'X-Tenant'`.
"""
@@ -81,7 +87,8 @@ def _tenant(
/,
collect: DynamoDBCollection,
) -> Tenant:
"""Get a Tenant instance based on the provided tenant_id and user's access permissions.
"""Get a Tenant instance based on the provided tenant_id
and user's access permissions.
Parameters
----------