Skip to content

Commit 73f6e07

Browse files
author
Curtis Mason
committed
Created CloudEvent class
CloudEvents is a more pythonic interface for using cloud events. It is powered by internal marshallers and cloud event base classes. It performs basic validation on fields, and cloud event type checking. Signed-off-by: Curtis Mason <cumason@google.com>
1 parent cda44dd commit 73f6e07

19 files changed

+451
-407
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Expected Behavior
2+
3+
4+
## Actual Behavior
5+
6+
7+
## Steps to Reproduce the Problem
8+
9+
1.
10+
2.
11+
3.
12+
13+
## Specifications
14+
15+
- Platform:
16+
- Python Version:

.github/pull_request_template.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
- Link to issue this resolves
1+
Fixes #<issuelink>
22

3-
- What I did
3+
## Changes
44

5-
- How I did it
65

7-
- How to verify it
6+
## One line description for the changelog
87

9-
- One line description for the changelog
8+
9+
- [ ] Tests pass
10+
- [ ] Appropriate changes to README are included in PR

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ This SDK is still considered a work in progress, therefore things might (and
66
will) break with every update.
77

88
This SDK current supports the following versions of CloudEvents:
9+
910
- v1.0
1011
- v0.3
11-
- v0.2
12-
- v0.1
1312

1413
## Python SDK
1514

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

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

119-
120118
#### CloudEvent to request
121119

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

157155
The code below shows how integrate both libraries in order to create a CloudEvent from an HTTP request:
156+
158157
```python
159158
response = requests.get(url)
160159
response.raise_for_status()
161160
headers = response.headers
162161
data = io.BytesIO(response.content)
163-
event = v02.Event()
162+
event = v1.Event()
164163
http_marshaller = marshaller.NewDefaultHTTPMarshaller()
165164
event = http_marshaller.FromRequest(
166165
event, headers, data, json.load)
167166

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

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

172171
## SDK versioning
173172

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

180180
## Community
181181

cloudevents/sdk/converters/binary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
from cloudevents.sdk import exceptions
1818
from cloudevents.sdk.converters import base
1919
from cloudevents.sdk.event import base as event_base
20-
from cloudevents.sdk.event import v02, v03, v1
20+
from cloudevents.sdk.event import v03, v1
2121

2222

2323
class BinaryHTTPCloudEventConverter(base.Converter):
2424

2525
TYPE = "binary"
26-
SUPPORTED_VERSIONS = [v02.Event, v03.Event, v1.Event]
26+
SUPPORTED_VERSIONS = [v03.Event, v1.Event]
2727

2828
def can_read(self, content_type: str) -> bool:
2929
return True

cloudevents/sdk/event/base.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
import json
1717
import typing
1818

19+
_ce_required_fields = {
20+
'id',
21+
'source',
22+
'type',
23+
'specversion'
24+
}
25+
26+
27+
_ce_optional_fields = {
28+
'datacontenttype',
29+
'schema',
30+
'subject',
31+
'time'
32+
}
33+
1934

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

118133
def UnmarshalJSON(self, b: typing.IO, data_unmarshaller: typing.Callable):
119134
raw_ce = json.load(b)
135+
120136
for name, value in raw_ce.items():
121137
if name == "data":
122138
value = data_unmarshaller(value)
@@ -134,7 +150,6 @@ def UnmarshalBinary(
134150
self.SetContentType(value)
135151
elif header.startswith("ce-"):
136152
self.Set(header[3:], value)
137-
138153
self.Set("data", data_unmarshaller(body))
139154

140155
def MarshalBinary(

cloudevents/sdk/event/v01.py

Lines changed: 0 additions & 137 deletions
This file was deleted.

cloudevents/sdk/event/v02.py

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)