diff --git a/sdk/eventgrid/azure-eventgrid/CHANGELOG.md b/sdk/eventgrid/azure-eventgrid/CHANGELOG.md index b61f5907630d..3067c83116b7 100644 --- a/sdk/eventgrid/azure-eventgrid/CHANGELOG.md +++ b/sdk/eventgrid/azure-eventgrid/CHANGELOG.md @@ -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`. diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py index a03126f1e7c7..b955ad7e3b03 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py @@ -27,7 +27,7 @@ def generate_shared_access_signature(endpoint, shared_access_key, expiration_dat Similar to .-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 """ diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py index 0a08ec4f23c2..b9e23ec5a418 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py @@ -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 - :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) @@ -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, + 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: A resource path relative to the topic path. + :vartype subject: str + :ivar event_type: The type of the event that occurred. + :vartype event_type: str + :ivar data: Event data specific to the event type. + :vartype data: object + :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 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: An identifier for the event. In not provided, a random UUID will be generated and used. + :vartype id: Optional[str] + :ivar event_time: 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] """ _validation = { diff --git a/sdk/eventgrid/azure-eventgrid/tests/recordings/test_eg_publisher_client.test_send_cloud_event_data_none.yaml b/sdk/eventgrid/azure-eventgrid/tests/recordings/test_eg_publisher_client.test_send_cloud_event_data_none.yaml new file mode 100644 index 000000000000..7566d90bb1d5 --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/tests/recordings/test_eg_publisher_client.test_send_cloud_event_data_none.yaml @@ -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 diff --git a/sdk/eventgrid/azure-eventgrid/tests/recordings/test_eg_publisher_client_async.test_send_cloud_event_data_none.yaml b/sdk/eventgrid/azure-eventgrid/tests/recordings/test_eg_publisher_client_async.test_send_cloud_event_data_none.yaml new file mode 100644 index 000000000000..12dcfeb121e7 --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/tests/recordings/test_eg_publisher_client_async.test_send_cloud_event_data_none.yaml @@ -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 diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py index 180d740abb83..d55c9c71a6f3 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py @@ -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): diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py index 128058d35f61..fd801f452b16 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py @@ -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')