Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cloud Events support for #55 #56

Merged
merged 50 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
86723ec
Ignore IDE files.
Jun 6, 2020
b0cd71a
Use the test file directory as a basis instead of cwd. Allows tests t…
joelgerard Jun 6, 2020
f1ebf4a
Merge branch 'master' of github.com:joelgerard/functions-framework-py…
Jun 8, 2020
64d8e3d
Add support for Cloud Events. Rough draft.
joelgerard Jun 9, 2020
bbf6d35
Return the functions return value. Test Cloud Events SDK 0.3. Add som…
joelgerard Jun 10, 2020
3bcb69d
Minor cleanup. Split test code.
joelgerard Jun 12, 2020
42ea896
Clean up unused paths, split large test files into two, ensure functi…
joelgerard Jun 15, 2020
4b3a10e
Merge branch 'master' of github.com:joelgerard/functions-framework-py…
joelgerard Jun 15, 2020
a1dddbb
Fix lint errors with black.
joelgerard Jun 15, 2020
4407259
Fix lint errors with black.
joelgerard Jun 15, 2020
47acff6
Merge remote-tracking branch 'origin/master'
joelgerard Jun 16, 2020
d40f4a0
Update setup.py
joelgerard Jun 16, 2020
1d83d3c
Update tests/test_cloudevent_functions.py
joelgerard Jun 16, 2020
7c46f60
Update tests/test_cloudevent_functions.py
joelgerard Jun 16, 2020
8832081
Update src/functions_framework/__init__.py
joelgerard Jun 16, 2020
7a16331
Update tests/test_functions/cloudevents/main.py
joelgerard Jun 16, 2020
16a6858
Clearer imports.
joelgerard Jun 16, 2020
bdbf5e2
don't factor out routes.
joelgerard Jun 16, 2020
ea2e28c
Add a TODO for testing the different combinations of events and signa…
joelgerard Jun 16, 2020
9e8d874
Add cloudevent as a signature type in the argument list.
joelgerard Jun 16, 2020
06ffc2d
Clarify import.
joelgerard Jun 16, 2020
ecb0b61
Clarify import.
joelgerard Jun 16, 2020
fa727f1
Merge remote-tracking branch 'origin/master'
joelgerard Jun 16, 2020
209a8d6
A sample that shows how to use a CloudEvent.
joelgerard Jun 16, 2020
f573a1e
In the case of a sig type / event type mismatch throw a 400
joelgerard Jun 16, 2020
7212640
Update the docs to use CloudEvent sig type instead of Event sig type.…
joelgerard Jun 16, 2020
974d52b
Lint fixes.
joelgerard Jun 16, 2020
9b87a6e
Tests for checking correct event type corresponds to correct function…
joelgerard Jun 16, 2020
8d33033
Sort imports.
joelgerard Jun 16, 2020
c297097
Remove old example.
joelgerard Jun 17, 2020
5176b8c
Readme to explain how to run the sample locally.
joelgerard Jun 17, 2020
f499790
Rename cloud_event to cloudevent
joelgerard Jun 17, 2020
973beaf
For legacy docs, add a notice to the new docs.
joelgerard Jun 17, 2020
30b9259
There is no 1.1 event type.
joelgerard Jun 17, 2020
48e939e
remove uneeded git installation.
joelgerard Jun 17, 2020
2532cec
use the term cloudevent rather than event everywhere where we are tal…
joelgerard Jun 17, 2020
7928d5d
Update examples/cloudevents/README.md
joelgerard Jun 17, 2020
a38b480
Update examples/cloudevents/README.md
joelgerard Jun 17, 2020
154de1c
Update examples/cloudevents/README.md
joelgerard Jun 17, 2020
2a92d9c
Update examples/cloudevents/main.py
joelgerard Jun 17, 2020
a2b3c67
Update tests/test_view_functions.py
joelgerard Jun 17, 2020
dbc44a3
Add legacy event back to docs.
joelgerard Jun 17, 2020
eafa781
Add legacy event back to docs.
joelgerard Jun 17, 2020
6ce6f63
Use abort from flask for consistency and fix return in event test.
joelgerard Jun 17, 2020
18432e8
Merge branch 'master' of github.com:joelgerard/functions-framework-py…
joelgerard Jun 17, 2020
c2ba64d
update docs and error messages to better mirror the other runtimes.
joelgerard Jun 17, 2020
6889f54
Minor fixes to docs w.r.t. naming.
joelgerard Jun 18, 2020
271e976
Update src/functions_framework/__init__.py
joelgerard Jun 18, 2020
7cb1d88
Fix enum per reviewer suggestion.
joelgerard Jun 18, 2020
2e34e8b
Rename text event => strucuture event.
joelgerard Jun 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,41 @@ You can configure the Functions Framework using command-line flags or environmen
| `--host` | `HOST` | The host on which the Functions Framework listens for requests. Default: `0.0.0.0` |
| `--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080` |
| `--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function` |
| `--signature-type` | `FUNCTION_SIGNATURE_TYPE` | The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http` or `cloudevent`. Note: the`event` signature type is legacy; `cloudevent` is preferred. |
| `--signature-type` | `FUNCTION_SIGNATURE_TYPE` | The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http` or `event` or `cloudevent` |
| `--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory) |
| `--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` |


# Enable Google Cloud Functions Events

The Functions Framework can unmarshall incoming
Google Cloud Functions [event](https://cloud.google.com/functions/docs/concepts/events-triggers#events) payloads to `data` and `context` objects.
These will be passed as arguments to your function when it receives a request.
Note that your function must use the `event`-style function signature:


```python
def hello(data, context):
print(data)
print(context)
```

To enable automatic unmarshalling, set the function signature type to `event`
using a command-line flag or an environment variable. By default, the HTTP
signature will be used and automatic event unmarshalling will be disabled.

For more details on this signature type, check out the Google Cloud Functions
documentation on
[background functions](https://cloud.google.com/functions/docs/writing/background#cloud_pubsub_example).

See the [running example](examples/cloud_run_event).
joelgerard marked this conversation as resolved.
Show resolved Hide resolved

# Enable CloudEvents

The Functions Framework can unmarshall incoming [CloudEvents](http://cloudevents.io) payloads to a Cloud Event object.
In this case, you can create a function that accepts a single argument, `cloudevent`, e.g.:
The Functions Framework can unmarshall incoming
[CloudEvents](http://cloudevents.io) payloads to a `cloudevent` object.
joelgerard marked this conversation as resolved.
Show resolved Hide resolved
It will be passed as an argument to your function when it receives a request.
Note that your function must use the `cloudevent`-style function signature


```python
Expand All @@ -147,15 +174,7 @@ def hello(cloudevent):

To enable automatic unmarshalling, set the function signature type to `cloudevent` using the `--signature-type` command-line flag or the `FUNCTION_SIGNATURE_TYPE` environment variable. By default, the HTTP signature type will be used and automatic event unmarshalling will be disabled.

Note, you can still use the legacy `event` function signature although in this case the function signature is slightly different, i.e.:

```python
def hello(data, context):
print(data)
print(context)
```

For more details on this signature type, check out the Google Cloud Functions documentation on [background functions](https://cloud.google.com/functions/docs/writing/background#cloud_pubsub_example).
See the [running example](examples/cloudevents).

# Advanced Examples

Expand Down
5 changes: 3 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Python Functions Frameworks Examples

* [`cloud_run_http`](./cloud_run_http/) - Deploying an HTTP function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
* [`cloud_events`](./cloud_events/) - Deploying a CloudEvent function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
* [`cloud_run_event`](./cloud_run_event/) - Deploying a legacy Event function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
* [`cloud_run_event`](./cloud_run_event/) - Deploying a [Google Cloud Functions Event](https://cloud.google.com/functions/docs/concepts/events-triggers#events) function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework
joelgerard marked this conversation as resolved.
Show resolved Hide resolved
* [`cloudevents`](./cloudevents/) - Deploying a [CloudEvent](https://github.com/cloudevents/sdk-python) function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework



5 changes: 3 additions & 2 deletions examples/cloud_run_event/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Events Example (legacy)
This example demonstrates how to write an event function. This will be retired in favor of Cloud Events. Please see [this example](../cloudevents).
# Google Cloud Functions Events Example
This example demonstrates how to write an event function. Note that you can also use [CloudEvents](https://github.com/cloudevents/sdk-python)
([example](../cloudevents)), which is a different construct.
2 changes: 1 addition & 1 deletion src/functions_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def view_func(path):
flask.abort(
400,
description="The FUNCTION_SIGNATURE_TYPE for this function is set to event "
"but no legacy event was given. If you are using CloudEvents set "
"but no Google Cloud Functions Event was given. If you are using CloudEvents set "
"FUNCTION_SIGNATURE_TYPE=cloudevent",
)

Expand Down