Update docs (#31)

* Update README to show v1 examples

Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* Update release process

Signed-off-by: Dustin Ingram <di@users.noreply.github.com>

* Update CHANGELOG

Signed-off-by: Dustin Ingram <di@users.noreply.github.com>
This commit is contained in:
Dustin Ingram 2020-04-27 19:18:23 -05:00 committed by GitHub
parent bcacf3391a
commit cda44dd83d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 125 additions and 72 deletions

View File

@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [0.3.0]
### Added ### Added
- Added Cloudevents V0.3 and V1 implementations ([#22]) - Added Cloudevents V0.3 and V1 implementations ([#22])
- Add helpful text to README ([#23]) - Add helpful text to README ([#23])
@ -45,7 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Initial release - Initial release
[Unreleased]: https://github.com/cloudevents/sdk-python/compare/0.2.4...HEAD [0.3.0]: https://github.com/cloudevents/sdk-python/compare/0.2.4...HEAD
[0.2.4]: https://github.com/cloudevents/sdk-python/compare/0.2.3...0.2.4 [0.2.4]: https://github.com/cloudevents/sdk-python/compare/0.2.3...0.2.4
[0.2.3]: https://github.com/cloudevents/sdk-python/compare/0.2.2...0.2.3 [0.2.3]: https://github.com/cloudevents/sdk-python/compare/0.2.2...0.2.3
[0.2.2]: https://github.com/cloudevents/sdk-python/compare/0.2.1...0.2.2 [0.2.2]: https://github.com/cloudevents/sdk-python/compare/0.2.1...0.2.2

107
README.md
View File

@ -6,6 +6,8 @@ This SDK is still considered a work in progress, therefore things might (and
will) break with every update. will) break with every update.
This SDK current supports the following versions of CloudEvents: This SDK current supports the following versions of CloudEvents:
- v1.0
- v0.3
- v0.2 - v0.2
- v0.1 - v0.1
@ -13,70 +15,97 @@ This SDK current supports the following versions of CloudEvents:
Package **cloudevents** provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec. Package **cloudevents** provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec.
Parsing upstream Event from HTTP Request: Parsing upstream structured Event from HTTP request:
```python ```python
import io import io
from cloudevents.sdk.event import v02 from cloudevents.sdk.event import v1
from cloudevents.sdk import marshaller from cloudevents.sdk import marshaller
m = marshaller.NewDefaultHTTPMarshaller() m = marshaller.NewDefaultHTTPMarshaller()
event = m.FromRequest(
v02.Event(),
{
"content-type": "application/cloudevents+json",
"ce-specversion": "0.2",
"ce-time": "2018-10-23T12:28:22.4579346Z",
"ce-id": "96fb5f0b-001e-0108-6dfe-da6e2806f124",
"ce-source": "<source-url>",
"ce-type": "word.found.name",
},
io.BytesIO(b"this is where your CloudEvent data"),
lambda x: x.read()
)
event = m.FromRequest(
v1.Event(),
{"content-type": "application/cloudevents+json"},
io.StringIO(
"""
{
"specversion": "1.0",
"datacontenttype": "application/json",
"type": "word.found.name",
"id": "96fb5f0b-001e-0108-6dfe-da6e2806f124",
"time": "2018-10-23T12:28:22.4579346Z",
"source": "<source-url>"
}
"""
),
lambda x: x.read(),
)
```
Parsing upstream binary Event from HTTP request:
```python
import io
from cloudevents.sdk.event import v1
from cloudevents.sdk import marshaller
m = marshaller.NewDefaultHTTPMarshaller()
event = m.FromRequest(
v1.Event(),
{
"ce-specversion": "1.0",
"content-type": "application/json",
"ce-type": "word.found.name",
"ce-id": "96fb5f0b-001e-0108-6dfe-da6e2806f124",
"ce-time": "2018-10-23T12:28:22.4579346Z",
"ce-source": "<source-url>",
},
io.BytesIO(b"this is where your CloudEvent data"),
lambda x: x.read(),
)
``` ```
Creating a minimal CloudEvent in version 0.1: Creating a minimal CloudEvent in version 0.1:
```python ```python
from cloudevents.sdk.event import v01 from cloudevents.sdk.event import v1
event = ( event = (
v01.Event(). v1.Event()
SetContentType("application/json"). .SetContentType("application/json")
SetData('{"name":"john"}'). .SetData('{"name":"john"}')
SetEventID("my-id"). .SetEventID("my-id")
SetSource("from-galaxy-far-far-away"). .SetSource("from-galaxy-far-far-away")
SetEventTime("tomorrow"). .SetEventTime("tomorrow")
SetEventType("cloudevent.greet.you") .SetEventType("cloudevent.greet.you")
) )
``` ```
Creating HTTP request from CloudEvent: Creating HTTP request from CloudEvent:
```python ```python
from cloudevents.sdk import converters from cloudevents.sdk import converters
from cloudevents.sdk import marshaller from cloudevents.sdk import marshaller
from cloudevents.sdk.converters import structured from cloudevents.sdk.converters import structured
from cloudevents.sdk.event import v01 from cloudevents.sdk.event import v1
event = ( event = (
v01.Event(). v1.Event()
SetContentType("application/json"). .SetContentType("application/json")
SetData('{"name":"john"}'). .SetData('{"name":"john"}')
SetEventID("my-id"). .SetEventID("my-id")
SetSource("from-galaxy-far-far-away"). .SetSource("from-galaxy-far-far-away")
SetEventTime("tomorrow"). .SetEventTime("tomorrow")
SetEventType("cloudevent.greet.you") .SetEventType("cloudevent.greet.you")
)
m = marshaller.NewHTTPMarshaller(
[
structured.NewJSONHTTPCloudEventConverter()
]
) )
m = marshaller.NewHTTPMarshaller([structured.NewJSONHTTPCloudEventConverter()])
headers, body = m.ToRequest(event, converters.TypeStructured, lambda x: x) headers, body = m.ToRequest(event, converters.TypeStructured, lambda x: x)
``` ```
## HOWTOs with various Python HTTP frameworks ## HOWTOs with various Python HTTP frameworks
@ -85,7 +114,7 @@ In this topic you'd find various example how to integrate an SDK with various HT
### Python requests ### Python requests
One of popular framework is [0.2-force-improvements](http://docs.python-requests.org/en/master/). One of popular framework is [`requests`](http://docs.python-requests.org/en/master/).
#### CloudEvent to request #### CloudEvent to request

View File

@ -1,8 +1,35 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Fail fast and fail hard.
set -eo pipefail
# Check for our version
if [ -z "$CLOUDEVENTS_SDK_VERSION" ]; then
echo "Need to set CLOUDEVENTS_SDK_VERSION"
exit 1
fi
# Run tests on target branch
tox
# Cut off stable branch
git checkout -b v${CLOUDEVENTS_SDK_VERSION}-stable git checkout -b v${CLOUDEVENTS_SDK_VERSION}-stable
# Create GitHub tag
git tag -a ${CLOUDEVENTS_SDK_VERSION} -m "${CLOUDEVENTS_SDK_VERSION}"
# Build distribution package
rm -rf dist
pip install -U setuptools wheel
python setup.py sdist bdist_wheel
# Submit relase to PyPI
pip install -U twine
twine upload dist/*
# Push the release to GitHub
git push origin v${CLOUDEVENTS_SDK_VERSION}-stable git push origin v${CLOUDEVENTS_SDK_VERSION}-stable
PBR_VERSION=${CLOUDEVENTS_SDK_VERSION} python setup.py sdist bdist_wheel git push --tags
twine upload dist/cloudevents-${CLOUDEVENTS_SDK_VERSIONN}*
# Switch back to the master branch
git checkout master git checkout master

View File

@ -1,49 +1,35 @@
Release process # Release process
===============
Run tests on target brunch ## Run tests on target branch
--------------------------
Steps: Steps:
tox tox
Cut off stable branch ## Cut off stable branch
---------------------
Steps: Steps:
git checkout -b vX.X.X-stable git checkout -b vX.X.X-stable
git push origin vX.X.X-stable
Create GitHub tag ## Create GitHub tag
-----------------
Steps: Steps:
Releases ---> Draft New Release git tag -a X.X.X -m "X.X.X"
Name: CloudEvents Python SDK version X.X.X stable release
Collect changes from previous version ## Build distribution package
-------------------------------------
Steps: Steps:
git log --oneline --decorate rm -rf dist
pip install -U setuptools wheel
python setup.py sdist bdist_wheel
Build distribution package ## Check install capability for the wheel
--------------------------
Steps:
PBR_VERSION=X.X.X python setup.py sdist bdist_wheel
Check install capability for the wheel
--------------------------------------
Steps: Steps:
@ -52,15 +38,23 @@ Steps:
pip install dist/cloudevents-X.X.X-py3-none-any.whl pip install dist/cloudevents-X.X.X-py3-none-any.whl
Submit release to PYPI ## Submit release to PyPI
----------------------
Steps: Steps:
twine upload dist/cloudevents-X.X.X-py3-none-any.whl pip install -U twine
twine upload dist/*
Verify install capability for the wheel
--------------------------------------- ## Push the release to GitHub
Steps:
git push origin vX.X.X-stable
git push --tags
## Verify install capability for the wheel
Steps: Steps:

View File

@ -24,3 +24,6 @@ packages =
[global] [global]
setup-hooks = setup-hooks =
pbr.hooks.setup_hook pbr.hooks.setup_hook
[pbr]
skip_changelog = True