-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
move cloud events to azure core #16661
Conversation
89b5010
to
54f5f3b
Compare
|
||
def _decode(content): | ||
try: | ||
return base64.b64decode(content.encode('utf-8')) |
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.
- ascii is enough, per base64 spec.
- I'm not even sure we need to encode, could you describe the scenario where we do?
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.
Yeah, this method is confusing to me. Is the only reason for it to exist to normalize the exception type?
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.
yes - thinking about it, i think we dont need this method at all - removing it
self.type = type | ||
self.specversion = kwargs.pop("specversion", "1.0") | ||
self.id = kwargs.pop("id", str(uuid.uuid4())) | ||
self.time = kwargs.pop("time", dt.datetime.utcnow().isoformat()) |
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.
https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow
Warning Because naive datetime objects are treated by many datetime methods as local times, it is preferred to use aware datetimes to represent times in UTC. As such, the recommended way to create an object representing the current time in UTC is by calling datetime.now(timezone.utc).
Problem is, Python 2 doesn't have timezone.utc. @johanste usually I tell people to use msrest.serialization.utc since they use msrest as a dependency anyway, but here it won't work. Though?
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.
updated
source=event.pop("source", None), | ||
type=event.pop("type", None), | ||
specversion=event.pop("specversion", None), | ||
data=event.pop("data", None) or _decode(event.pop("data_base64", None)), |
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 would expect an error if both data and data_base64 are present for clarity
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 agree with it, but if we ever decide to add data_base64
in the future, this error would cause a breaking change - thoughts?
import json | ||
|
||
from azure.core.messaging import CloudEvent | ||
from devtools_testutils import AzureMgmtTestCase |
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.
why?
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.
bad copying ;) - removed it
|
||
|
||
def test_cloud_custom_dict_with_extensions(): | ||
event = CloudEvent.from_dict(cloud_custom_dict_with_extensions) |
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 actually find it confusing to have the body in another file here. Could we get rid of the _mock.py file and insert the dict here?
sdk/core/azure-core/CHANGELOG.md
Outdated
@@ -2,6 +2,9 @@ | |||
|
|||
## 1.11.1 (Unreleased) |
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.
1.12.0
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.
Please separate core changes and event hub changes into different PRs.
:type subject: str | ||
:keyword specversion: Optional. The version of the CloudEvent spec. Defaults to "1.0" | ||
:type specversion: str | ||
:keyword id: Optional. An identifier for the event. The combination of id and source must be |
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.
We don't need explicit "Optional." for keyword arguments. Right? :)
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.
hmm, not sure if it's a good practice - but there can certainly be "required" keyword only params (hopefully not in our libraries, but still possible) - thought no harm in mentioning it's optional :)
:rtype: CloudEvent | ||
""" | ||
return cls( | ||
id=event.pop("id", None), |
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.
Given we already pass **kwargs into cls, why we need id=event.pop("id", None), etc.?
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.
hmm, intentionally popping them since we want to have the remainder of the dict as "extensions"
sdk/core/azure-core/tests/_mocks.py
Outdated
@@ -0,0 +1,42 @@ | |||
# storage cloud event |
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.
Please give the file a more specific name.
And you also need to bump the core dependency version to 1.12.0 for event grid. :) |
8f08e33
to
4505a22
Compare
Please review core related chages here |
/azp run python - autorest - pr |
Azure Pipelines successfully started running 1 pipeline(s). |
Fixes #16585
Adding
CloudEvent
to azure-core as follows: