wip
This commit is contained in:
@@ -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(),
|
||||
),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
----------
|
||||
|
||||
@@ -11,9 +11,9 @@ from layercake.dynamodb import (
|
||||
KeyPair,
|
||||
)
|
||||
|
||||
import elastic
|
||||
from boto3clients import dynamodb_client
|
||||
from conf import ELASTIC_CONN, ORDER_TABLE
|
||||
import elastic
|
||||
|
||||
router = Router()
|
||||
order_layer = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
||||
|
||||
@@ -6,9 +6,9 @@ from layercake.dynamodb import (
|
||||
PrefixKey,
|
||||
)
|
||||
|
||||
import konviva
|
||||
from boto3clients import dynamodb_client
|
||||
from conf import USER_TABLE
|
||||
import konviva
|
||||
from middlewares import User
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from http import HTTPStatus
|
||||
import json
|
||||
from http import HTTPStatus
|
||||
from typing import Annotated
|
||||
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
@@ -17,11 +17,11 @@ from layercake.dynamodb import (
|
||||
from layercake.extra_types import CpfStr, NameStr
|
||||
from pydantic import UUID4, BaseModel, StringConstraints
|
||||
|
||||
import cognito
|
||||
import elastic
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client, idp_client
|
||||
import cognito
|
||||
from conf import ELASTIC_CONN, USER_POOOL_ID, USER_TABLE
|
||||
import elastic
|
||||
from middlewares import AuditLogMiddleware
|
||||
from models import User
|
||||
from rules.user import update_user
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import base64
|
||||
from dataclasses import dataclass
|
||||
from http import HTTPMethod
|
||||
import json
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
from http import HTTPMethod
|
||||
|
||||
import jsonlines
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
import pytest
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer
|
||||
|
||||
PYTEST_TABLE_NAME = 'pytest'
|
||||
PK = os.getenv('DYNAMODB_PARTITION_KEY')
|
||||
|
||||
Reference in New Issue
Block a user