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

Support Signature Type: CloudEvent #55

Closed
grant opened this issue May 28, 2020 · 8 comments
Closed

Support Signature Type: CloudEvent #55

grant opened this issue May 28, 2020 · 8 comments
Assignees

Comments

@grant
Copy link
Contributor

grant commented May 28, 2020

Support signature type cloudevent

This signature type should support HTTP requests with CloudEvent objects delivered via either structured and binary CloudEvent objects. Usually a CloudEvents SDK can handle transforming the HTTP request to a language-native CloudEvent object.

New signature cloudevent in Functions Framework contract

The end-user should see the parameter cloudevent, which is a native CloudEvent object using the CloudEvent SDK if possible.

Example User Experience (in Node)

function handler(cloudevent) {
  console.log(cloudevent.id);
  console.log(cloudevent.data.message);
  console.log(cloudevent.custom_values_should_be_accepted);
  return "anything"
}

Example HTTP requests

The CloudEvents specification requires support for both "binary" and "structured" encodings for CloudEvents delivered via HTTP. The Function Framework must support both encodings. A CloudEvents SDK might make this easier, but most SDKs are not complete, so logic may exist within the Framework.

Examples:

Binary content mode

POST /any/url/is/accepted HTTP/1.1
Host: example.com
ce-specversion: 1.0
ce-type: com.example.someevent
ce-time: 2018-04-05T03:56:24Z
ce-id: 1234-1234-1234
ce-source: /mycontext/subcontext
x-google-custom-header: 77
Content-Type: <contentType>
Content-Length: 33
{
    "message": "Hello World!"
}

Structured content mode

POST /someresource HTTP/1.1
Host: example.com
Content-Type: <contentType>
Content-Length: 266
{
    "specversion": "1.0",
    "type": "com.example.someevent",
    "time": "2018-04-05T03:56:24Z",
    "id": "1234-1234-1234",
    "source": "/mycontext/subcontext",
    "datacontenttype": "application/json",
    "data": {
        "message": "Hello World!"
    },
    "custom_values_should_be_accepted": 42
}

A user should be able to access all of the HTTP headers.
A user should be able to access the body of the CloudEvent in the data field of an object.


@grant
Copy link
Contributor Author

grant commented Jun 10, 2020

Sometimes GitHub prevents assignment, I think for new users, maybe a comment tag would work? @joelgerard

@joelgerard
Copy link
Contributor

OK. I have a PR coming for #55.

@joelgerard joelgerard self-assigned this Jun 10, 2020
grant pushed a commit that referenced this issue Jun 19, 2020
* Ignore IDE files.

* Use the test file directory as a basis instead of cwd. Allows tests to be run from anywhere and enables IDE debugger

* Add support for Cloud Events. Rough draft.

I will squash a bunch of these interim commits before submitting the PR.

DO NOT SUBMIT

* Return the functions return value. Test Cloud Events SDK 0.3. Add some error handling.

Please see all the TODO questions before I finish off this PR.

DO NOT SUBMIT

* Minor cleanup. Split test code.

* Clean up unused paths, split large test files into two, ensure functions DO NOT return a custom value. General tidy-up. Support binary functions.

* Fix lint errors with black.

* Fix lint errors with black.

* Update setup.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update tests/test_cloudevent_functions.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update tests/test_cloudevent_functions.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update src/functions_framework/__init__.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update tests/test_functions/cloudevents/main.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Clearer imports.

* don't factor out routes.

* Add a TODO for testing the different combinations of events and signature types.

* Add cloudevent as a signature type in the argument list.

* Clarify import.

* Clarify import.

* A sample that shows how to use a CloudEvent.

* In the case of a sig type / event type mismatch throw a 400

* Update the docs to use CloudEvent sig type instead of Event sig type. Note that I wrote the "Event" type is deprecated. Not sure if this is accurate.

* Lint fixes.

* Tests for checking correct event type corresponds to correct function sig. Fixed abort import error.

* Sort imports.

* Remove old example.

* Readme to explain how to run the sample locally.

* Rename cloud_event to cloudevent

* For legacy docs, add a notice to the new docs.

* There is no 1.1 event type.

* use the term cloudevent rather than event everywhere where we are talking about a CloudEvent to disambiguate these signature types.

* Update examples/cloudevents/README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloudevents/README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloudevents/README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloudevents/main.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update tests/test_view_functions.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Add legacy event back to docs.

* Add legacy event back to docs.

* Use abort from flask for consistency and fix return in event test.

* update docs and error messages to better mirror the other runtimes.

* Minor fixes to docs w.r.t. naming.

* Update src/functions_framework/__init__.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Fix enum per reviewer suggestion.

* Rename text event => strucuture event.

Co-authored-by: Joel Gerard <joelgerard@google.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
di added a commit that referenced this issue Jun 23, 2020
* Ignore IDE files.

* Use the test file directory as a basis instead of cwd. Allows tests to be run from anywhere and enables IDE debugger

* Add support for Cloud Events. Rough draft.

I will squash a bunch of these interim commits before submitting the PR.

DO NOT SUBMIT

* Return the functions return value. Test Cloud Events SDK 0.3. Add some error handling.

Please see all the TODO questions before I finish off this PR.

DO NOT SUBMIT

* Minor cleanup. Split test code.

* Clean up unused paths, split large test files into two, ensure functions DO NOT return a custom value. General tidy-up. Support binary functions.

* Fix lint errors with black.

* Fix lint errors with black.

* Update setup.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update tests/test_cloudevent_functions.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update tests/test_cloudevent_functions.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update src/functions_framework/__init__.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update tests/test_functions/cloudevents/main.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Clearer imports.

* don't factor out routes.

* Add a TODO for testing the different combinations of events and signature types.

* Add cloudevent as a signature type in the argument list.

* Clarify import.

* Clarify import.

* A sample that shows how to use a CloudEvent.

* In the case of a sig type / event type mismatch throw a 400

* Update the docs to use CloudEvent sig type instead of Event sig type. Note that I wrote the "Event" type is deprecated. Not sure if this is accurate.

* Lint fixes.

* Tests for checking correct event type corresponds to correct function sig. Fixed abort import error.

* Sort imports.

* Remove old example.

* Readme to explain how to run the sample locally.

* Rename cloud_event to cloudevent

* For legacy docs, add a notice to the new docs.

* There is no 1.1 event type.

* use the term cloudevent rather than event everywhere where we are talking about a CloudEvent to disambiguate these signature types.

* Update examples/cloudevents/README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloudevents/README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloudevents/README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloudevents/main.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update tests/test_view_functions.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Add legacy event back to docs.

* Add legacy event back to docs.

* Use abort from flask for consistency and fix return in event test.

* update docs and error messages to better mirror the other runtimes.

* Minor fixes to docs w.r.t. naming.

* Update src/functions_framework/__init__.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Fix enum per reviewer suggestion.

* Rename text event => strucuture event.

Co-authored-by: Joel Gerard <joelgerard@google.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

Co-authored-by: joelgerard <joelgerard@users.noreply.github.com>
Co-authored-by: Joel Gerard <joelgerard@google.com>
@grant
Copy link
Contributor Author

grant commented Jun 23, 2020

Fixed with #56.

@grant grant closed this as completed Jun 23, 2020
di added a commit that referenced this issue Jul 6, 2020
di added a commit that referenced this issue Jul 6, 2020
* 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
@grant grant reopened this Aug 7, 2020
@grant
Copy link
Contributor Author

grant commented Aug 7, 2020

Re-opening as CE support was reverted from master.

@grant grant assigned cumason123 and unassigned joelgerard Aug 7, 2020
@di
Copy link
Member

di commented Aug 7, 2020

Cloud Event support is part of the version-2.x-dev branch and was released in functions-framework==2.0.0.

@grant
Copy link
Contributor Author

grant commented Aug 8, 2020

OK. We should still have the landing page/default branch for this repo to be correct.

def hello(data, context): for a CloudEvents with signature event as stated in the README is not correct.

@di
Copy link
Member

di commented Aug 11, 2020

@di di closed this as completed Aug 11, 2020
@grant
Copy link
Contributor Author

grant commented Aug 11, 2020

Cool thanks! 👍

di added a commit that referenced this issue Aug 19, 2020
* 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
di added a commit that referenced this issue Aug 19, 2020
* 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

* Add legacy GCF Python 3.7 behavior (#77)

* Add legacy GCF Python 3.7 behavior

* Add test

* Modify tests

* Version 1.6.0 (#81)

Co-authored-by: Arjun Srinivasan <69502+asriniva@users.noreply.github.com>
di added a commit that referenced this issue Oct 22, 2020
* 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 <cumason@google.com>

* reverted auto format

Signed-off-by: Curtis Mason <cumason@google.com>

* lint fixes

Signed-off-by: Curtis Mason <cumason@google.com>

* changed cloudevents to <=1.0 in setup

Signed-off-by: Curtis Mason <cumason@google.com>

* made cloudevents==1.0

Signed-off-by: Curtis Mason <cumason@google.com>

* added cloudevent_view tests

Signed-off-by: Curtis Mason <cumason@google.com>

* test lint fixes

Signed-off-by: Curtis Mason <cumason@google.com>

* implemented try_catch in cloudevent view wrapper

Signed-off-by: Curtis Mason <cumason@google.com>

* import fix

Signed-off-by: Curtis Mason <cumason@google.com>

* adjusted cloud_run_cloudevents readme

Signed-off-by: Curtis Mason <cumason@google.com>

* added elif for cloudevent

Signed-off-by: Curtis Mason <cumason@google.com>

* adjusted README

Signed-off-by: Curtis Mason <cumason@google.com>

* upgraded to cloudevents 1.0.1

Signed-off-by: Curtis Mason <cumason@google.com>

* import ordering lint fix

Signed-off-by: Curtis Mason <cumason@google.com>

* removed event from readme cloudevents section

Signed-off-by: Curtis Mason <cumason@google.com>

* resolved various nits and reverted event code

Signed-off-by: Curtis Mason <cumason@google.com>

* dockerfile env variables

Signed-off-by: Curtis Mason <cumason@google.com>

* Update examples/cloud_run_cloudevents/main.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* cleaned up test_cloudevent_functions

Signed-off-by: Curtis Mason <cumason@google.com>

* Update examples/cloud_run_cloudevents/Dockerfile

Co-authored-by: Adam Ross <grayside@gmail.com>
Signed-off-by: Curtis Mason <cumason@google.com>

* tunneled cloud_exceptions in flask abort

Signed-off-by: Curtis Mason <cumason@google.com>

* Added additional documentation in sample code

Signed-off-by: Curtis Mason <cumason@google.com>

* added time to tests

Signed-off-by: Curtis Mason <cumason@google.com>

* Update README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloud_run_cloudevents/send_cloudevent.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloud_run_cloudevents/README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update examples/cloud_run_cloudevents/README.md

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update src/functions_framework/__init__.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* Update src/functions_framework/__init__.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* cloudevents 1.1.0 update

Signed-off-by: Curtis Mason <cumason@google.com>

* simplified exceptions debug

Signed-off-by: Curtis Mason <cumason@google.com>

* simplified cloudevent view test

Signed-off-by: Curtis Mason <cumason@google.com>

* Update src/functions_framework/__init__.py

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>

* shebang cloudevent executable

Signed-off-by: Curtis Mason <cumason@google.com>

* cloudevents version bump

Signed-off-by: Curtis Mason <cumason@google.com>

* Removed InvalidStructuredJSON exception

Signed-off-by: Curtis Mason <cumason@google.com>

* Don't bump version in a feature branch

* Add back missing CHANGELOG lines

* Reformat with latest black

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Katie McLaughlin <glasnt@google.com>
Co-authored-by: Adam Ross <grayside@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants