Skip to content
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
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- `EventGridConsumer` is now renamed to `EventGridDeserializer`.
- `decode_cloud_event` is renamed to `deserialize_cloud_events`.
- `decode_eventgrid_event` is renamed to `deserialize_eventgrid_events`.
- The system events now exist in the `azure.eventgrid.systemevents` namespace instead of `azure.eventgrid.models` namespace.
- `azure.eventgrid.models` namespace along with all the models in it are now removed. `azure.eventgrid.SystemEventMappings` can be used to get the event model type mapping.
- `topic_hostname` is renamed to `endpoint` in the `EventGridPublisherClient`.
- `data` is now a required param for `CloudEvent`.
- `azure.eventgrid.generate_shared_access_signature` method is now renamed to `generate_sas`.
Expand Down
4 changes: 3 additions & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

from ._publisher_client import EventGridPublisherClient
from ._consumer import EventGridDeserializer
from ._event_mappings import SystemEventMappings
from ._helpers import generate_sas
from ._models import CloudEvent, CustomEvent, EventGridEvent
from ._version import VERSION

__all__ = ['EventGridPublisherClient', 'EventGridDeserializer',
'CloudEvent', 'CustomEvent', 'EventGridEvent', 'generate_sas'
'CloudEvent', 'CustomEvent', 'EventGridEvent', 'generate_sas',
'SystemEventMappings'
]
__version__ = VERSION
12 changes: 6 additions & 6 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class EventGridDeserializer(object):
def deserialize_cloud_events(self, cloud_event, **kwargs): # pylint: disable=no-self-use
# type: (Union[str, dict, bytes], Any) -> CloudEvent
"""Single event following CloudEvent schema will be parsed and returned as Deserialized Event.
Use `.data` to get the data in the raw format. To check the list of recognizable system topics,
visit https://docs.microsoft.com/azure/event-grid/system-topics.

:param cloud_event: The event to be deserialized.
:type cloud_event: Union[str, dict, bytes]
:rtype: CloudEvent
Expand All @@ -34,11 +37,8 @@ def deserialize_cloud_events(self, cloud_event, **kwargs): # pylint: disable=no-
try:
cloud_event = CloudEvent._from_json(cloud_event, encode) # pylint: disable=protected-access
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need updating I believe once you change the _from_json to _to_json :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #16352

Copy link
Contributor

@yunhaoling yunhaoling Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I just realize that currently the _from_json accepts a json string and returns a json/dict object?

and if I'm understanding correctly, we're gonna have a separate PR which has the methods matching the functionality?
(probably we could be a bit verbose on the method name, like _from_json_str, _to_json_object-ish)

deserialized_event = CloudEvent._from_generated(cloud_event) # pylint: disable=protected-access
CloudEvent._deserialize_data(deserialized_event, deserialized_event.type) # pylint: disable=protected-access
return deserialized_event
except Exception as err:
_LOGGER.error('Error: cannot deserialize event. Event does not have a valid format. \
Event must be a string, dict, or bytes following the CloudEvent schema.')
_LOGGER.error('Your event: %s', cloud_event)
_LOGGER.error(err)
raise ValueError('Error: cannot deserialize event. Event does not have a valid format. \
Expand All @@ -47,6 +47,9 @@ def deserialize_cloud_events(self, cloud_event, **kwargs): # pylint: disable=no-
def deserialize_eventgrid_events(self, eventgrid_event, **kwargs): # pylint: disable=no-self-use
# type: (Union[str, dict, bytes], Any) -> EventGridEvent
"""Single event following EventGridEvent schema will be parsed and returned as Deserialized Event.
Use `.data` to get the data in the raw format. To check the list of recognizable system topics,
visit https://docs.microsoft.com/azure/event-grid/system-topics.

:param eventgrid_event: The event to be deserialized.
:type eventgrid_event: Union[str, dict, bytes]
:rtype: EventGridEvent
Expand All @@ -57,11 +60,8 @@ def deserialize_eventgrid_events(self, eventgrid_event, **kwargs): # pylint: dis
try:
eventgrid_event = EventGridEvent._from_json(eventgrid_event, encode) # pylint: disable=protected-access
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, will need updating once _from_json is changed _to_json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this tracked in the decode changes where i'm including a _to_json as well (along with a _from_json) #16352

deserialized_event = EventGridEvent.deserialize(eventgrid_event)
EventGridEvent._deserialize_data(deserialized_event, deserialized_event.event_type) # pylint: disable=protected-access
return cast(EventGridEvent, deserialized_event)
except Exception as err:
_LOGGER.error('Error: cannot deserialize event. Event does not have a valid format. \
Event must be a string, dict, or bytes following the CloudEvent schema.')
_LOGGER.error('Your event: %s', eventgrid_event)
_LOGGER.error(err)
raise ValueError('Error: cannot deserialize event. Event does not have a valid format. \
Expand Down
Loading