add expires_at to cert

This commit is contained in:
2025-09-17 20:34:08 -03:00
parent ad1a57e6a0
commit 51bf5191e9
5 changed files with 12 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
import json
from datetime import datetime
from datetime import datetime, timedelta
import requests
from aws_lambda_powertools import Logger
@@ -36,12 +36,14 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
# There is no certificate to issue from metadata
return False
cert = course['cert']
started_at: datetime = fromisoformat(course['started_at']) # type: ignore
completed_at: datetime = fromisoformat(course['completed_at']) # type: ignore
cert_expires_at = now_ + timedelta(days=int(cert['exp_interval']))
json_data = json.dumps(
data = json.dumps(
{
'template_s3_uri': course['cert']['s3_uri'],
'template_s3_uri': cert['s3_uri'],
'template_vars': {
'name': new_image['user']['name'],
'cpf': _cpffmt(new_image['user']['cpf']),
@@ -54,7 +56,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
},
)
# Send template URI and data to Paperforge API to generate a PDF
r = requests.post(PAPERFORGE_API, data=json_data)
r = requests.post(PAPERFORGE_API, data=data)
r.raise_for_status()
object_key = f'issuedcerts/{enrollment_id}.pdf'
@@ -83,6 +85,7 @@ def lambda_handler(event: EventBridgeEvent, context: LambdaContext) -> bool:
':issued_cert': {
's3_uri': s3_uri,
'issued_at': now_,
'expires_at': cert_expires_at,
},
},
cond_expr='attribute_exists(sk)',