This commit is contained in:
2025-10-14 23:38:39 -03:00
parent a7e5a0a528
commit 54c92b3996
11 changed files with 38 additions and 18 deletions

View File

@@ -2,7 +2,7 @@ from abc import ABC
from dataclasses import dataclass
from datetime import timedelta
from enum import Enum
from typing import NotRequired, Self, TypedDict
from typing import NotRequired, TypedDict
from layercake.dateutils import now, ttl
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair

View File

@@ -9,11 +9,13 @@ from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey
from boto3clients import dynamodb_client
from config import (
COURSE_TABLE,
ENROLLMENT_TABLE,
)
logger = Logger(__name__)
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
enrollment_layer = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
course_layer = DynamoDBPersistenceLayer(COURSE_TABLE, dynamodb_client)
@event_source(data_class=EventBridgeEvent)
@@ -28,7 +30,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
# Post-migration: after removing the stopgap file `patch_course_metadata.py`,
# use `access_expires_at` from `new_image`
access_period = int(
dyn.collection.get_item(
course_layer.collection.get_item(
KeyPair(
pk=new_image['course']['id'],
sk=SortKey('0', path_spec='access_period'),
@@ -36,7 +38,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
)
)
with dyn.transact_writer() as transact:
with enrollment_layer.transact_writer() as transact:
transact.put(
item={
'id': enrollment_id,

View File

@@ -26,7 +26,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
terms = user_layer.get_item(
# Post-migration (users): uncomment the following line
# KeyPair(new_image['org_id'], 'METADATA#BILLING_TERMS'),
KeyPair(new_image['tenant_id'], 'metadata#billing_policy'),
KeyPair(new_image['org_id'], 'metadata#billing_policy'),
)
if not terms:

View File

@@ -48,7 +48,7 @@ class Enrollment(BaseModel):
return super().model_dump(
exclude={
'user': {'email_verified'},
'course': {'cert', 'access_period'},
'course': {'cert'},
},
*args,
**kwargs,

View File

@@ -252,6 +252,8 @@ Resources:
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref EnrollmentTable
- DynamoDBReadPolicy:
TableName: !Ref CourseTable
Events:
DynamoDBEvent:
Type: EventBridgeRule