update enrollment

This commit is contained in:
2025-08-26 13:50:20 -03:00
parent 0450a4b964
commit 25349ff533
13 changed files with 990 additions and 13 deletions

View File

@@ -71,5 +71,5 @@ def send_email(
)
return False
return True
else:
return True

View File

@@ -0,0 +1,73 @@
from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.data_classes import (
EventBridgeEvent,
event_source,
)
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dateutils import now
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
from boto3clients import dynamodb_client
from config import (
ENROLLMENT_TABLE,
)
logger = Logger(__name__)
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
@event_source(data_class=EventBridgeEvent)
@logger.inject_lambda_context
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
"""After the certificate expires, the enrollment will be marked as archived."""
old_image = event.detail['old_image']
now_ = now()
try:
with dyn.transact_writer() as transact:
transact.update(
key=KeyPair(
pk=old_image['id'],
sk='0',
),
update_expr='SET #status = :archived, updated_at = :updated_at',
cond_expr='#status = :completed',
expr_attr_names={
'#status': 'status',
},
expr_attr_values={
':completed': 'COMPLETED',
':archived': 'ARCHIVED',
':updated_at': now_,
},
)
transact.put(
item={
'id': old_image['id'],
'sk': 'ARCHIVED',
'archived_at': now_,
},
cond_expr='attribute_not_exists(sk)',
)
transact.put(
item={
'id': old_image['id'],
'sk': 'SCHEDULE#SET_AS_ARCHIVED#EXECUTED',
'created_at': now_,
},
)
except Exception as exc:
logger.exception(exc)
dyn.put_item(
item={
'id': old_image['id'],
'sk': 'SCHEDULE#SET_AS_ARCHIVED#FAILED',
'reason': str(exc),
'created_at': now_,
},
)
return False
else:
return True

View File

@@ -0,0 +1,75 @@
from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.data_classes import (
EventBridgeEvent,
event_source,
)
from aws_lambda_powertools.utilities.typing import LambdaContext
from layercake.dateutils import now
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
from boto3clients import dynamodb_client
from config import (
ENROLLMENT_TABLE,
)
logger = Logger(__name__)
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
@event_source(data_class=EventBridgeEvent)
@logger.inject_lambda_context
def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
"""If there is no certificate and the access period has ended,
the enrollment will be marked as expired."""
old_image = event.detail['old_image']
now_ = now()
try:
with dyn.transact_writer() as transact:
transact.update(
key=KeyPair(
pk=old_image['id'],
sk='0',
),
update_expr='SET #status = :expired, updated_at = :updated_at',
cond_expr='#status = :in_progress OR #status = :pending',
expr_attr_names={
'#status': 'status',
},
expr_attr_values={
':pending': 'PENDING',
':in_progress': 'IN_PROGRESS',
':expired': 'EXPIRED',
':updated_at': now_,
},
)
transact.put(
item={
'id': old_image['id'],
'sk': 'EXPIRED',
'expired_at': now_,
},
cond_expr='attribute_not_exists(sk)',
)
transact.put(
item={
'id': old_image['id'],
'sk': 'SCHEDULE#SET_AS_EXPIRED#EXECUTED',
'created_at': now_,
},
)
except Exception as exc:
logger.exception(exc)
dyn.put_item(
item={
'id': old_image['id'],
'sk': 'SCHEDULE#SET_AS_EXPIRED#FAILED',
'reason': str(exc),
'created_at': now_,
},
)
return False
else:
return True