diff --git a/sdk/eventgrid/azure-eventgrid/README.md b/sdk/eventgrid/azure-eventgrid/README.md index f6d8bba39a6e..fd5ae787f722 100644 --- a/sdk/eventgrid/azure-eventgrid/README.md +++ b/sdk/eventgrid/azure-eventgrid/README.md @@ -25,7 +25,7 @@ This is a GA release of Azure Event Grid's `EventGridPublisherClient` and `Event ### Event Grid Resources Azure Event Grid Namespaces supports both pull and push delivery. Azure Event Grid Basic supports only push delivery. -More information on the two resource types can be found [here](https://learn.microsoft.com/azure/event-grid/choose-right-tier). +More information on the two resource tiers can be found [here](https://learn.microsoft.com/azure/event-grid/choose-right-tier). **Note:** Azure Event Grid Namespaces only supports the Cloud Event v1.0 Schema. @@ -401,7 +401,14 @@ The following section provides several code snippets illustrating common pattern These code samples show common champion scenario operations with the Azure Event Grid client library. -#### Basic Event Grid Scenarios +#### Additional Namespace Event Grid Scenarios + +* Authenticate the client: [sample_namespace_authentication_async.py][python-eg-namespace-authenticate-async] +* Publish to the namespace topic: [sample_publish_cloud_event_async.py][python-eg-namespace-publish-cloud-async] +* Consume and Process from an event subscription: [sample_consume_process_events.py][python-eg-namespace-consume-async] + + +#### Additional Basic Event Grid Scenarios * Generate Shared Access Signature: [sample_generate_sas.py][python-eg-generate-sas] @@ -455,29 +462,40 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [azure_core_ref_docs]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/core/azure-core#configurations [azure_subscription]: https://azure.microsoft.com/free/ -[python-eg-auth]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_authentication.py -[python-eg-generate-sas]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_generate_sas.py -[python-eg-sample-send-using-sas]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_to_a_topic_using_sas_credential.py -[python-eg-sample-eg-event]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_events_to_a_topic.py -[python-eg-sample-eg-event-to-domain]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_events_to_a_domain.py -[python-eg-sample-send-cloudevent]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py -[python-eg-publish-custom-schema]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_custom_schema_to_a_topic.py -[python-eg-sample-send-eg-as-dict]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_event_using_dict.py -[python-eg-sample-send-cloudevent-as-dict]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_cloud_event_using_dict.py - -[python-eg-auth-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_authentication_async.py -[python-eg-sample-send-using-sas-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_to_a_topic_using_sas_credential_async.py -[python-eg-sample-eg-event-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_events_to_a_topic_async.py -[python-eg-sample-eg-event-to-domain-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_events_to_a_domain_async.py -[python-eg-sample-send-cloudevent-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py -[python-eg-publish-custom-schema-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_custom_schema_to_a_topic_async.py -[python-eg-sample-send-eg-as-dict-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_event_using_dict_async.py -[python-eg-sample-send-cloudevent-as-dict-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cloud_event_using_dict_async.py - -[python-eg-publish-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/publish_samples -[python-eg-consume-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/consume_samples -[python-eg-sample-consume-custom-payload]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_custom_payload.py - +[python-eg-auth]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_authentication.py +[python-eg-generate-sas]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_generate_sas.py +[python-eg-sample-send-using-sas]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_events_to_a_topic_using_sas_credential.py +[python-eg-sample-eg-event]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_events_to_a_topic.py +[python-eg-sample-eg-event-to-domain]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_events_to_a_domain.py +[python-eg-sample-send-cloudevent]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py +[python-eg-publish-custom-schema]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_custom_schema_to_a_topic.py +[python-eg-sample-send-eg-as-dict]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_event_using_dict.py +[python-eg-sample-send-cloudevent-as-dict]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_cloud_event_using_dict.py + +[python-eg-auth-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_authentication_async.py +[python-eg-sample-send-using-sas-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_events_to_a_topic_using_sas_credential_async.py +[python-eg-sample-eg-event-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_events_to_a_topic_async.py +[python-eg-sample-eg-event-to-domain-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_events_to_a_domain_async.py +[python-eg-sample-send-cloudevent-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py +[python-eg-publish-custom-schema-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_custom_schema_to_a_topic_async.py +[python-eg-sample-send-eg-as-dict-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_event_using_dict_async.py +[python-eg-sample-send-cloudevent-as-dict-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_cloud_event_using_dict_async.py + +[python-eg-publish-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples +[python-eg-consume-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples +[python-eg-sample-consume-custom-payload]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_consume_custom_payload.py + + +[python-eg-namespace-authenticate]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_namespace_authentication.py +[python-eg-namespace-publish-cncf]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cncf_events.py +[python-eg-namespace-publish-cloud]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cloud_event.py +[python-eg-namespace-consume]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/samples/sync_samples/sample_consume_process_events.py + + +[python-eg-namespace-authenticate-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_namespace_authentication_async.py +[python-eg-namespace-publish-cncf-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cncf_events_async.py +[python-eg-namespace-publish-cloud-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cloud_event_async.py +[python-eg-namespace-consume-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_consume_process_events_async.py [cla]: https://cla.microsoft.com [code_of_conduct]: https://opensource.microsoft.com/codeofconduct/ diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_operations/_patch.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_operations/_patch.py index 0606157136ab..f85459747e8b 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_operations/_patch.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_operations/_patch.py @@ -81,8 +81,8 @@ def send( ) -> None: # pylint: disable=docstring-should-be-keyword, docstring-missing-param """Send events to the Event Grid Service. - :param events: The event(s) to send. If sending to an Event Grid Namespace, the dict or list of dicts - should be in the format of a CloudEvent. + :param events: The event(s) to send. If sending to an Event Grid Namespace, the dict, list of dicts, + or event(s) should be in the format of a CloudEvent. :type events: CloudEvent or List[CloudEvent] or Dict[str, Any] or List[Dict[str, Any]] or CNCFCloudEvent or List[CNCFCloudEvent] or EventGridEvent or List[EventGridEvent] :keyword channel_name: The name of the channel to send the event to. Event Grid Basic Resource only. @@ -154,15 +154,15 @@ def receive( """Receive Batch of Cloud Events from the Event Subscription. :keyword max_events: Max Events count to be received. Minimum value is 1, while maximum value - is 100 events. If not specified, the default value is 1. Default value is None. + is 100 events. The default is None, meaning it will receive one event if available. :paramtype max_events: int :keyword max_wait_time: Max wait time value for receive operation in Seconds. It is the time in seconds that the server approximately waits for the availability of an event and responds to the request. If an event is available, the broker responds immediately to the client. Minimum - value is 10 seconds, while maximum value is 120 seconds. If not specified, the default value is - 60 seconds. Default value is None. + value is 10 seconds, while maximum value is 120 seconds. The default value is None, meaning it + will wait for 60 seconds. :paramtype max_wait_time: int - :return: Receive Details. + :return: ReceiveDetails list of received events and their broker properties. :rtype: list[~azure.eventgrid.models.ReceiveDetails] :raises ~azure.core.exceptions.HttpResponseError: """ diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_patch.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_patch.py index b63baf75804a..945d3e4d29b4 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_patch.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_patch.py @@ -30,7 +30,7 @@ class EventGridPublisherClient(InternalEventGridPublisherClient): """EventGridPublisherClient. Sends events to a basic topic, basic domain, or a namespace topic - specified during the client initialization. + specified during the client initialization. A single instance or a list of dictionaries, CloudEvents or EventGridEvents are accepted. If a list is provided, the list must contain only one type of event. @@ -44,10 +44,11 @@ class EventGridPublisherClient(InternalEventGridPublisherClient): AzureKeyCredential type or a TokenCredential type. Required. :type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.TokenCredential - :keyword namespace_topic: The name of the topic to publish events to. Required for EventGrid Namespaces. - Default value is None, which is used for EventGrid Basic. + :keyword namespace_topic: The name of the topic to publish events to. Required for Event Grid Namespaces. + Default value is None, which is used for Event Grid Basic. :paramtype namespace_topic: str or None - :keyword api_version: The API version to use for this operation. Default value is "2024-06-01". + :keyword api_version: The API version to use for this operation. Default value for Event Grid Namespace + is "2024-06-01", default value for Event Grid Basic is "2018-01-01". Note that overriding this default value may result in unsupported behavior. :paramtype api_version: str """ @@ -96,7 +97,7 @@ class EventGridConsumerClient(InternalEventGridConsumerClient): """EventGridConsumerClient. Consumes and manages events from a namespace topic - and event subscription specified during the client initialization. + and event subscription specified during the client initialization. :param endpoint: The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net. Required. @@ -107,7 +108,7 @@ class EventGridConsumerClient(InternalEventGridConsumerClient): ~azure.core.credentials.TokenCredential :keyword namespace_topic: The name of the topic to consume events from. Required. :paramtype namespace_topic: str - :subscription: The name of the subscription to consume events from. Required. + :keyword subscription: The name of the subscription to consume events from. Required. :paramtype subscription: str :keyword api_version: The API version to use for this operation. Default value is "2024-06-01". Note that overriding this default value may result in unsupported behavior. diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_operations/_patch.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_operations/_patch.py index 4cd5f859561d..e39c0a97ce27 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_operations/_patch.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_operations/_patch.py @@ -64,8 +64,8 @@ async def send( ) -> None: # pylint: disable=docstring-should-be-keyword, docstring-missing-param """Send events to the Event Grid Service. - :param events: The event(s) to send. If sending to an Event Grid Namespace, the dict or list of dicts - should be in the format of a CloudEvent. + :param events: The event(s) to send. If sending to an Event Grid Namespace, the dict, list of dicts, + or event(s) should be in the format of a CloudEvent. :type events: CloudEvent or List[CloudEvent] or Dict[str, Any] or List[Dict[str, Any]] or CNCFCloudEvent or List[CNCFCloudEvent] or EventGridEvent or List[EventGridEvent] :keyword channel_name: The name of the channel to send the event to. Event Grid Basic Resource only. @@ -138,15 +138,15 @@ async def receive( """Receive Batch of Cloud Events from the Event Subscription. :keyword max_events: Max Events count to be received. Minimum value is 1, while maximum value - is 100 events. If not specified, the default value is 1. Default value is None. + is 100 events. The default is None, meaning it will receive one event if available. :paramtype max_events: int :keyword max_wait_time: Max wait time value for receive operation in Seconds. It is the time in seconds that the server approximately waits for the availability of an event and responds to the request. If an event is available, the broker responds immediately to the client. Minimum - value is 10 seconds, while maximum value is 120 seconds. If not specified, the default value is - 60 seconds. Default value is None. + value is 10 seconds, while maximum value is 120 seconds. The default value is None, meaning it + will wait for 60 seconds. :paramtype max_wait_time: int - :return: ReceiveDetails + :return: ReceiveDetails list of received events and their broker properties. :rtype: list[~azure.eventgrid.models.ReceiveDetails] :raises ~azure.core.exceptions.HttpResponseError: """ diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_patch.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_patch.py index c82fcc0033d0..64bf0555f705 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_patch.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_patch.py @@ -30,7 +30,7 @@ class EventGridPublisherClient(InternalEventGridPublisherClient): """EventGridPublisherClient. Sends events to a basic topic, basic domain, or a namespace topic - specified during the client initialization. + specified during the client initialization. A single instance or a list of dictionaries, CloudEvents or EventGridEvents are accepted. If a list is provided, the list must contain only one type of event. @@ -44,10 +44,11 @@ class EventGridPublisherClient(InternalEventGridPublisherClient): AzureKeyCredential type or a AsyncTokenCredential type. Required. :type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials_async.AsyncTokenCredential - :keyword namespace_topic: The name of the topic to publish events to. Required for EventGrid Namespaces. - Default value is None, which is used for EventGrid Basic. + :keyword namespace_topic: The name of the topic to publish events to. Required for Event Grid Namespaces. + Default value is None, which is used for Event Grid Basic. :paramtype namespace_topic: str or None - :keyword api_version: The API version to use for this operation. Default value is "2024-06-01". + :keyword api_version: The API version to use for this operation. Default value for Event Grid Namespace + is "2024-06-01", default value for Event Grid Basic is "2018-01-01". Note that overriding this default value may result in unsupported behavior. :paramtype api_version: str """ @@ -94,7 +95,7 @@ class EventGridConsumerClient(InternalEventGridConsumerClient): """EventGridConsumerClient. Consumes and manages events from a namespace topic - and event subscription specified during the client initialization. + and event subscription specified during the client initialization. :param endpoint: The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net. Required. @@ -105,7 +106,7 @@ class EventGridConsumerClient(InternalEventGridConsumerClient): ~azure.core.credentials_async.AsyncTokenCredential :keyword namespace_topic: The name of the topic to consume events from. Required. :paramtype namespace_topic: str - :subscription: The name of the subscription to consume events from. Required. + :keyword subscription: The name of the subscription to consume events from. Required. :paramtype subscription: str :keyword api_version: The API version to use for this operation. Default value is "2024-06-01". Note that overriding this default value may result in unsupported behavior. diff --git a/sdk/eventgrid/azure-eventgrid/samples/README.md b/sdk/eventgrid/azure-eventgrid/samples/README.md index 226c849d8d08..027a581529bd 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/README.md +++ b/sdk/eventgrid/azure-eventgrid/samples/README.md @@ -13,11 +13,9 @@ urlFragment: eventgrid-samples ## Sync samples These code samples show common champion scenario operations with the Azure Event Grid client library. -* Generate Shared Access Signature: [sample_generate_sas.py][python-eg-generate-sas] +* Authenticate the client: [sample_authentication.py][python-eg-auth] or [sample_namespace_authentication.py][python-eg-namespace-authenticate] -* Authenticate the client: [sample_authentication.py][python-eg-auth] - -* Publish events to a topic using SAS: [sample_publish_events_to_a_topic_using_sas_credential_async.py][python-eg-sample-send-using-sas] +* Publish Cloud Event to a namespace topic: [sample_publish_cloud_event.py][python-eg-namespace-publish-cloud] * Publish Event Grid Events to a topic: [sample_publish_eg_events_to_a_topic.py][python-eg-sample-eg-event] * Publish EventGrid Events to a domain topic: [sample_publish_eg_events_to_a_domain_topic.py][python-eg-sample-eg-event-to-domain] * Publish a Cloud Event: [sample_publish_events_using_cloud_events_1.0_schema.py][python-eg-sample-send-cloudevent] @@ -32,9 +30,10 @@ To publish events, dict representation of the models could also be used as follo ## Async samples These code samples show common champion scenario operations with the Azure Event Grid client library using the async client. -* Authenticate the client: [sample_authentication_async.py][python-eg-auth-async] -* Publish events to a topic using SAS: [sample_publish_events_to_a_topic_using_sas_credential_async.py][python-eg-sample-send-using-sas-async] +* Authenticate the client: [sample_authentication_async.py][python-eg-auth-async] or [sample_namespace_authentication_async.py][python-eg-namespace-authenticate-async] + +* Publish Cloud Event to a namespace topic: [sample_publish_cloud_event_async.py][python-eg-namespace-publish-cloud-async] * Publish EventGrid Events to a topic: [sample_publish_eg_events_to_a_topic_async.py][python-eg-sample-eg-event-async] * Publish EventGrid Events to a domain topic: [sample_publish_eg_events_to_a_domain_topic_async.py][python-eg-sample-eg-event-to-domain-async] * Publish a Cloud Event: [sample_publish_events_using_cloud_events_1.0_schema_async.py][python-eg-sample-send-cloudevent-async] @@ -49,28 +48,40 @@ To publish events, dict representation of the models could also be used as follo * More samples related to the send scenario can be seen [here][python-eg-publish-samples]. * To see more samples related to consuming a payload from different messaging services as a typed object, please visit [Consume Samples][python-eg-consume-samples] -[python-eg-auth]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_authentication.py -[python-eg-generate-sas]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_generate_sas.py -[python-eg-sample-send-using-sas]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_to_a_topic_using_sas_credential.py -[python-eg-sample-eg-event]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_events_to_a_topic.py -[python-eg-sample-eg-event-to-domain]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_events_to_a_domain.py -[python-eg-sample-send-cloudevent]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py -[python-eg-publish-custom-schema]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_custom_schema_to_a_topic.py -[python-eg-sample-send-eg-as-dict]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_event_using_dict.py -[python-eg-sample-send-cloudevent-as-dict]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_cloud_event_using_dict.py - -[python-eg-auth-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_authentication_async.py -[python-eg-sample-send-using-sas-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_to_a_topic_using_sas_credential_async.py -[python-eg-sample-eg-event-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_events_to_a_topic_async.py -[python-eg-sample-eg-event-to-domain-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_events_to_a_domain_async.py -[python-eg-sample-send-cloudevent-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py -[python-eg-publish-custom-schema-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_custom_schema_to_a_topic_async.py -[python-eg-sample-send-eg-as-dict-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_event_using_dict_async.py -[python-eg-sample-send-cloudevent-as-dict-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cloud_event_using_dict_async.py - -[python-eg-publish-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/publish_samples -[python-eg-consume-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/consume_samples - -[python-eg-sample-consume-custom-payload]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_custom_payload.py +[python-eg-auth]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_authentication.py +[python-eg-generate-sas]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_generate_sas.py +[python-eg-sample-send-using-sas]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_events_to_a_topic_using_sas_credential.py +[python-eg-sample-eg-event]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_events_to_a_topic.py +[python-eg-sample-eg-event-to-domain]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_events_to_a_domain.py +[python-eg-sample-send-cloudevent]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py +[python-eg-publish-custom-schema]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_custom_schema_to_a_topic.py +[python-eg-sample-send-eg-as-dict]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_event_using_dict.py +[python-eg-sample-send-cloudevent-as-dict]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_cloud_event_using_dict.py + +[python-eg-auth-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_authentication_async.py +[python-eg-sample-send-using-sas-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_events_to_a_topic_using_sas_credential_async.py +[python-eg-sample-eg-event-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_events_to_a_topic_async.py +[python-eg-sample-eg-event-to-domain-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_events_to_a_domain_async.py +[python-eg-sample-send-cloudevent-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py +[python-eg-publish-custom-schema-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_custom_schema_to_a_topic_async.py +[python-eg-sample-send-eg-as-dict-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_event_using_dict_async.py +[python-eg-sample-send-cloudevent-as-dict-async]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_cloud_event_using_dict_async.py + +[python-eg-publish-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples +[python-eg-consume-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples + +[python-eg-sample-consume-custom-payload]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_consume_custom_payload.py [publisher-service-doc]: https://docs.microsoft.com/azure/event-grid/concepts + + +[python-eg-namespace-authenticate]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_namespace_authentication.py +[python-eg-namespace-publish-cncf]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cncf_events.py +[python-eg-namespace-publish-cloud]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cloud_event.py +[python-eg-namespace-consume]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_consume_process_events.py + + +[python-eg-namespace-authenticate-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_namespace_authentication_async.py +[python-eg-namespace-publish-cncf-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cncf_events_async.py +[python-eg-namespace-publish-cloud-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cloud_event_async.py +[python-eg-namespace-consume-async]:https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_consume_process_events_async.py \ No newline at end of file diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_authentication_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_authentication_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_authentication_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_authentication_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cloud_event_using_dict_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_cloud_event_using_dict_async.py similarity index 69% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cloud_event_using_dict_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_cloud_event_using_dict_async.py index 1c341e44d183..6541a4ca0323 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cloud_event_using_dict_async.py +++ b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_cloud_event_using_dict_async.py @@ -23,7 +23,6 @@ async def publish(): - # To Event Grid Basic topic_key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"] endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"] @@ -46,29 +45,5 @@ async def publish(): ) # [END publish_cloud_event_dict_async] - # To Event Grid Namespaces - topic_endpoint = os.environ["EVENTGRID_ENDPOINT"] - topic_key = os.environ["EVENTGRID_KEY"] - topic_name = os.environ["EVENTGRID_TOPIC_NAME"] - sub = os.environ["EVENTGRID_EVENT_SUBSCRIPTION_NAME"] - - credential = AzureKeyCredential(topic_key) - client = EventGridPublisherClient(topic_endpoint, credential, namespace_topic=topic_name) - - async with client: - await client.send( - [ - { - "type": "Contoso.Items.ItemReceived", - "source": "/contoso/items", - "data": {"itemSku": "Contoso Item SKU #1"}, - "subject": "Door1", - "specversion": "1.0", - "id": "randomclouduuid11", - } - ] - ) - - if __name__ == "__main__": asyncio.run(publish()) diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cncf_cloud_events_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_cncf_cloud_events_async.py similarity index 67% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cncf_cloud_events_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_cncf_cloud_events_async.py index f777f4ffd67b..446206227607 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_cncf_cloud_events_async.py +++ b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_cncf_cloud_events_async.py @@ -23,7 +23,6 @@ async def publish(): - # To Event Grid Basic topic_key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"] endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"] @@ -38,29 +37,5 @@ async def publish(): ] ) - # To Event Grid Namespaces - - topic_endpoint = os.environ["EVENTGRID_ENDPOINT"] - topic_key = os.environ["EVENTGRID_KEY"] - topic_name = os.environ["EVENTGRID_TOPIC_NAME"] - - credential = AzureKeyCredential(topic_key) - client = EventGridPublisherClient(topic_endpoint, credential, namespace_topic=topic_name) - - async with client: - await client.send( - [ - CloudEvent( - attributes={ - "type": "cloudevent", - "source": "/cncf/cloud/event/1.0", - "subject": "testing-cncf-event", - }, - data=b"This is a cncf cloud event.", - ) - ] - ) - - if __name__ == "__main__": asyncio.run(publish()) diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_custom_schema_to_a_topic_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_custom_schema_to_a_topic_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_custom_schema_to_a_topic_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_custom_schema_to_a_topic_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_event_using_dict_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_event_using_dict_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_event_using_dict_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_event_using_dict_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_events_to_a_domain_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_events_to_a_domain_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_events_to_a_domain_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_events_to_a_domain_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_events_to_a_topic_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_events_to_a_topic_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_eg_events_to_a_topic_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_eg_events_to_a_topic_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_to_a_topic_using_sas_credential_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_events_to_a_topic_using_sas_credential_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_to_a_topic_using_sas_credential_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_events_to_a_topic_using_sas_credential_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_events_using_cloud_events_1.0_schema_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_to_channel_async.py b/sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_to_channel_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_publish_to_channel_async.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/async_samples/sample_publish_to_channel_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_eventhub.py b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_cloud_events_from_eventhub.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_eventhub.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_cloud_events_from_eventhub.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_storage_queue.py b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_cloud_events_from_storage_queue.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_events_from_storage_queue.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_cloud_events_from_storage_queue.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eventgrid_events_from_service_bus_queue.py b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_eventgrid_events_from_service_bus_queue.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eventgrid_events_from_service_bus_queue.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/consume_eventgrid_events_from_service_bus_queue.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/.funcignore b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/.funcignore similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/.funcignore rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/.funcignore diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/.gitignore b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/.gitignore similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/.gitignore rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/.gitignore diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/__init__.py b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/EventGridTrigger1/__init__.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/__init__.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/EventGridTrigger1/__init__.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/function.json b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/EventGridTrigger1/function.json similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/function.json rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/EventGridTrigger1/function.json diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/host.json b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/EventGridTrigger1/host.json similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/host.json rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/EventGridTrigger1/host.json diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/sample.dat b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/EventGridTrigger1/sample.dat similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/EventGridTrigger1/sample.dat rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/EventGridTrigger1/sample.dat diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/host.json b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/host.json similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/host.json rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/host.json diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/proxies.json b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/proxies.json similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/proxies.json rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/proxies.json diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/requirements.txt b/sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/requirements.txt similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/consume_samples/functionsapp/requirements.txt rename to sdk/eventgrid/azure-eventgrid/samples/basic/consume_samples/functionsapp/requirements.txt diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_cloud_events_to_custom_topic_sample.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_cloud_events_to_custom_topic_sample.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_cloud_events_to_domain_topic_sample.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_cloud_events_to_domain_topic_sample.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_custom_schema_events_to_topic_sample.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_custom_schema_events_to_topic_sample.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_event_grid_events_to_custom_topic_sample.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_event_grid_events_to_custom_topic_sample.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py b/sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_with_shared_access_signature_sample.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/publish_samples/publish_with_shared_access_signature_sample.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_authentication.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_authentication.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_authentication.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_authentication.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_custom_payload.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_consume_custom_payload.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_custom_payload.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_consume_custom_payload.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_generate_sas.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_generate_sas.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_generate_sas.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_generate_sas.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_cloud_event_using_dict.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_cloud_event_using_dict.py similarity index 70% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_cloud_event_using_dict.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_cloud_event_using_dict.py index 50c313c51fc3..d9dad90d8e19 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_cloud_event_using_dict.py +++ b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_cloud_event_using_dict.py @@ -19,8 +19,6 @@ from azure.eventgrid import EventGridPublisherClient, EventGridConsumerClient from azure.core.credentials import AzureKeyCredential - -# To Event Grid Basic topic_key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"] endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"] @@ -41,25 +39,3 @@ ] ) # [END publish_cloud_event_dict] - -# To Event Grid Namespaces -topic_endpoint = os.environ["EVENTGRID_ENDPOINT"] -topic_key = os.environ["EVENTGRID_KEY"] -topic_name = os.environ["EVENTGRID_TOPIC_NAME"] -sub = os.environ["EVENTGRID_EVENT_SUBSCRIPTION_NAME"] - -credential = AzureKeyCredential(topic_key) -client = EventGridPublisherClient(topic_endpoint, credential, namespace_topic=topic_name) - -client.send( - [ - { - "type": "Contoso.Items.ItemReceived", - "source": "/contoso/items", - "data": {"itemSku": "Contoso Item SKU #1"}, - "subject": "Door1", - "specversion": "1.0", - "id": "randomclouduuid11", - } - ] -) diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_cncf_cloud_events.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_cncf_cloud_events.py similarity index 72% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_cncf_cloud_events.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_cncf_cloud_events.py index ffb49eb077c2..b686d9220ed1 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_cncf_cloud_events.py +++ b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_cncf_cloud_events.py @@ -19,7 +19,6 @@ from azure.core.credentials import AzureKeyCredential from cloudevents.http import CloudEvent -# To EventGrid Basic topic_key = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_KEY"] endpoint = os.environ["EVENTGRID_CLOUD_EVENT_TOPIC_ENDPOINT"] @@ -34,20 +33,3 @@ ) ] ) - -# To Event Grid Namespaces -topic_endpoint = os.environ["EVENTGRID_ENDPOINT"] -topic_key = os.environ["EVENTGRID_KEY"] -topic_name = os.environ["EVENTGRID_TOPIC_NAME"] - -credential = AzureKeyCredential(topic_key) -client = EventGridPublisherClient(topic_endpoint, credential, namespace_topic=topic_name) - -client.send( - [ - CloudEvent( - attributes={"type": "cloudevent", "source": "/cncf/cloud/event/1.0", "subject": "testing-cncf-event"}, - data=b"This is a cncf cloud event.", - ) - ] -) diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_custom_schema_to_a_topic.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_custom_schema_to_a_topic.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_custom_schema_to_a_topic.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_custom_schema_to_a_topic.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_event_using_dict.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_event_using_dict.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_event_using_dict.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_event_using_dict.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_events_to_a_domain.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_events_to_a_domain.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_events_to_a_domain.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_events_to_a_domain.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_events_to_a_topic.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_events_to_a_topic.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_eg_events_to_a_topic.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_eg_events_to_a_topic.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_to_a_topic_using_sas_credential.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_events_to_a_topic_using_sas_credential.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_to_a_topic_using_sas_credential.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_events_to_a_topic_using_sas_credential.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_events_using_cloud_events_1.0_schema.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_to_channel.py b/sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_to_channel.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_publish_to_channel.py rename to sdk/eventgrid/azure-eventgrid/samples/basic/sync_samples/sample_publish_to_channel.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_consume_process_events_async.py b/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_consume_process_events_async.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/async_samples/sample_consume_process_events_async.py rename to sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_consume_process_events_async.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_namespace_authentication_async.py b/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_namespace_authentication_async.py new file mode 100644 index 000000000000..cf5aadaaeeae --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_namespace_authentication_async.py @@ -0,0 +1,39 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +""" +FILE: sample_namespace_authentication_async.py +DESCRIPTION: + These samples demonstrate authenticating an EventGridPublisherClient and an EventGridConsumerClient. +USAGE: + python sample_namespace_authentication_async.py + Set the environment variables with your own values before running the sample: + 1) EVENTGRID_KEY - The access key of your eventgrid account. + 2) EVENTGRID_ENDPOINT - The namespace hostname. Typically it exists in the format + "https://..eventgrid.azure.net". + 3) EVENTGRID_TOPIC_NAME - The namespace topic name. + 4) EVENTGRID_EVENT_SUBSCRIPTION_NAME = The event subscription name. +""" +import os +from azure.eventgrid.aio import EventGridPublisherClient, EventGridConsumerClient +from azure.core.credentials import AzureKeyCredential + +topic_key = os.environ["EVENTGRID_KEY"] +endpoint = os.environ["EVENTGRID_ENDPOINT"] +topic_name = os.environ["EVENTGRID_TOPIC_NAME"] +event_subscription_name = os.environ["EVENTGRID_EVENT_SUBSCRIPTION_NAME"] + +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) + + +from azure.identity.aio import DefaultAzureCredential +from azure.eventgrid.aio import EventGridPublisherClient + +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) diff --git a/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cloud_event_async.py b/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cloud_event_async.py new file mode 100644 index 000000000000..8c512a36baee --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cloud_event_async.py @@ -0,0 +1,46 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +""" +FILE: sample_publish_cloud_event_async.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents using dict representations + and sending them as a list. +USAGE: + python sample_publish_cloud_event_async.py + Set the environment variables with your own values before running the sample: + 1) EVENTGRID_KEY - The access key of your eventgrid account. + 2) EVENTGRID_ENDPOINT - The namespace hostname. Typically it exists in the format + "https://..eventgrid.azure.net". + 3) EVENTGRID_TOPIC_NAME - The namespace topic name. +""" +import os +import asyncio +from azure.eventgrid.aio import EventGridPublisherClient +from azure.core.credentials import AzureKeyCredential + +topic_key = os.environ["EVENTGRIDKEY"] +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( + [ + { + "type": "Contoso.Items.ItemReceived", + "source": "/contoso/items", + "data": {"itemSku": "Contoso Item SKU #1"}, + "subject": "Door1", + "specversion": "1.0", + "id": "randomclouduuid11", + } + ] + ) + +if __name__ == '__main__': + asyncio.run(publish()) \ No newline at end of file diff --git a/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cncf_events_async.py b/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cncf_events_async.py new file mode 100644 index 000000000000..862bbf052cdf --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/samples/namespace/async_samples/sample_publish_cncf_events_async.py @@ -0,0 +1,42 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +""" +FILE: sample_publish_cncf_events_async.py +DESCRIPTION: + This sample demonstrates creating sending a cloud event from the CNCF library. +USAGE: + python sample_publish_cncf_events_async.py + Set the environment variables with your own values before running the sample: + 1) EVENTGRID_KEY - The access key of your eventgrid account. + 2) EVENTGRID_ENDPOINT - The namespace hostname. Typically it exists in the format + "https://..eventgrid.azure.net". + 3) EVENTGRID_TOPIC_NAME - The namespace topic name. +""" +import os +import asyncio +from azure.eventgrid.aio import EventGridPublisherClient +from azure.core.credentials import AzureKeyCredential +from cloudevents.http import CloudEvent + +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(): + await client.send( + [ + CloudEvent( + attributes={"type": "cloudevent", "source": "/cncf/cloud/event/1.0", "subject": "testing-cncf-event"}, + data=b"This is a cncf cloud event.", + ) + ] + ) + +if __name__ == '__main__': + asyncio.run(publish()) diff --git a/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_process_events.py b/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_consume_process_events.py similarity index 100% rename from sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_process_events.py rename to sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_consume_process_events.py diff --git a/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_namespace_authentication.py b/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_namespace_authentication.py new file mode 100644 index 000000000000..ef73807b878f --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_namespace_authentication.py @@ -0,0 +1,39 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +""" +FILE: sample_namespace_authentication.py +DESCRIPTION: + These samples demonstrate authenticating an EventGridPublisherClient and an EventGridConsumerClient. +USAGE: + python sample_namespace_authentication.py + Set the environment variables with your own values before running the sample: + 1) EVENTGRID_KEY - The access key of your eventgrid account. + 2) EVENTGRID_ENDPOINT - The namespace hostname. Typically it exists in the format + "https://..eventgrid.azure.net". + 3) EVENTGRID_TOPIC_NAME - The namespace topic name. + 4) EVENTGRID_EVENT_SUBSCRIPTION_NAME = The event subscription name. +""" +import os +from azure.eventgrid import EventGridPublisherClient, EventGridConsumerClient +from azure.core.credentials import AzureKeyCredential + +topic_key = os.environ["EVENTGRID_KEY"] +endpoint = os.environ["EVENTGRID_ENDPOINT"] +topic_name = os.environ["EVENTGRID_TOPIC_NAME"] +event_subscription_name = os.environ["EVENTGRID_EVENT_SUBSCRIPTION_NAME"] + +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) + + +from azure.identity import DefaultAzureCredential +from azure.eventgrid import EventGridPublisherClient + +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) diff --git a/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cloud_event.py b/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cloud_event.py new file mode 100644 index 000000000000..e39e1b94c366 --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cloud_event.py @@ -0,0 +1,41 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +""" +FILE: sample_publish_cloud_event.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents using dict representations + and sending them as a list. +USAGE: + python sample_publish_cloud_event.py + Set the environment variables with your own values before running the sample: + 1) EVENTGRID_KEY - The access key of your eventgrid account. + 2) EVENTGRID_ENDPOINT - The namespace hostname. Typically it exists in the format + "https://..eventgrid.azure.net". + 3) EVENTGRID_TOPIC_NAME - The namespace topic name. +""" +import os +from azure.eventgrid import EventGridPublisherClient +from azure.core.credentials import AzureKeyCredential + +topic_key = os.environ["EVENTGRIDKEY"] +endpoint = os.environ["EVENTGRID_ENDPOINT"] +topic_name = os.environ["EVENTGRID_TOPIC_NAME"] + +credential = AzureKeyCredential(topic_key) +client = EventGridPublisherClient(endpoint, credential, namespace_topic=topic_name) + +client.send( + [ + { + "type": "Contoso.Items.ItemReceived", + "source": "/contoso/items", + "data": {"itemSku": "Contoso Item SKU #1"}, + "subject": "Door1", + "specversion": "1.0", + "id": "randomclouduuid11", + } + ] +) diff --git a/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cncf_events.py b/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cncf_events.py new file mode 100644 index 000000000000..dd8f173c9ae8 --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/samples/namespace/sync_samples/sample_publish_cncf_events.py @@ -0,0 +1,37 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +""" +FILE: sample_publish_cncf_events.py +DESCRIPTION: + This sample demonstrates creating sending a cloud event from the CNCF library. +USAGE: + python sample_publish_cncf_events.py + Set the environment variables with your own values before running the sample: + 1) EVENTGRID_KEY - The access key of your eventgrid account. + 2) EVENTGRID_ENDPOINT - The namespace hostname. Typically it exists in the format + "https://..eventgrid.azure.net". + 3) EVENTGRID_TOPIC_NAME - The namespace topic name. +""" +import os +from azure.eventgrid import EventGridPublisherClient +from azure.core.credentials import AzureKeyCredential +from cloudevents.http import CloudEvent + +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) + +client.send( + [ + CloudEvent( + attributes={"type": "cloudevent", "source": "/cncf/cloud/event/1.0", "subject": "testing-cncf-event"}, + data=b"This is a cncf cloud event.", + ) + ] +) diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_dual_client_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_dual_client_async.py new file mode 100644 index 000000000000..c5afcf85c2bd --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/tests/test_dual_client_async.py @@ -0,0 +1,134 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +import logging +import sys +import os +import json +import asyncio +import pytest +import uuid +from msrest.serialization import UTC +import datetime as dt + +from devtools_testutils import AzureRecordedTestCase +from azure.core.messaging import CloudEvent +from azure.core.exceptions import HttpResponseError +from azure.eventgrid.aio import EventGridConsumerClient, EventGridPublisherClient +from eventgrid_preparer import ( + EventGridPreparer, +) + + +class TestEventGridDualClientAsync(AzureRecordedTestCase): + def create_eg_publisher_client(self, endpoint, topic=None): + credential = self.get_credential(EventGridPublisherClient, is_async=True) + client = self.create_client_from_credential( + EventGridPublisherClient, credential=credential, endpoint=endpoint, namespace_topic=topic + ) + return client + + def create_eg_consumer_client(self, endpoint, topic=None, subscription=None): + credential = self.get_credential(EventGridConsumerClient, is_async=True) + client = self.create_client_from_credential( + EventGridConsumerClient, + credential=credential, + endpoint=endpoint, + namespace_topic=topic, + subscription=subscription, + ) + return client + + + @pytest.mark.live_test_only + @EventGridPreparer() + @pytest.mark.asyncio + async def test_eg_dual_client_send_eventgrid_event(self, **kwargs): + eventgrid_endpoint = kwargs["eventgrid_endpoint"] + eventgrid_topic_name = kwargs["eventgrid_topic_name"] + 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": { + "team": "azure-sdk", + "project": "azure-eventgrid", + }, + "subject": "Door1", + "eventType": "Azure.SDK.TestEvent", + "eventTime": dt.datetime.now(UTC()), + "dataVersion": "2.0", + } + + await basic_client.send(event) + + with pytest.raises(TypeError): + await namespace_client.send(event) + + @pytest.mark.live_test_only + @EventGridPreparer() + @pytest.mark.asyncio + async def test_eg_dual_client_send_custom_event(self, **kwargs): + eventgrid_endpoint = kwargs["eventgrid_endpoint"] + eventgrid_topic_name = kwargs["eventgrid_topic_name"] + 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", + "customDataVersion": "2.0", + "customId": "1234", + "customEventTime": dt.datetime.now(UTC()).isoformat(), + "customData": "sample data", + } + + await basic_client.send(custom_event) + + with pytest.raises(TypeError): + await namespace_client.send(custom_event) + + @pytest.mark.live_test_only + @EventGridPreparer() + @pytest.mark.asyncio + async def test_eg_dual_client_send_channel_name(self, **kwargs): + eventgrid_endpoint = kwargs["eventgrid_endpoint"] + eventgrid_topic_name = kwargs["eventgrid_topic_name"] + cloud_event_endpoint = kwargs["eventgrid_partner_namespace_topic_endpoint"] + 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"}, + type="Sample.Cloud.Event", + ) + + await basic_client.send(cloud_event, channel_name=channel_name) + + with pytest.raises(ValueError): + await namespace_client.send(cloud_event, channel_name=channel_name) + + @pytest.mark.live_test_only + @EventGridPreparer() + @pytest.mark.asyncio + async def test_eg_dual_client_consumer(self, **kwargs): + eventgrid_endpoint = kwargs["eventgrid_endpoint"] + 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) + + + await namespace_client.receive() + + with pytest.raises(ValueError): + basic_client = self.create_eg_consumer_client(cloud_event_endpoint) + await basic_client.receive() \ No newline at end of file diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer_client_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer_client_async.py index b3bd78a78fdd..22bbc3461734 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer_client_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_consumer_client_async.py @@ -16,7 +16,6 @@ from devtools_testutils import AzureRecordedTestCase from azure.core.messaging import CloudEvent -from azure.core.credentials import AzureKeyCredential from azure.eventgrid.aio import EventGridConsumerClient, EventGridPublisherClient from eventgrid_preparer import ( EventGridPreparer, diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_dual_client.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_dual_client.py new file mode 100644 index 000000000000..b6133ae18e6f --- /dev/null +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_dual_client.py @@ -0,0 +1,128 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +import logging +import sys +import os +import json +import pytest +import uuid +from msrest.serialization import UTC +import datetime as dt + +from devtools_testutils import AzureRecordedTestCase +from azure.core.messaging import CloudEvent +from azure.core.exceptions import HttpResponseError +from azure.eventgrid import EventGridConsumerClient, EventGridPublisherClient +from eventgrid_preparer import ( + EventGridPreparer, +) + + +class TestEventGridDualClient(AzureRecordedTestCase): + def create_eg_publisher_client(self, endpoint, topic=None): + credential = self.get_credential(EventGridPublisherClient) + client = self.create_client_from_credential( + EventGridPublisherClient, credential=credential, endpoint=endpoint, namespace_topic=topic + ) + return client + + def create_eg_consumer_client(self, endpoint, topic=None, subscription=None): + credential = self.get_credential(EventGridConsumerClient) + client = self.create_client_from_credential( + EventGridConsumerClient, + credential=credential, + endpoint=endpoint, + namespace_topic=topic, + subscription=subscription, + ) + return client + + + @pytest.mark.live_test_only + @EventGridPreparer() + def test_eg_dual_client_send_eventgrid_event(self, **kwargs): + eventgrid_endpoint = kwargs["eventgrid_endpoint"] + eventgrid_topic_name = kwargs["eventgrid_topic_name"] + 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": { + "team": "azure-sdk", + "project": "azure-eventgrid", + }, + "subject": "Door1", + "eventType": "Azure.SDK.TestEvent", + "eventTime": dt.datetime.now(UTC()), + "dataVersion": "2.0", + } + + basic_client.send(event) + + with pytest.raises(TypeError): + namespace_client.send(event) + + @pytest.mark.live_test_only + @EventGridPreparer() + def test_eg_dual_client_send_custom_event(self, **kwargs): + eventgrid_endpoint = kwargs["eventgrid_endpoint"] + eventgrid_topic_name = kwargs["eventgrid_topic_name"] + 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", + "customDataVersion": "2.0", + "customId": "1234", + "customEventTime": dt.datetime.now(UTC()).isoformat(), + "customData": "sample data", + } + + basic_client.send(custom_event) + + with pytest.raises(TypeError): + namespace_client.send(custom_event) + + @pytest.mark.live_test_only + @EventGridPreparer() + def test_eg_dual_client_send_channel_name(self, **kwargs): + eventgrid_endpoint = kwargs["eventgrid_endpoint"] + eventgrid_topic_name = kwargs["eventgrid_topic_name"] + cloud_event_endpoint = kwargs["eventgrid_partner_namespace_topic_endpoint"] + 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"}, + type="Sample.Cloud.Event", + ) + + basic_client.send(cloud_event, channel_name=channel_name) + + with pytest.raises(ValueError): + namespace_client.send(cloud_event, channel_name=channel_name) + + @pytest.mark.live_test_only + @EventGridPreparer() + def test_eg_dual_client_consumer(self, **kwargs): + eventgrid_endpoint = kwargs["eventgrid_endpoint"] + eventgrid_topic_name = kwargs["eventgrid_topic_name"] + subscription_name = 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, subscription_name) + + namespace_client.receive() + + with pytest.raises(ValueError): + basic_client = self.create_eg_consumer_client(cloud_event_endpoint) + basic_client.receive() \ No newline at end of file