FAQ | This is a LIVE service | Changelog

Update cloud event handler to perform validation of received message

Description

Update the existing cloud_event handler decorator to perform validation on the received event. The received event is expected to consist of a CloudEvent object, with a data field consisting of a MessagePublishedData object.

Further details

This will require adding a Pydantic model to validate the MessagePublishedData object, the CloudEvent object should already be validated by the functions_framework.

In addition to adding this validation, the testing module should include a test support function to allow downstream implementers to build equivalent MessagePublishedData objects for testing.

Task list

Acceptance criteria

  • Messages received by a handler decorated with cloud_event have their payload validated to match the MessagePublishedData schema
  • Validation failures should respond with a bad request/400 status
    • Ensure exception is logged in this case

Links/references

Edited by Mike Knee