Skip to content
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

Add data as positional for cloud event #16288

Merged
merged 7 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions sdk/eventgrid/azure-eventgrid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- The system events now exist in the `azure.eventgrid.systemevents` namespace instead of `azure.eventgrid.models` namespace.
- The `send` method in the `EventGridPubliserClient` is now replaced by the `send_events`.
- `topic_hostname` is renamed to `endpoint` in the `EventGridPublisherClient`.
- `data` is now a required param for `CloudEvent`.

**Bug Fixes**
- `EventGridEvent` has two additional required positional parameters namely, `data` and `data_version`.
Expand Down
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def generate_shared_access_signature(endpoint, shared_access_key, expiration_dat
Similar to <YOUR-TOPIC-NAME>.<YOUR-REGION-NAME>-1.eventgrid.azure.net
:param str shared_access_key: The shared access key to be used for generating the token
:param datetime.datetime expiration_date_utc: The expiration datetime in UTC for the signature.
:param str api_version: The API Version to include in the signature.
:keyword str api_version: The API Version to include in the signature.
If not provided, the default API version will be used.
:rtype: str
"""
Expand Down
80 changes: 63 additions & 17 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,54 @@ class CloudEvent(EventMixin): #pylint:disable=too-many-instance-attributes
:param source: Required. Identifies the context in which an event happened. The combination of id and source must
be unique for each distinct event. If publishing to a domain topic, source must be the domain name.
:type source: str
:param data: Event data specific to the event type.
:type data: object
:param type: Required. Type of event related to the originating occurrence.
:type type: str
yunhaoling marked this conversation as resolved.
Show resolved Hide resolved
:param time: The time (in UTC) the event was generated, in RFC3339 format.
:param data: Required. Event data specific to the event type.
:type data: object
:keyword time: Optional. The time (in UTC) the event was generated, in RFC3339 format.
:type time: ~datetime.datetime
:param dataschema: Identifies the schema that data adheres to.
:keyword dataschema: Optional. Identifies the schema that data adheres to.
:type dataschema: str
:param datacontenttype: Content type of data value.
:keyword datacontenttype: Optional. Content type of data value.
:type datacontenttype: str
:param subject: This describes the subject of the event in the context of the event producer
:keyword subject: Optional. This describes the subject of the event in the context of the event producer
(identified by source).
:type subject: str
:param id: Optional. An identifier for the event. The combination of id and source must be
: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
unique for each distinct event. If not provided, a random UUID will be generated and used.
:type id: Optional[str]
:ivar source: Identifies the context in which an event happened. The combination of id and source must
be unique for each distinct event. If publishing to a domain topic, source must be the domain name.
:vartype source: str
:ivar data: Event data specific to the event type.
:vartype data: object
:ivar type: Type of event related to the originating occurrence.
:vartype type: str
:ivar time: The time (in UTC) the event was generated, in RFC3339 format.
:vartype time: ~datetime.datetime
:ivar dataschema: Identifies the schema that data adheres to.
:vartype dataschema: str
:ivar datacontenttype: Content type of data value.
:vartype datacontenttype: str
:ivar subject: This describes the subject of the event in the context of the event producer
(identified by source).
:vartype subject: str
:ivar specversion: Optional. The version of the CloudEvent spec. Defaults to "1.0"
:vartype specversion: str
:ivar id: An identifier for the event. The combination of id and source must be
unique for each distinct event. If not provided, a random UUID will be generated and used.
:vartype id: Optional[str]
"""
def __init__(self, source, type, **kwargs): # pylint: disable=redefined-builtin
# type: (str, str, Any) -> None
def __init__(self, source, type, data, **kwargs): # pylint: disable=redefined-builtin
# type: (str, str, object, Any) -> None
self.source = source
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.now(UTC()).isoformat())
self.data = kwargs.pop("data", None)
self.data = data
self.datacontenttype = kwargs.pop("datacontenttype", None)
self.dataschema = kwargs.pop("dataschema", None)
self.subject = kwargs.pop("subject", None)
Expand Down Expand Up @@ -145,18 +168,41 @@ class EventGridEvent(InternalEventGridEvent, EventMixin):
:param data_version: Required. The schema version of the data object.
If not provided, will be stamped with an empty value.
:type data_version: str
:param topic: The resource path of the event source. If not provided, Event Grid will stamp onto the event.
:keyword topic: Optional. The resource path of the event source. If not provided, Event Grid will
stamp onto the event.
:type topic: str
:ivar metadata_version: The schema version of the event metadata. If provided, must match Event Grid Schema exactly.
If not provided, EventGrid will stamp onto event.
:vartype metadata_version: str
:param data_version: The schema version of the data object. If not provided, will be stamped with an empty value.
:keyword metadata_version: Optional. The schema version of the event metadata. If provided,
rakshith91 marked this conversation as resolved.
Show resolved Hide resolved
must match Event Grid Schema exactly. If not provided, EventGrid will stamp onto event.
:type metadata_version: str
:keyword data_version: Optional. The schema version of the data object. If not provided,
will be stamped with an empty value.
:type data_version: str
:param id: Optional. An identifier for the event. In not provided, a random UUID will be generated and used.
:keyword id: Optional. An identifier for the event. In not provided, a random UUID will be generated and used.
:type id: Optional[str]
:param event_time: Optional.The time (in UTC) of the event. If not provided,
:keyword event_time: Optional.The time (in UTC) of the event. If not provided,
it will be the time (in UTC) the event was generated.
:type event_time: Optional[~datetime.datetime]
:ivar subject: Required. A resource path relative to the topic path.
:vartype subject: str
:ivar event_type: Required. The type of the event that occurred.
:vartype event_type: str
:ivar data: Required. Event data specific to the event type.
:vartype data: object
:ivar data_version: Required. The schema version of the data object.
If not provided, will be stamped with an empty value.
:vartype data_version: str
:ivar topic: The resource path of the event source. If not provided, Event Grid will stamp onto the event.
:vartype topic: str
:ivar metadata_version: The schema version of the event metadata. If provided, must match Event Grid Schema exactly.
If not provided, EventGrid will stamp onto event.
:vartype metadata_version: str
:ivar data_version: The schema version of the data object. If not provided, will be stamped with an empty value.
:vartype data_version: str
:ivar id: Optional. An identifier for the event. In not provided, a random UUID will be generated and used.
:vartype id: Optional[str]
:ivar event_time: Optional.The time (in UTC) of the event. If not provided,
it will be the time (in UTC) the event was generated.
:vartype event_time: Optional[~datetime.datetime]
rakshith91 marked this conversation as resolved.
Show resolved Hide resolved
"""

_validation = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interactions:
- request:
body: '[{"id": "880b26eb-96c6-4a14-b373-c3be6634cd21", "source": "http://samplesource.dev",
"type": "Sample.Cloud.Event", "time": "2021-01-21T20:04:19.0468Z", "specversion":
"1.0"}]'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Content-Length:
- '174'
Content-Type:
- application/cloudevents-batch+json; charset=utf-8
User-Agent:
- azsdk-python-eventgrid/2.0.0b5 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, 21 Jan 2021 20:04:21 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,28 @@
interactions:
- request:
body: '[{"id": "e4d278ac-c129-433d-a9f7-10af74a41b44", "source": "http://samplesource.dev",
"type": "Sample.Cloud.Event", "time": "2021-01-21T20:04:44.736922Z", "specversion":
"1.0"}]'
headers:
Content-Length:
- '176'
Content-Type:
- application/cloudevents-batch+json; charset=utf-8
User-Agent:
- azsdk-python-eventgridpublisherclient/2.0.0b5 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, 21 Jan 2021 20:04:46 GMT
server: Microsoft-HTTPAPI/2.0
strict-transport-security: max-age=31536000; includeSubDomains
status:
code: 200
message: OK
url: https://cloudeventgridtestmehspu.westus-1.eventgrid.azure.net/api/events?api-version=2018-01-01
version: 1
13 changes: 13 additions & 0 deletions sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ def test_send_cloud_event_data_dict(self, resource_group, eventgrid_topic, event
)
client.send_events(cloud_event)


@CachedResourceGroupPreparer(name_prefix='eventgridtest')
@CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest')
def test_send_cloud_event_data_none(self, resource_group, eventgrid_topic, eventgrid_topic_primary_key, eventgrid_topic_endpoint):
akc_credential = AzureKeyCredential(eventgrid_topic_primary_key)
client = EventGridPublisherClient(eventgrid_topic_endpoint, akc_credential)
cloud_event = CloudEvent(
source = "http://samplesource.dev",
data = None,
type="Sample.Cloud.Event"
)
client.send_events(cloud_event)

@CachedResourceGroupPreparer(name_prefix='eventgridtest')
@CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest')
def test_send_cloud_event_data_str(self, resource_group, eventgrid_topic, eventgrid_topic_primary_key, eventgrid_topic_endpoint):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@ async def test_send_cloud_event_dict(self, resource_group, eventgrid_topic, even
}
await client.send_events(cloud_event1)

@CachedResourceGroupPreparer(name_prefix='eventgridtest')
@CachedEventGridTopicPreparer(name_prefix='cloudeventgridtest')
@pytest.mark.asyncio
async def test_send_cloud_event_data_none(self, resource_group, eventgrid_topic, eventgrid_topic_primary_key, eventgrid_topic_endpoint):
akc_credential = AzureKeyCredential(eventgrid_topic_primary_key)
client = EventGridPublisherClient(eventgrid_topic_endpoint, akc_credential)
cloud_event = CloudEvent(
source = "http://samplesource.dev",
data = None,
type="Sample.Cloud.Event"
)
await client.send_events(cloud_event)

@CachedResourceGroupPreparer(name_prefix='eventgridtest')
@CachedEventGridTopicPreparer(name_prefix='eventgridtest')
Expand Down