Update behavior for event vs cloudevent function signature type
Closed this issue · 9 comments
The new behavior will be as follows:
- The function framework will accept legacy events and convert to a
CloudEvent
type for bothevent
andcloudevent
function signature types - User-provided functions will be validated at runtime to ensure the folliowing:
- The function accepts exactly one parameter argument
- The argument must be
RequestInterface
if the function signature type ishttp
- The argument must be
CloudEvent
if the function signature type isevent
orcloudevent
- The framework will throw an exception if any of the above conditions fail.
- Use functions-framework-conformance tests to verify
Sounds good to me. Thanks!
@mtraver how do we tell a legacy event
from a cloudevent
? Is it by the presence of the JSON data
property?
Node is similar, checking the 4 headers.
https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/master/src/cloudevents.ts#L28
Note, we should also check if application/cloudevents+json
(although GCP just needs the headers)
@mtraver this is very helpful, thank you. A few things:
- The python code you provided does not convert from
Event
toCloudEvent
, which we've decided to do here. Is there a standard way of converting fromEvent
toCloudEvent
? - We do not differ between a "structured" vs "binary" Cloud Event. Does that need to be added as well?
Here are the binary and structured converters in Python:
-
BinaryHTTPCloudEventConverter: https://sourcegraph.com/github.com/cloudevents/sdk-python@master/-/blob/cloudevents/sdk/converters/binary.py#L24
-
UnmarshalBinary: https://sourcegraph.com/github.com/cloudevents/sdk-python@master/-/blob/cloudevents/sdk/event/base.py#L253
-
JSONHTTPCloudEventConverter: https://sourcegraph.com/github.com/cloudevents/sdk-python@master/-/blob/cloudevents/sdk/converters/structured.py#L24
-
UnmarshalJSON: https://sourcegraph.com/github.com/cloudevents/sdk-python@master/-/blob/cloudevents/sdk/event/base.py#L221
@mtraver Do we need to support data_base64
? I see that is a field supported in Python that we are not currently supporting in PHP
@mtraver also, in the links you provided, I'm not seeing support for the legacy event fields resource
, eventType
, eventId
, or timestamp
Probably because cloudevents
SDK doesn't cover legacy events, that should be handled in the functions framework...