-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Cloud Event Abstraction #13542
Cloud Event Abstraction #13542
Changes from all commits
d111542
a8a01f9
1b62b89
8022a0c
f1e1cbe
db40e9c
a82a463
71ecc66
d38c325
48394c9
1cd55e5
6fb8283
38a76e6
5a91d22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,10 @@ def send(self, events, **kwargs): | |
events = [events] | ||
|
||
if all(isinstance(e, CloudEvent) for e in events) or all(_is_cloud_event(e) for e in events): | ||
try: | ||
events = [e._to_generated(**kwargs) for e in events] | ||
except AttributeError: | ||
pass # means it's a dictionary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rakshith91 still, how could this happen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry - missed it |
||
kwargs.setdefault("content_type", "application/cloudevents-batch+json; charset=utf-8") | ||
self._client.publish_cloud_event_events(self._topic_hostname, events, **kwargs) | ||
elif all(isinstance(e, EventGridEvent) for e in events) or all(isinstance(e, dict) for e in events): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
interactions: | ||
- request: | ||
body: '[{"id": "a3f05c78-9a8d-44d8-a1a3-131b8da61192", "source": "http://samplesource.dev", | ||
"data_base64": "Y2xvdWRldmVudA==", "type": "Sample.Cloud.Event", "time": "2020-09-04T17:06:31.601865Z", | ||
"specversion": "1.0"}]' | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '211' | ||
Content-Type: | ||
- application/cloudevents-batch+json; charset=utf-8 | ||
User-Agent: | ||
- azsdk-python-eventgridpublisherclient/unknown Python/3.7.3 (Windows-10-10.0.18362-SP0) | ||
method: POST | ||
uri: https://cloudeventgridtestegtopic.westus-1.eventgrid.azure.net/api/events?api-version=2018-01-01 | ||
response: | ||
body: | ||
string: '' | ||
headers: | ||
api-supported-versions: | ||
- '2018-01-01' | ||
content-length: | ||
- '0' | ||
date: | ||
- Fri, 04 Sep 2020 17:06:29 GMT | ||
server: | ||
- Microsoft-HTTPAPI/2.0 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
interactions: | ||
- request: | ||
body: '[{"reason_code": 204, "extension": "extension", "id": "9da8e4ce-df2c-4480-b809-c7132fb3ee74", | ||
"source": "http://samplesource.dev", "data": "cloudevent", "type": "Sample.Cloud.Event", | ||
"time": "2020-09-03T21:37:15.165652Z", "specversion": "1.0"}]' | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '244' | ||
Content-Type: | ||
- application/cloudevents-batch+json; charset=utf-8 | ||
User-Agent: | ||
- azsdk-python-eventgridpublisherclient/unknown Python/3.7.3 (Windows-10-10.0.18362-SP0) | ||
method: POST | ||
uri: https://cloudeventgridtestegtopic.westus-1.eventgrid.azure.net/api/events?api-version=2018-01-01 | ||
response: | ||
body: | ||
string: '' | ||
headers: | ||
api-supported-versions: | ||
- '2018-01-01' | ||
content-length: | ||
- '0' | ||
date: | ||
- Thu, 03 Sep 2020 21:37:13 GMT | ||
server: | ||
- Microsoft-HTTPAPI/2.0 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extensions should be passed part of additional_properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies if I misremembered our call the other day but did we reach a conclusion about not using kwargs for extensions? My fear being that we've just lost symmetry if someone **'s a serialized cloudevent back into itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i took the liberty to slightly change the behavior to this
will serialize to
In other words, extensions can be accepted as both kwargs and an explicit extensions dictionary
Rationale is
I can disallow kwargs if there is a strong opinion against this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pitfall here is if someone has an additional property called additional_properties, we get "undefined behavior". I seem to recall a mention in the call that we weren't TOO worried about that/could document it/reserved keywords and all that, but it's the one thing that irks me.
This may be a good target for getting some broader user input on, having them hit this pitfall and see if it's dig-out-able or understandable to their eyes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
What if you do
CloudEvent(foo=True, extensions={"foo":False})
for instance? I think we are opening a pandora's box of things we're unsure the day before the code complete. I would suggest we keep extensions only but make this a priority question in user study.I'm not against it and it has appeal, but right now I want to be sure we have the base minimal behavior, and improve from it first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed it to accepting only extensions - thank you both for the inputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also @KieranBrantnerMagee , I'm catching up your comment,
additional_properties
is just for autorest model, I was explaining how to tell autorest model to serialize attributes that were not on the Swagger. It was not a comment about the external API of public CloudEvent for customer.