reenroll when failed

This commit is contained in:
2025-09-12 20:16:08 -03:00
parent e51964bc8b
commit 9fb1895557
4 changed files with 25 additions and 15 deletions

View File

@@ -6,8 +6,7 @@ from layercake.strutils import md5_hash
from schemas import Enrollment
Tenant = TypedDict('Tenant', {'id': str, 'name': str})
CreatedBy = TypedDict('CreatedBy', {'id': str, 'name': str})
Org = TypedDict('Org', {'org_id': str, 'name': str})
DeduplicationWindow = TypedDict('DeduplicationWindow', {'offset_days': int})
Subscription = TypedDict(
'Subscription',
@@ -38,7 +37,7 @@ class DeduplicationConflictError(Exception):
def enroll(
enrollment: Enrollment,
*,
created_by: CreatedBy | None = None,
org: Org | None = None,
subscription: Subscription | None = None,
linked_entities: frozenset[LinkedEntity] = frozenset(),
deduplication_window: DeduplicationWindow | None = None,
@@ -56,7 +55,11 @@ def enroll(
'sk': '0',
'created_at': now_,
**enrollment.model_dump(),
},
}
| ({'subscription_covered': True} if subscription else {})
| ({'tenant_id': org['org_id']} if org else {}),
# Post-migration: uncomment the following line
# | ({'org_id': org['org_id']} if org else {}),
)
transact.put(
item={
@@ -67,6 +70,8 @@ def enroll(
}
)
print(course.model_dump(include={'cert', 'access_period'}))
for entity in linked_entities:
keyprefix = entity.type.lower()
transact.put(
@@ -78,17 +83,16 @@ def enroll(
}
)
if created_by:
if org:
transact.put(
item={
'id': enrollment.id,
'sk': 'author',
# Post-migration: uncomment the following line
# 'sk': 'created_by',
'user_id': created_by['id'],
'name': created_by['name'],
# Post-migration: uncomment the following line
# 'sk': 'ORG',
'sk': 'tenant',
'created_at': now_,
},
}
| org
)
if subscription: