Skip to content

More pythonic interface for CloudEvents #36

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
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Expected Behavior


## Actual Behavior


## Steps to Reproduce the Problem

1.
2.
3.

## Specifications

- Platform:
- Python Version:
11 changes: 6 additions & 5 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
- Link to issue this resolves
Fixes #<issuelink>

- What I did
## Changes

- How I did it

- How to verify it
## One line description for the changelog

- One line description for the changelog

- [ ] Tests pass
- [ ] Appropriate changes to README are included in PR
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ This SDK is still considered a work in progress, therefore things might (and
will) break with every update.

This SDK current supports the following versions of CloudEvents:

- v1.0
- v0.3
- v0.2
- v0.1

## Python SDK

Expand Down Expand Up @@ -116,7 +115,6 @@ In this topic you'd find various example how to integrate an SDK with various HT

One of popular framework is [`requests`](http://docs.python-requests.org/en/master/).


#### CloudEvent to request

The code below shows how integrate both libraries in order to convert a CloudEvent into an HTTP request:
Expand Down Expand Up @@ -155,27 +153,29 @@ Complete example of turning a CloudEvent into a request you can find [here](samp
#### Request to CloudEvent

The code below shows how integrate both libraries in order to create a CloudEvent from an HTTP request:

```python
response = requests.get(url)
response.raise_for_status()
headers = response.headers
data = io.BytesIO(response.content)
event = v02.Event()
event = v1.Event()
http_marshaller = marshaller.NewDefaultHTTPMarshaller()
event = http_marshaller.FromRequest(
event, headers, data, json.load)

```
Complete example of turning a CloudEvent into a request you can find [here](samples/python-requests/request_to_cloudevent.py).

Complete example of turning a CloudEvent into a request you can find [here](samples/python-requests/request_to_cloudevent.py).

## SDK versioning

The goal of this package is to provide support for all released versions of CloudEvents, ideally while maintaining
the same API. It will use semantic versioning with following rules:
* MAJOR version increments when backwards incompatible changes is introduced.
* MINOR version increments when backwards compatible feature is introduced INCLUDING support for new CloudEvents version.
* PATCH version increments when a backwards compatible bug fix is introduced.

- MAJOR version increments when backwards incompatible changes is introduced.
- MINOR version increments when backwards compatible feature is introduced INCLUDING support for new CloudEvents version.
- PATCH version increments when a backwards compatible bug fix is introduced.

## Community

Expand Down
4 changes: 2 additions & 2 deletions cloudevents/sdk/converters/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
from cloudevents.sdk import exceptions
from cloudevents.sdk.converters import base
from cloudevents.sdk.event import base as event_base
from cloudevents.sdk.event import v02, v03, v1
from cloudevents.sdk.event import v03, v1


class BinaryHTTPCloudEventConverter(base.Converter):

TYPE = "binary"
SUPPORTED_VERSIONS = [v02.Event, v03.Event, v1.Event]
SUPPORTED_VERSIONS = [v03.Event, v1.Event]

def can_read(self, content_type: str) -> bool:
return True
Expand Down
17 changes: 16 additions & 1 deletion cloudevents/sdk/event/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
import json
import typing

_ce_required_fields = {
'id',
'source',
'type',
'specversion'
}


_ce_optional_fields = {
'datacontenttype',
'schema',
'subject',
'time'
}


# TODO(slinkydeveloper) is this really needed?
class EventGetterSetter(object):
Expand Down Expand Up @@ -117,6 +132,7 @@ def MarshalJSON(self, data_marshaller: typing.Callable) -> typing.IO:

def UnmarshalJSON(self, b: typing.IO, data_unmarshaller: typing.Callable):
raw_ce = json.load(b)

for name, value in raw_ce.items():
if name == "data":
value = data_unmarshaller(value)
Expand All @@ -134,7 +150,6 @@ def UnmarshalBinary(
self.SetContentType(value)
elif header.startswith("ce-"):
self.Set(header[3:], value)

self.Set("data", data_unmarshaller(body))

def MarshalBinary(
Expand Down
137 changes: 0 additions & 137 deletions cloudevents/sdk/event/v01.py

This file was deleted.

88 changes: 0 additions & 88 deletions cloudevents/sdk/event/v02.py

This file was deleted.

Loading