Add Pydantic Model Validation for CloudEvents
As a developer,
I would like to use Pydantic models for automatic validation of CloudEvents in ucam-faas
to ensure data integrity and ease of handling event data structures.
Background
The ucam-faas currently handles CloudEvents but lacks automatic validation of the event data structure. By integrating Pydantic models and adding decorators, we can validate the data payloads against predefined schemas, thus reducing errors and improving data handling. This enhancement will use the existing CloudEvent and CamSISCloudEventData schemas, generated Pydantic models, and extend functionality to support these validations.
Acceptance Criteria
-
Implement a decorator @cloud_event_pydanticthat wraps cloud event functions. -
The decorator should accept a Pydanticmodel class for validation. -
Raise appropriate validation errors if the data does not conform to the schema. -
Update README.mdto include examples of using the new decorator.
Code Example
@ucam_faas.cloud_event_pydantic(CamSISCloudEventData)
def handle_camsis_event(camsis_event: CamSISCloudEventData):
# CloudEvent and CamSISRecordExists validated and loaded in pydantic object
do_something = camsis_event.xml_payload
https://gitlab.developers.cam.ac.uk/uis/devops/iam/idhub/api/-/merge_requests/60#note_637165
Edited by Eugene E.