-
Notifications
You must be signed in to change notification settings - Fork 3k
Send spec #13143
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
Merged
Merged
Send spec #13143
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3cd4cbe
Event grid track 2 (#12768)
t-swpill 69ce1f1
Packaging update of azure-eventgrid
AutorestCI da433c1
Packaging update of azure-eventgrid
AutorestCI 88bd601
tests fix (#13026)
5303288
Packaging update of azure-eventgrid
AutorestCI 04a61c4
Event grid v2 (#13051)
7d35094
Send spec initial
rakshith91 977e140
recordings
rakshith91 5fe6516
tests fix
rakshith91 7b014cc
Update sdk/eventgrid/azure-eventgrid/tests/recordings/test_eg_publish…
6d9d4e4
Apply suggestions from code review
231fd35
Update sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_clien…
783364f
analyze
rakshith91 e191136
Apply suggestions from code review
5a1bd50
async tests
rakshith91 741feea
no async for py2
rakshith91 5bc8c56
comment
rakshith91 de9a50e
Apply suggestions from code review
081cf65
Apply suggestions from code review
3f88670
Apply suggestions from code review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,23 @@ | |
|
||
if TYPE_CHECKING: | ||
# pylint: disable=unused-import,ungrouped-imports | ||
from typing import Any | ||
from typing import Any, Union, Dict, List | ||
SendType = Union[ | ||
CloudEvent, | ||
EventGridEvent, | ||
CustomEvent, | ||
Dict, | ||
List[CloudEvent], | ||
List[EventGridEvent], | ||
List[CustomEvent] | ||
] | ||
|
||
from ._models import CloudEvent, EventGridEvent, CustomEvent | ||
from ._helpers import _get_topic_hostname_only_fqdn, _get_authentication_policy | ||
from ._helpers import _get_topic_hostname_only_fqdn, _get_authentication_policy, _is_cloud_event | ||
from ._generated._event_grid_publisher_client import EventGridPublisherClient as EventGridPublisherClientImpl | ||
from . import _constants as constants | ||
|
||
|
||
class EventGridPublisherClient(object): | ||
"""EventGrid Python Publisher Client. | ||
|
||
|
@@ -36,20 +46,24 @@ def __init__(self, topic_hostname, credential, **kwargs): | |
self._topic_hostname = topic_hostname | ||
auth_policy = _get_authentication_policy(credential) | ||
self._client = EventGridPublisherClientImpl(authentication_policy=auth_policy, **kwargs) | ||
|
||
def send(self, events, **kwargs): | ||
# type: (Union[List[CloudEvent], List[EventGridEvent], List[CustomEvent]], Any) -> None | ||
# type: (SendType, Any) -> None | ||
"""Sends event data to topic hostname specified during client initialization. | ||
|
||
:param events: A list of CloudEvent/EventGridEvent/CustomEvent to be sent. | ||
:type events: Union[List[models.CloudEvent], List[models.EventGridEvent], List[models.CustomEvent]] | ||
:keyword str content_type: The type of content to be used to send the events. | ||
rakshith91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:rtype: None | ||
raise: :class:`ValueError`, when events do not follow specified SendType. | ||
:raise: :class:`ValueError`, when events do not follow specified SendType. | ||
""" | ||
if not isinstance(events, list): | ||
events = [events] | ||
|
||
if all(isinstance(e, CloudEvent) for e in events): | ||
if all(isinstance(e, CloudEvent) for e in events) or all(_is_cloud_event(e) for e in events): | ||
kwargs.setdefault("content_type", "application/cloudevents-batch+json; charset=utf-8") | ||
KieranBrantnerMagee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self._client.publish_cloud_event_events(self._topic_hostname, events, **kwargs) | ||
elif all(isinstance(e, EventGridEvent) for e in events): | ||
elif all(isinstance(e, EventGridEvent) for e in events) or all(isinstance(e, dict) for e in events): | ||
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. intentionally not doing a client side validation for dicts that are not cloud event |
||
kwargs.setdefault("content_type", "application/json; charset=utf-8") | ||
self._client.publish_events(self._topic_hostname, events, **kwargs) | ||
elif all(isinstance(e, CustomEvent) for e in events): | ||
serialized_events = [dict(e) for e in events] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the ""Software""), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
# | ||
# -------------------------------------------------------------------------- | ||
import platform | ||
import sys | ||
|
||
|
||
# Ignore async tests for Python < 3.5 | ||
collect_ignore_glob = [] | ||
if sys.version_info < (3, 5): | ||
collect_ignore_glob.append("*_async.py") |
40 changes: 40 additions & 0 deletions
40
...entgrid/tests/recordings/test_eg_publisher_client.test_send_cloud_event_data_as_list.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
interactions: | ||
- request: | ||
body: '[{"id": "3dc4b913-4bc2-41f8-be9b-bf1f67069806", "source": "http://samplesource.dev", | ||
"data": "cloudevent", "type": "Sample.Cloud.Event", "time": "2020-08-19T03:36:41.947462Z", | ||
"specversion": "1.0"}]' | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '198' | ||
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) | ||
aeg-sas-key: | ||
- dHUaOOg5xRj+D7iH/AC92GyHweLx9ugrDuMDg4e5Xvw= | ||
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: | ||
- Wed, 19 Aug 2020 03:36:43 GMT | ||
server: | ||
- Microsoft-HTTPAPI/2.0 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
40 changes: 40 additions & 0 deletions
40
...-eventgrid/tests/recordings/test_eg_publisher_client.test_send_cloud_event_data_dict.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
interactions: | ||
- request: | ||
body: '[{"id": "51c18497-2a25-45f1-b9ba-fdaf08c00263", "source": "http://samplesource.dev", | ||
"data": {"sample": "cloudevent"}, "type": "Sample.Cloud.Event", "time": "2020-08-19T03:36:42.304479Z", | ||
"specversion": "1.0"}]' | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '210' | ||
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) | ||
aeg-sas-key: | ||
- dHUaOOg5xRj+D7iH/AC92GyHweLx9ugrDuMDg4e5Xvw= | ||
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: | ||
- Wed, 19 Aug 2020 03:36:43 GMT | ||
server: | ||
- Microsoft-HTTPAPI/2.0 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
40 changes: 40 additions & 0 deletions
40
...e-eventgrid/tests/recordings/test_eg_publisher_client.test_send_cloud_event_data_str.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
interactions: | ||
- request: | ||
body: '[{"id": "6a315e93-a59c-4eca-b2f2-6bf3b8f27984", "source": "http://samplesource.dev", | ||
"data": "cloudevent", "type": "Sample.Cloud.Event", "time": "2020-08-19T03:36:42.629467Z", | ||
"specversion": "1.0"}]' | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '198' | ||
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) | ||
aeg-sas-key: | ||
- dHUaOOg5xRj+D7iH/AC92GyHweLx9ugrDuMDg4e5Xvw= | ||
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: | ||
- Wed, 19 Aug 2020 03:36:43 GMT | ||
server: | ||
- Microsoft-HTTPAPI/2.0 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
39 changes: 39 additions & 0 deletions
39
...azure-eventgrid/tests/recordings/test_eg_publisher_client.test_send_cloud_event_dict.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
interactions: | ||
- request: | ||
body: '[{"id": "1234", "source": "http://samplesource.dev", "data": "cloudevent", | ||
"type": "Sample.Cloud.Event", "specversion": "1.0"}]' | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '127' | ||
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) | ||
aeg-sas-key: | ||
- dHUaOOg5xRj+D7iH/AC92GyHweLx9ugrDuMDg4e5Xvw= | ||
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: | ||
- Wed, 19 Aug 2020 03:36:44 GMT | ||
server: | ||
- Microsoft-HTTPAPI/2.0 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
40 changes: 40 additions & 0 deletions
40
...re-eventgrid/tests/recordings/test_eg_publisher_client.test_send_custom_schema_event.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
interactions: | ||
- request: | ||
body: '[{"customSubject": "sample", "customEventType": "sample.event", "customDataVersion": | ||
"2.0", "customId": "1234", "customEventTime": "2020-08-19T03:36:56.936961+00:00", | ||
"customData": "sample data"}]' | ||
headers: | ||
Accept: | ||
- '*/*' | ||
Accept-Encoding: | ||
- gzip, deflate | ||
Connection: | ||
- keep-alive | ||
Content-Length: | ||
- '196' | ||
Content-Type: | ||
- application/json | ||
User-Agent: | ||
- azsdk-python-eventgridpublisherclient/unknown Python/3.7.3 (Windows-10-10.0.18362-SP0) | ||
aeg-sas-key: | ||
- uPQPJHQHsAhBxWOWtRXslz3sXf7TJ5lcqLZ6SC4QzJ4= | ||
method: POST | ||
uri: https://customeventgridtestegtopic.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: | ||
- Wed, 19 Aug 2020 03:36:57 GMT | ||
server: | ||
- Microsoft-HTTPAPI/2.0 | ||
strict-transport-security: | ||
- max-age=31536000; includeSubDomains | ||
status: | ||
code: 200 | ||
message: OK | ||
version: 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.