-
Notifications
You must be signed in to change notification settings - Fork 118
Added cloudevent signature type using cloudevents sdk-python #78
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
Merged
di
merged 50 commits into
GoogleCloudPlatform:master
from
cumason123:cloudevents-1.0.0-refactor
Oct 22, 2020
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
6f0d848
Version 1.5.0 (#69)
di 95d0b35
Improve documentation around Dockerfiles (#70)
glasnt ac48e64
added cloudevents 1.0.0
0d19c7f
reverted auto format
000d83c
lint fixes
8f78a8b
changed cloudevents to <=1.0 in setup
b9695ac
made cloudevents==1.0
9bad206
merged cloudevents from master into version-1.x-dev
eb40068
added cloudevent_view tests
ab1b800
test lint fixes
19f066c
implemented try_catch in cloudevent view wrapper
5b480ec
import fix
351bf58
adjusted cloud_run_cloudevents readme
9c323c9
added elif for cloudevent
9fc5a56
adjusted README
a0d841b
upgraded to cloudevents 1.0.1
d48d0b9
import ordering lint fix
cd2f753
removed event from readme cloudevents section
0d94485
resolved various nits and reverted event code
2b0a8ab
dockerfile env variables
a859e7b
Update examples/cloud_run_cloudevents/main.py
cumason123 fb48d89
cleaned up test_cloudevent_functions
cb61aab
Update examples/cloud_run_cloudevents/Dockerfile
cumason123 33f867c
tunneled cloud_exceptions in flask abort
8030642
Added additional documentation in sample code
430a3d1
added time to tests
1c2c1b4
Update README.md
cumason123 78cef16
Update README.md
cumason123 d2cdec0
Update README.md
cumason123 1f0c56b
Update README.md
cumason123 280379f
Update examples/cloud_run_cloudevents/send_cloudevent.py
cumason123 3032e3e
Update examples/cloud_run_cloudevents/README.md
cumason123 6400a6d
Update examples/cloud_run_cloudevents/README.md
cumason123 c8f1948
Update src/functions_framework/__init__.py
cumason123 3c20027
Update src/functions_framework/__init__.py
cumason123 1b67e3d
cloudevents 1.1.0 update
e83785d
simplified exceptions debug
a546ce2
simplified cloudevent view test
7f57803
Update src/functions_framework/__init__.py
cumason123 8ec12b4
shebang cloudevent executable
3235319
Merge branch 'cloudevents-1.0.0-refactor' of github.com:cumason123/fu…
bf0a40f
cloudevents version bump
a08e485
Merge branch 'master' of github.com:GoogleCloudPlatform/functions-fra…
e1e0395
Removed InvalidStructuredJSON exception
76eb1ac
Merge branch 'master' into cloudevents-1.0.0-refactor
di 5e17f8f
Don't bump version in a feature branch
di 7477dea
Add back missing CHANGELOG lines
di 2d2413e
Reformat with latest black
di 15ad5a9
Merge branch 'master' into cloudevents-1.0.0-refactor
di 7e16ae1
Merge branch 'master' into cloudevents-1.0.0-refactor
di File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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: | ||
cumason123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```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 | ||
``` | ||
grant marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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 hidden or 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 | ||
grant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.