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

[EG] Eventgrid Release #36030

Merged
merged 7 commits into from
Jun 11, 2024
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
8 changes: 4 additions & 4 deletions sdk/eventgrid/azure-eventgrid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Release History

## 4.20.0 (Unreleased)
## 4.20.0 (2024-06-11)

### Features Added
### Breaking Changes
### Bugs Fixed
### Other Changes

- This is a GA of the `EventGridConsumerClient`, the `EventGridConsumerClient` supports the following operations for Cloud Events in Event Grid Namespace: `receive`, `release`, `acknowledge`, `reject` and `renew_locks`.
- The `EventGridPublisherClient` now supports the Event Grid Namespace tier. Initialize the client with the namespace endpoint, and the `namespace_topic` kwarg to send Cloud Events to an Event Grid Namespace topic.

## 4.20.0b2 (2024-04-25)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def generate_sas(

.. admonition:: Example:

.. literalinclude:: ../samples/sync_samples/sample_generate_sas.py
.. literalinclude:: ../samples/basic/sync_samples/sample_generate_sas.py
:start-after: [START generate_sas]
:end-before: [END generate_sas]
:language: python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ class EventGridPublisherClient(object): # pylint: disable=client-accepts-api-ve

.. admonition:: Example:

.. literalinclude:: ../samples/sync_samples/sample_authentication.py
.. literalinclude:: ../samples/basic/sync_samples/sample_authentication.py
:start-after: [START client_auth_with_key_cred]
:end-before: [END client_auth_with_key_cred]
:language: python
:dedent: 0
:caption: Creating the EventGridPublisherClient with an endpoint and AzureKeyCredential.

.. literalinclude:: ../samples/sync_samples/sample_authentication.py
.. literalinclude:: ../samples/basic/sync_samples/sample_authentication.py
:start-after: [START client_auth_with_sas_cred]
:end-before: [END client_auth_with_sas_cred]
:language: python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ class EventGridPublisherClient: # pylint: disable=client-accepts-api-version-ke

.. admonition:: Example:

.. literalinclude:: ../samples/async_samples/sample_authentication_async.py
.. literalinclude:: ../samples/basic/async_samples/sample_authentication_async.py
:start-after: [START client_auth_with_key_cred_async]
:end-before: [END client_auth_with_key_cred_async]
:language: python
:dedent: 0
:caption: Creating the EventGridPublisherClient with an endpoint and AzureKeyCredential.

.. literalinclude:: ../samples/async_samples/sample_authentication_async.py
.. literalinclude:: ../samples/basic/async_samples/sample_authentication_async.py
:start-after: [START client_auth_with_sas_cred_async]
:end-before: [END client_auth_with_sas_cred_async]
:language: python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,11 @@ def send(

def _http_response_error_handler(self, exception):
if isinstance(exception, HttpResponseError):
if exception.status_code == 400:
raise HttpResponseError("Invalid event data. Please check the data and try again.") from exception
if exception.status_code == 404:
raise ResourceNotFoundError(
"Resource not found. "
"For Event Grid Namespaces, please specify the namespace_topic name on the client. "
"For Event Grid Basic, do not specify the namespace_topic name."
"For Event Grid Basic, do not specify the namespace_topic name."
) from exception
raise exception

Expand Down
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class EventGridPublisherClient(InternalEventGridPublisherClient):
If dictionaries are provided and sending to a namespace topic,
the dictionary must follow the CloudEvent schema.

:param endpoint: The host name of the namespace, e.g.
:param endpoint: The endpoint of the Event Grid tier (basic or namespace), e.g.
namespaceName1.westus-1.eventgrid.azure.net. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ async def send(

def _http_response_error_handler(self, exception):
if isinstance(exception, HttpResponseError):
if exception.status_code == 400:
raise HttpResponseError("Invalid event data. Please check the data and try again.") from exception
if exception.status_code == 404:
raise ResourceNotFoundError(
"Resource not found. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class EventGridConsumerClient(InternalEventGridConsumerClient):
Consumes and manages events from a namespace topic
and event subscription specified during the client initialization.

:param endpoint: The host name of the namespace, e.g.
:param endpoint: The endpoint of the Event Grid tier (basic or namespace), e.g.
namespaceName1.westus-1.eventgrid.azure.net. Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a
Expand Down
3 changes: 2 additions & 1 deletion sdk/eventgrid/azure-eventgrid/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[tool.azure-sdk-build]
pyright = false
verifytypes = false
verifytypes = false
strict_sphinx = true
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ async def publish():
)
# [END publish_cloud_event_dict_async]


if __name__ == "__main__":
asyncio.run(publish())
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ async def publish():
]
)


if __name__ == "__main__":
asyncio.run(publish())
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

credential_key = AzureKeyCredential(topic_key)
publisher_client = EventGridPublisherClient(endpoint, credential_key, namespace_topic=topic_name)
consumer_client = EventGridConsumerClient(endpoint, credential_key, namespace_topic=topic_name, subscription=event_subscription_name)
consumer_client = EventGridConsumerClient(
endpoint, credential_key, namespace_topic=topic_name, subscription=event_subscription_name
)


from azure.identity.aio import DefaultAzureCredential
Expand All @@ -36,4 +38,6 @@
default_az_credential = DefaultAzureCredential()
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
publisher_client = EventGridPublisherClient(endpoint, default_az_credential, namespace_topic=topic_name)
consumer_client = EventGridConsumerClient(endpoint, default_az_credential, namespace_topic=topic_name, subscription=event_subscription_name)
consumer_client = EventGridConsumerClient(
endpoint, default_az_credential, namespace_topic=topic_name, subscription=event_subscription_name
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
from azure.eventgrid.aio import EventGridPublisherClient
from azure.core.credentials import AzureKeyCredential

topic_key = os.environ["EVENTGRIDKEY"]
topic_key = os.environ["EVENTGRID_KEY"]
endpoint = os.environ["EVENTGRID_ENDPOINT"]
topic_name = os.environ["EVENTGRID_TOPIC_NAME"]

credential = AzureKeyCredential(topic_key)
client = EventGridPublisherClient(endpoint, credential, namespace_topic=topic_name)


async def publish():
client.send(
[
Expand All @@ -42,5 +43,6 @@ async def publish():
]
)

if __name__ == '__main__':
asyncio.run(publish())

if __name__ == "__main__":
asyncio.run(publish())
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
credential = AzureKeyCredential(topic_key)
client = EventGridPublisherClient(endpoint, credential, namespace_topic=topic_name)


async def publish():
await client.send(
[
Expand All @@ -38,5 +39,6 @@ async def publish():
]
)

if __name__ == '__main__':

if __name__ == "__main__":
asyncio.run(publish())
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

credential_key = AzureKeyCredential(topic_key)
publisher_client = EventGridPublisherClient(endpoint, credential_key, namespace_topic=topic_name)
consumer_client = EventGridConsumerClient(endpoint, credential_key, namespace_topic=topic_name, subscription=event_subscription_name)
consumer_client = EventGridConsumerClient(
endpoint, credential_key, namespace_topic=topic_name, subscription=event_subscription_name
)


from azure.identity import DefaultAzureCredential
Expand All @@ -36,4 +38,6 @@
default_az_credential = DefaultAzureCredential()
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
publisher_client = EventGridPublisherClient(endpoint, default_az_credential, namespace_topic=topic_name)
consumer_client = EventGridConsumerClient(endpoint, default_az_credential, namespace_topic=topic_name, subscription=event_subscription_name)
consumer_client = EventGridConsumerClient(
endpoint, default_az_credential, namespace_topic=topic_name, subscription=event_subscription_name
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from azure.eventgrid import EventGridPublisherClient
from azure.core.credentials import AzureKeyCredential

topic_key = os.environ["EVENTGRIDKEY"]
topic_key = os.environ["EVENTGRID_KEY"]
endpoint = os.environ["EVENTGRID_ENDPOINT"]
topic_name = os.environ["EVENTGRID_TOPIC_NAME"]

Expand Down
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
url="https://github.com/Azure/azure-sdk-for-python/tree/main/sdk",
keywords="azure, azure sdk",
classifiers=[
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
Expand Down
16 changes: 8 additions & 8 deletions sdk/eventgrid/azure-eventgrid/tests/test_dual_client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def create_eg_consumer_client(self, endpoint, topic=None, subscription=None):
subscription=subscription,
)
return client


@pytest.mark.live_test_only
@EventGridPreparer()
Expand All @@ -52,7 +51,7 @@ async def test_eg_dual_client_send_eventgrid_event(self, **kwargs):
event_endpoint = kwargs["eventgrid_topic_endpoint"]
namespace_client = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
basic_client = self.create_eg_publisher_client(event_endpoint)

event = {
"id": uuid.uuid4(),
"data": {
Expand All @@ -68,7 +67,7 @@ async def test_eg_dual_client_send_eventgrid_event(self, **kwargs):
await basic_client.send(event)

with pytest.raises(TypeError):
await namespace_client.send(event)
await namespace_client.send(event)

@pytest.mark.live_test_only
@EventGridPreparer()
Expand All @@ -79,7 +78,7 @@ async def test_eg_dual_client_send_custom_event(self, **kwargs):
custom_event_endpoint = kwargs["eventgrid_custom_event_topic_endpoint"]
namespace_client = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
basic_client = self.create_eg_publisher_client(custom_event_endpoint)

custom_event = {
"customSubject": "sample",
"customEventType": "sample.event",
Expand All @@ -104,7 +103,7 @@ async def test_eg_dual_client_send_channel_name(self, **kwargs):
channel_name = kwargs["eventgrid_partner_channel_name"]
namespace_client = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
basic_client = self.create_eg_publisher_client(cloud_event_endpoint)

cloud_event = CloudEvent(
source="http://samplesource.dev",
data={"sample": "cloudevent"},
Expand All @@ -124,11 +123,12 @@ async def test_eg_dual_client_consumer(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_subscription = kwargs["eventgrid_event_subscription_name"]
cloud_event_endpoint = kwargs["eventgrid_cloud_event_topic_endpoint"]
namespace_client = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_subscription)

namespace_client = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_subscription
)

await namespace_client.receive()

with pytest.raises(ValueError):
basic_client = self.create_eg_consumer_client(cloud_event_endpoint)
await basic_client.receive()
await basic_client.receive()
16 changes: 12 additions & 4 deletions sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def test_receive_data(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_event_subscription_name = kwargs["eventgrid_event_subscription_name"]
publisher = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
consumer = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name)
consumer = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name
)
cloud_event = CloudEvent(
source="http://samplesource.dev",
data={"sample": "cloudevent"},
Expand All @@ -72,7 +74,9 @@ def test_receive_renew_data(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_event_subscription_name = kwargs["eventgrid_event_subscription_name"]
publisher = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
consumer = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name)
consumer = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name
)

cloud_event = CloudEvent(
source="http://samplesource.dev",
Expand All @@ -97,7 +101,9 @@ def test_receive_release_data(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_event_subscription_name = kwargs["eventgrid_event_subscription_name"]
publisher = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
consumer = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name)
consumer = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name
)

cloud_event = CloudEvent(
source="http://samplesource.dev",
Expand All @@ -121,7 +127,9 @@ def test_receive_reject_data(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_event_subscription_name = kwargs["eventgrid_event_subscription_name"]
publisher = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
consumer = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name)
consumer = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name
)

cloud_event = CloudEvent(
source="http://samplesource.dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ async def test_receive_data(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_event_subscription_name = kwargs["eventgrid_event_subscription_name"]
publisher = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
consumer = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name)
consumer = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name
)
cloud_event = CloudEvent(
source="http://samplesource.dev",
data={"sample": "cloudevent"},
Expand All @@ -74,7 +76,9 @@ async def test_receive_renew_data(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_event_subscription_name = kwargs["eventgrid_event_subscription_name"]
publisher = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
consumer = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name)
consumer = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name
)
cloud_event = CloudEvent(
source="http://samplesource.dev",
data={"sample": "cloudevent"},
Expand All @@ -99,7 +103,9 @@ async def test_receive_release_data(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_event_subscription_name = kwargs["eventgrid_event_subscription_name"]
publisher = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
consumer = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name)
consumer = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name
)
cloud_event = CloudEvent(
source="http://samplesource.dev",
data={"sample": "cloudevent"},
Expand All @@ -123,7 +129,9 @@ async def test_receive_reject_data(self, **kwargs):
eventgrid_topic_name = kwargs["eventgrid_topic_name"]
eventgrid_event_subscription_name = kwargs["eventgrid_event_subscription_name"]
publisher = self.create_eg_publisher_client(eventgrid_endpoint, eventgrid_topic_name)
consumer = self.create_eg_consumer_client(eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name)
consumer = self.create_eg_consumer_client(
eventgrid_endpoint, eventgrid_topic_name, eventgrid_event_subscription_name
)
cloud_event = CloudEvent(
source="http://samplesource.dev",
data={"sample": "cloudevent"},
Expand Down
Loading