add himself to log

This commit is contained in:
2025-04-02 16:04:06 -03:00
parent 748764833b
commit 34085af4a8
3 changed files with 13 additions and 5 deletions

View File

@@ -89,6 +89,7 @@ class AuditLogMiddleware(BaseMiddlewareHandler):
action=self.action, action=self.action,
data=data, data=data,
ip=ip_addr, ip=ip_addr,
author='himself',
ttl=retention_days, ttl=retention_days,
) )

View File

@@ -4,7 +4,11 @@ from aws_lambda_powertools.event_handler.api_gateway import (
APIGatewayHttpResolver, APIGatewayHttpResolver,
Response, Response,
) )
from aws_lambda_powertools.event_handler.exceptions import BadRequestError, ServiceError from aws_lambda_powertools.event_handler.exceptions import (
BadRequestError,
NotFoundError,
ServiceError,
)
from aws_lambda_powertools.event_handler.middlewares import ( from aws_lambda_powertools.event_handler.middlewares import (
BaseMiddlewareHandler, BaseMiddlewareHandler,
NextMiddleware, NextMiddleware,
@@ -102,6 +106,8 @@ def _tenant(
If tenant_id is not provided. If tenant_id is not provided.
ForbiddenError ForbiddenError
If the user lacks the necessary ACL permissions for the specified tenant_id. If the user lacks the necessary ACL permissions for the specified tenant_id.
NotFoundError
If tenant not found.
""" """
if not tenant_id: if not tenant_id:
raise BadRequestError('Missing tenant') raise BadRequestError('Missing tenant')
@@ -116,5 +122,5 @@ def _tenant(
if tenant_id == '*': if tenant_id == '*':
return Tenant(id=tenant_id, name='default') return Tenant(id=tenant_id, name='default')
obj = collect.get_item(KeyPair(tenant_id, '0')) obj = collect.get_item(KeyPair(tenant_id, '0'), exception_cls=NotFoundError)
return Tenant.parse_obj(obj) return Tenant.parse_obj(obj)

View File

@@ -31,13 +31,14 @@ def test_post_course(
lambda_context, lambda_context,
) )
# print(r)
assert 'id' in json.loads(r['body']) assert 'id' in json.loads(r['body'])
assert r['statusCode'] == HTTPStatus.CREATED assert r['statusCode'] == HTTPStatus.CREATED
collect = DynamoDBCollection(dynamodb_persistence_layer) collect = DynamoDBCollection(dynamodb_persistence_layer)
logs = collect.get_items( logs = collect.get_items(
PartitionKey(ComposeKey('5OxmMjL-ujoR5IMGegQz', prefix='log', delimiter=':')) PartitionKey(
ComposeKey('5OxmMjL-ujoR5IMGegQz', prefix='log', delimiter=':'),
) )
)
assert len(logs['items']) == 3
print(logs) print(logs)