-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cloudevent signature type using cloudevents sdk-python (#78)
* Version 1.5.0 (#69) * Revert "Version 2.0.0 (#67)" This reverts commit f2471b4. * Revert "Add Cloud Events support for #55 (#56) (#64)" This reverts commit 8f3fe35. * Version 1.5.0 * Improve documentation around Dockerfiles (#70) * Add a link to an example Dockerfile in the top README.md * Update the inline Dockerfile to match file * Remove explicit gunicorn installation * make readme links absolute, useful Useful for when this readme appears on both github and pypi * added cloudevents 1.0.0 Signed-off-by: Curtis Mason <[email protected]> * reverted auto format Signed-off-by: Curtis Mason <[email protected]> * lint fixes Signed-off-by: Curtis Mason <[email protected]> * changed cloudevents to <=1.0 in setup Signed-off-by: Curtis Mason <[email protected]> * made cloudevents==1.0 Signed-off-by: Curtis Mason <[email protected]> * added cloudevent_view tests Signed-off-by: Curtis Mason <[email protected]> * test lint fixes Signed-off-by: Curtis Mason <[email protected]> * implemented try_catch in cloudevent view wrapper Signed-off-by: Curtis Mason <[email protected]> * import fix Signed-off-by: Curtis Mason <[email protected]> * adjusted cloud_run_cloudevents readme Signed-off-by: Curtis Mason <[email protected]> * added elif for cloudevent Signed-off-by: Curtis Mason <[email protected]> * adjusted README Signed-off-by: Curtis Mason <[email protected]> * upgraded to cloudevents 1.0.1 Signed-off-by: Curtis Mason <[email protected]> * import ordering lint fix Signed-off-by: Curtis Mason <[email protected]> * removed event from readme cloudevents section Signed-off-by: Curtis Mason <[email protected]> * resolved various nits and reverted event code Signed-off-by: Curtis Mason <[email protected]> * dockerfile env variables Signed-off-by: Curtis Mason <[email protected]> * Update examples/cloud_run_cloudevents/main.py Co-authored-by: Dustin Ingram <[email protected]> Signed-off-by: Curtis Mason <[email protected]> * cleaned up test_cloudevent_functions Signed-off-by: Curtis Mason <[email protected]> * Update examples/cloud_run_cloudevents/Dockerfile Co-authored-by: Adam Ross <[email protected]> Signed-off-by: Curtis Mason <[email protected]> * tunneled cloud_exceptions in flask abort Signed-off-by: Curtis Mason <[email protected]> * Added additional documentation in sample code Signed-off-by: Curtis Mason <[email protected]> * added time to tests Signed-off-by: Curtis Mason <[email protected]> * Update README.md Co-authored-by: Dustin Ingram <[email protected]> * Update README.md Co-authored-by: Dustin Ingram <[email protected]> * Update README.md Co-authored-by: Dustin Ingram <[email protected]> * Update README.md Co-authored-by: Dustin Ingram <[email protected]> * Update examples/cloud_run_cloudevents/send_cloudevent.py Co-authored-by: Dustin Ingram <[email protected]> * Update examples/cloud_run_cloudevents/README.md Co-authored-by: Dustin Ingram <[email protected]> * Update examples/cloud_run_cloudevents/README.md Co-authored-by: Dustin Ingram <[email protected]> * Update src/functions_framework/__init__.py Co-authored-by: Dustin Ingram <[email protected]> * Update src/functions_framework/__init__.py Co-authored-by: Dustin Ingram <[email protected]> * cloudevents 1.1.0 update Signed-off-by: Curtis Mason <[email protected]> * simplified exceptions debug Signed-off-by: Curtis Mason <[email protected]> * simplified cloudevent view test Signed-off-by: Curtis Mason <[email protected]> * Update src/functions_framework/__init__.py Co-authored-by: Dustin Ingram <[email protected]> * shebang cloudevent executable Signed-off-by: Curtis Mason <[email protected]> * cloudevents version bump Signed-off-by: Curtis Mason <[email protected]> * Removed InvalidStructuredJSON exception Signed-off-by: Curtis Mason <[email protected]> * Don't bump version in a feature branch * Add back missing CHANGELOG lines * Reformat with latest black Co-authored-by: Dustin Ingram <[email protected]> Co-authored-by: Katie McLaughlin <[email protected]> Co-authored-by: Adam Ross <[email protected]>
- Loading branch information
1 parent
033de0f
commit fccb88c
Showing
18 changed files
with
578 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# 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_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 | ||
* [`cloud_run_cloudevents`](./cloud_run_cloudevents/) - Deploying a [CloudEvent](https://github.com/cloudevents/sdk-python) function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework | ||
* [`cloud_run_event`](./cloud_run_event/) - Deploying a CloudEvent function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework | ||
* [`cloud_run_cloudevents`](./cloud_run_cloudevents/) - Deploying a [CloudEvent](https://github.com/cloudevents/sdk-python) function to [Cloud Run](http://cloud.google.com/run) with the Functions Framework |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,23 @@ | ||
# Deploying a CloudEvent function to Cloud Run with the Functions Framework | ||
This sample uses the [Cloud Events SDK](https://github.com/cloudevents/sdk-python) to send and receive a CloudEvent on Cloud Run. | ||
# Deploying a CloudEvent Function to Cloud Run with the Functions Framework | ||
|
||
This sample uses the [CloudEvents SDK](https://github.com/cloudevents/sdk-python) to send and receive a [CloudEvent](http://cloudevents.io) on Cloud Run. | ||
|
||
## How to run this locally | ||
|
||
Build the Docker image: | ||
|
||
```commandline | ||
docker build --tag ff_example . | ||
docker build -t cloudevent_example . | ||
``` | ||
|
||
Run the image and bind the correct ports: | ||
|
||
```commandline | ||
docker run -p:8080:8080 ff_example | ||
docker run --rm -p 8080:8080 -e PORT=8080 cloudevent_example | ||
``` | ||
|
||
Send an event to the container: | ||
|
||
```python | ||
from cloudevents.sdk import converters | ||
from cloudevents.sdk import marshaller | ||
from cloudevents.sdk.converters import structured | ||
from cloudevents.sdk.event import v1 | ||
import requests | ||
import json | ||
|
||
def run_structured(event, url): | ||
http_marshaller = marshaller.NewDefaultHTTPMarshaller() | ||
structured_headers, structured_data = http_marshaller.ToRequest( | ||
event, converters.TypeStructured, json.dumps | ||
) | ||
print("structured CloudEvent") | ||
print(structured_data.getvalue()) | ||
|
||
response = requests.post(url, | ||
headers=structured_headers, | ||
data=structured_data.getvalue()) | ||
response.raise_for_status() | ||
|
||
event = ( | ||
v1.Event() | ||
.SetContentType("application/json") | ||
.SetData('{"name":"john"}') | ||
.SetEventID("my-id") | ||
.SetSource("from-galaxy-far-far-away") | ||
.SetEventTime("tomorrow") | ||
.SetEventType("cloudevent.greet.you") | ||
) | ||
|
||
run_structured(event, "http://0.0.0.0:8080/") | ||
|
||
docker run -t cloudevent_example send_cloudevent.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# Optionally include additional dependencies here | ||
cloudevents>=1.2.0 | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/local/bin/python | ||
|
||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from cloudevents.http import CloudEvent, to_structured | ||
import requests | ||
import json | ||
|
||
|
||
# Create a cloudevent using https://github.com/cloudevents/sdk-python | ||
# Note we only need source and type because the cloudevents constructor by | ||
# default will set "specversion" to the most recent cloudevent version (e.g. 1.0) | ||
# and "id" to a generated uuid.uuid4 string. | ||
attributes = { | ||
"Content-Type": "application/json", | ||
"source": "from-galaxy-far-far-away", | ||
"type": "cloudevent.greet.you" | ||
} | ||
data = {"name":"john"} | ||
|
||
event = CloudEvent(attributes, data) | ||
|
||
# Send the event to our local docker container listening on port 8080 | ||
headers, data = to_structured(event) | ||
requests.post("http://localhost:8080/", headers=headers, data=data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.