From 1daa366745e4f91180004b72bf1415c7bf09b383 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Tue, 1 Sep 2020 09:30:12 -0700 Subject: [PATCH 1/5] docstrings --- .../cs1_publish_custom_events_to_a_topic.py | 16 +++- ...custom_events_to_a_topic_with_signature.py | 16 +++- ...publish_custom_events_to_a_domain_topic.py | 18 ++++- .../cs3_consume_system_events.py | 7 ++ .../cs4_consume_custom_events.py | 7 ++ ...sh_events_using_cloud_events_1.0_schema.py | 15 +++- ...me_events_using_cloud_events_1.0_schema.py | 7 ++ .../consume_cloud_custom_data_sample.py | 8 ++ ...ume_eg_storage_blob_created_data_sample.py | 8 ++ .../consume_cloud_events_from_eventhub.py | 15 ++-- ...ume_cloud_events_from_service_bus_queue.py | 15 ++-- ...consume_cloud_events_from_storage_queue.py | 10 +++ ...ish_cloud_events_to_custom_topic_sample.py | 55 ++++++++------ ...ish_cloud_events_to_domain_topic_sample.py | 62 ++++++++++------ ...sh_custom_schema_events_to_topic_sample.py | 73 +++++++++++-------- ...vent_grid_events_to_custom_topic_sample.py | 59 +++++++++------ ...ish_with_shared_access_signature_sample.py | 57 +++++++++------ 17 files changed, 305 insertions(+), 143 deletions(-) diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py index d98de8ab82ed..91753f083946 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py @@ -1,8 +1,20 @@ +""" +FILE: cs1_publish_custom_events_to_a_topic.py +DESCRIPTION: + These samples demonstrate sending an EventGrid Event. +USAGE: + python cs1_publish_custom_events_to_a_topic.py + Set the environment variables with your own values before running the sample: + 1) EG_ACCESS_KEY - The access key of your eventgrid account. + 2) EG_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". +""" + from azure.eventgrid import EventGridPublisherClient, EventGridEvent, CloudEvent from azure.core.credentials import AzureKeyCredential -topic_hostname = ".-1.eventgrid.azure.net" -topic_key = "" +topic_key = os.environ["EG_ACCESS_KEY"] +topic_hostname = os.environ["EG_TOPIC_HOSTNAME"] credential = AzureKeyCredential(topic_key) client = EventGridPublisherClient(topic_hostname, credential) diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py index b320f603ea65..a635b7ef5d2c 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py @@ -1,8 +1,20 @@ +""" +FILE: cs1b_publish_custom_events_to_a_topic_with_signature.py +DESCRIPTION: + These samples demonstrate sending an EventGrid Event using a shared access signature for authentication. +USAGE: + python cs1b_publish_custom_events_to_a_topic_with_signature.py + Set the environment variables with your own values before running the sample: + 1) EG_ACCESS_KEY - The access key of your eventgrid account. + 2) EG_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". +""" + from azure.eventgrid import EventGridPublisherClient, EventGridEvent, CloudEvent, generate_shared_access_signature, EventGridSharedAccessSignatureCredential from azure.core.credentials import AzureKeyCredential -topic_hostname = ".-1.eventgrid.azure.net" -topic_key = "" +topic_key = os.environ["EG_ACCESS_KEY"] +topic_hostname = os.environ["EG_TOPIC_HOSTNAME"] expiration_date_utc = dt.datetime.now(tzutc()) + timedelta(hours=1) signature = generate_shared_access_signature(topic_hostname, topic_key, expiration_date_utc) diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py index 3221d4ad30d5..a6b0e666dd98 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py @@ -1,8 +1,20 @@ +""" +FILE: cs2_publish_custom_events_to_a_domain_topic.py +DESCRIPTION: + These samples demonstrate creating a list of EventGrid Events and sending them as a list. +USAGE: + python cs2_publish_custom_events_to_a_domain_topic.py + Set the environment variables with your own values before running the sample: + 1) EG_ACCESS_KEY - The access key of your eventgrid account. + 2) EG_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". +""" + from azure.eventgrid import EventGridPublisherClient, EventGridEvent from azure.core.credentials import AzureKeyCredential -domain_hostname = ".-1.eventgrid.azure.net" -domain_key = "" +domain_key = os.environ["EG_ACCESS_KEY"] +domain_hostname = os.environ["EG_TOPIC_HOSTNAME"] credential = AzureKeyCredential(domain_key) client = EventGridPublisherClient(domain_hostname, credential) @@ -26,4 +38,4 @@ subject="Door1", data_version="2.0" ) -]) \ No newline at end of file +]) diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py index ef39037148d4..5f46ea50bcd2 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py @@ -1,3 +1,10 @@ +""" +FILE: cs3_consume_system_events.py +DESCRIPTION: + These samples demonstrate deserializing a message from system event. +USAGE: + python cs3_consume_system_events.py +""" import os from azure.eventgrid import EventGridConsumer diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py index 13d41d0f09ea..ea5799322088 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py @@ -1,3 +1,10 @@ +""" +FILE: cs4_consume_custom_events.py +DESCRIPTION: + These samples demonstrate deserializing a custom event +USAGE: + python cs4_consume_custom_events.py +""" import os from azure.eventgrid import EventGridConsumer diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py index 4474b6ab40fb..84a6e01435d1 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py @@ -1,8 +1,19 @@ +""" +FILE: cs5_publish_events_using_cloud_events_1.0_schema.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending then as a list. +USAGE: + python cs5_publish_events_using_cloud_events_1.0_schema.py + Set the environment variables with your own values before running the sample: + 1) CLOUD_ACCESS_KEY - The access key of your eventgrid account. + 2) CLOUD_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". +""" from azure.eventgrid import EventGridPublisherClient, CloudEvent from azure.core.credentials import AzureKeyCredential -topic_hostname = ".-1.eventgrid.azure.net" -topic_key = "" +topic_key = os.environ["CLOUD_ACCESS_KEY"] +topic_hostname = os.environ["CLOUD_TOPIC_HOSTNAME"] credential = AzureKeyCredential(topic_key) client = EventGridPublisherClient(topic_hostname, credential) diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py index 2001070fb68c..278efccdea7d 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py @@ -1,3 +1,10 @@ +""" +FILE: cs6_consume_events_using_cloud_events_1.0_schema.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending then as a list. +USAGE: + python cs6_consume_events_using_cloud_events_1.0_schema.py +""" import os from azure.eventgrid import EventGridConsumer diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py index ce477ef69963..30398f9b583a 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py @@ -1,3 +1,11 @@ +""" +FILE: consume_cloud_custom_data_sample.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending then as a list. +USAGE: + python consume_cloud_custom_data_sample.py + Set the environment variables with your own values before running the sample: +""" import json from azure.eventgrid import EventGridConsumer, CloudEvent diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py index 21735940739f..152b2a6920de 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py @@ -1,3 +1,11 @@ +""" +FILE: consume_eg_storage_blob_created_data_sample.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending then as a list. +USAGE: + python consume_eg_storage_blob_created_data_sample.py + Set the environment variables with your own values before running the sample: +""" import json from azure.eventgrid import EventGridConsumer, EventGridEvent, StorageBlobCreatedEventData diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py index b672777afc0b..5e7a6ffd9f85 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py @@ -1,10 +1,15 @@ -import sys +""" +FILE: consume_cloud_events_from_eventhub.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending then as a list. +USAGE: + python consume_cloud_events_from_eventhub.py + Set the environment variables with your own values before running the sample: + 1) EVENT_HUB_CONN_STR: The connection string to the Event hub account + 3) EVENTHUB_NAME: The name of the eventhub account +""" import os -PACKAGE_PARENT = '..' -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) -sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) - from azure.eventgrid import EventGridConsumer, CloudEvent, EventGridEvent from azure.eventhub import EventHubConsumerClient diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py index 3f1b61057d83..aa8263d4bc3d 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py @@ -1,10 +1,15 @@ -import sys +""" +FILE: consume_cloud_events_from_eventhub.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending then as a list. +USAGE: + python consume_cloud_events_from_eventhub.py + Set the environment variables with your own values before running the sample: + 1) SB_CONN_STR: The connection string to the Service Bus account + 3) SERVICE_BUS_QUEUE_NAME: The name of the servicebus account +""" import os -PACKAGE_PARENT = '..' -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) -sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) - from azure.core.pipeline.policies import AzureKeyCredentialPolicy from azure.core.credentials import AzureKeyCredential diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py index 754c561bfbe1..b1e57e9e7e1e 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py @@ -1,3 +1,13 @@ +""" +FILE: consume_cloud_events_from_eventhub.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending then as a list. +USAGE: + python consume_cloud_events_from_eventhub.py + Set the environment variables with your own values before running the sample: + 1) STORAGE_QUEUE_CONN_STR: The connection string to the storage account + 3) STORAGE_QUEUE_NAME: The name of the storage queue. +""" import os from azure.storage.queue import QueueServiceClient from azure.eventgrid import EventGridConsumer, CloudEvent diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py index cada0ae9e5e5..787acb01cfed 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py @@ -1,12 +1,19 @@ -import sys +""" +FILE: publish_cloud_events_to_custom_topic_sample.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending them as a list + to a custom topic. +USAGE: + python publish_cloud_events_to_custom_topic_sample.py + Set the environment variables with your own values before running the sample: + 1) CLOUD_ACCESS_KEY - The access key of your eventgrid account. + 2) CLOUD_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". +""" import os from random import randint, sample import time -PACKAGE_PARENT = '..' -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) -sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) - from azure.core.credentials import AzureKeyCredential from azure.eventgrid import EventGridPublisherClient, CloudEvent @@ -19,21 +26,25 @@ team_members = ["Josh", "Kerri", "Kieran", "Laurent", "Lily", "Matt", "Soren", "Srikanta", "Swathi"] # possible values for data field -# publish events -while True: - event_list = [] # list of events to publish - # create events and append to list - for j in range(randint(1, 1)): - sample_members = sample(team_members, k=randint(1, 9)) # select random subset of team members - data_dict = {"team": sample_members} - event = CloudEvent( - type="Azure.Sdk.Sample", - source="https://egsample.dev/sampleevent", - data={"team": sample_members} - ) - event_list.append(event) +def publish_event(): + # publish events + for _ in range(10): + event_list = [] # list of events to publish + # create events and append to list + for j in range(randint(1, 1)): + sample_members = sample(team_members, k=randint(1, 9)) # select random subset of team members + data_dict = {"team": sample_members} + event = CloudEvent( + type="Azure.Sdk.Sample", + source="https://egsample.dev/sampleevent", + data={"team": sample_members} + ) + event_list.append(event) + + # publish list of events + client.send(event_list) + print("Batch of size {} published".format(len(event_list))) + time.sleep(randint(1, 5)) - # publish list of events - client.send(event_list) - print("Batch of size {} published".format(len(event_list))) - time.sleep(randint(1, 5)) +if __name__ == "__main__": + publish_event() diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py index 528d57d85887..082d43827854 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py @@ -1,12 +1,21 @@ +""" +FILE: publish_cloud_events_to_domain_topic_sample.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and sending them as a list + to a domain topic. +USAGE: + python publish_cloud_events_to_domain_topic_sample.py + Set the environment variables with your own values before running the sample: + 1) DOMAIN_ACCESS_KEY - The access key of your eventgrid account. + 2) DOMAIN_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". + 3) DOMAIN_NAME - the name of the topic +""" import sys import os from random import randint, sample import time -PACKAGE_PARENT = '..' -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) -sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) - from azure.core.credentials import AzureKeyCredential from azure.eventgrid import EventGridPublisherClient, CloudEvent @@ -14,27 +23,32 @@ domain_topic_hostname = os.environ["DOMAIN_TOPIC_HOSTNAME"] domain_name = os.environ["DOMAIN_NAME"] + # authenticate client credential = AzureKeyCredential(domain_key) client = EventGridPublisherClient(domain_topic_hostname, credential) -# publish events -while True: - - event_list = [] # list of events to publish - team_members = ["Josh", "Kerri", "Kieran", "Laurent", "Lily", "Matt", "Soren", "Srikanta", "Swathi"] # possible values for data field - - # create events and append to list - for j in range(randint(1, 3)): - sample_members = sample(team_members, k=randint(1, 9)) # select random subset of team members - event = CloudEvent( - type="Azure.Sdk.Demo", - source=domain_name, - data={"team": sample_members} - ) - event_list.append(event) - - # publish list of events - client.send(event_list) - print("Batch of size {} published".format(len(event_list))) - time.sleep(randint(1, 5)) +def publish_event(): + # publish events + for _ in range(10): + + event_list = [] # list of events to publish + team_members = ["Josh", "Kerri", "Kieran", "Laurent", "Lily", "Matt", "Soren", "Srikanta", "Swathi"] # possible values for data field + + # create events and append to list + for j in range(randint(1, 3)): + sample_members = sample(team_members, k=randint(1, 9)) # select random subset of team members + event = CloudEvent( + type="Azure.Sdk.Demo", + source=domain_name, + data={"team": sample_members} + ) + event_list.append(event) + + # publish list of events + client.send(event_list) + print("Batch of size {} published".format(len(event_list))) + time.sleep(randint(1, 5)) + +if __name__ == '__main__': + publish_event() \ No newline at end of file diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py index ecfbf4eb208d..3741ab373435 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py @@ -1,4 +1,14 @@ -import sys +""" +FILE: publish_custom_schema_events_to_topic_sample.py +DESCRIPTION: + These samples demonstrate creating a list of Custom Events and sending them as a list. +USAGE: + python publish_custom_schema_events_to_topic_sample.py + Set the environment variables with your own values before running the sample: + 1) CUSTOM_SCHEMA_ACCESS_KEY - The access key of your eventgrid account. + 2) CUSTOM_SCHEMA_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". +""" import os from random import randint, sample import time @@ -6,39 +16,40 @@ from msrest.serialization import UTC import datetime as dt -PACKAGE_PARENT = '..' -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) -sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) - from azure.core.credentials import AzureKeyCredential from azure.eventgrid import EventGridPublisherClient, CustomEvent key = os.environ["CUSTOM_SCHEMA_ACCESS_KEY"] topic_hostname = os.environ["CUSTOM_SCHEMA_TOPIC_HOSTNAME"] -# authenticate client -credential = AzureKeyCredential(key) -client = EventGridPublisherClient(topic_hostname, credential) - -custom_schema_event = { - "customSubject": "sample", - "customEventType": "sample.event", - "customDataVersion": "2.0", - "customId": uuid.uuid4(), - "customEventTime": dt.datetime.now(UTC()).isoformat(), - "customData": "sample data" -} - -# publish events -while True: - - event_list = [] # list of events to publish - # create events and append to list - for j in range(randint(1, 3)): - event = CustomEvent(custom_schema_event) - event_list.append(event) - - # publish list of events - client.send(event_list) - print("Batch of size {} published".format(len(event_list))) - time.sleep(randint(1, 5)) +def publish_event(): + # authenticate client + credential = AzureKeyCredential(key) + client = EventGridPublisherClient(topic_hostname, credential) + + custom_schema_event = { + "customSubject": "sample", + "customEventType": "sample.event", + "customDataVersion": "2.0", + "customId": uuid.uuid4(), + "customEventTime": dt.datetime.now(UTC()).isoformat(), + "customData": "sample data" + } + + # publish events + for _ in range(10): + + event_list = [] # list of events to publish + # create events and append to list + for j in range(randint(1, 3)): + event = CustomEvent(custom_schema_event) + event_list.append(event) + + # publish list of events + client.send(event_list) + print("Batch of size {} published".format(len(event_list))) + time.sleep(randint(1, 5)) + + +if __name__ == '__main__': + publish_event() \ No newline at end of file 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/publish_samples/publish_event_grid_events_to_custom_topic_sample.py index a8379f5cf84a..733222b6eb3e 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py @@ -1,12 +1,19 @@ -import sys +""" +FILE: publish_event_grid_events_to_custom_topic_sample.py +DESCRIPTION: + These samples demonstrate creating a list of Eventgrid Events and sending them as a list + to custom topic. +USAGE: + python publish_event_grid_events_to_custom_topic_sample.py + Set the environment variables with your own values before running the sample: + 1) EG_ACCESS_KEY - The access key of your eventgrid account. + 2) EG_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". +""" import os from random import randint, sample import time -PACKAGE_PARENT = '..' -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) -sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) - from azure.core.credentials import AzureKeyCredential from azure.eventgrid import EventGridPublisherClient, EventGridEvent @@ -19,22 +26,26 @@ team_members = ["Josh", "Kerri", "Kieran", "Laurent", "Lily", "Matt", "Soren", "Srikanta", "Swathi"] # possible values for data field -# publish events -while True: - - event_list = [] # list of events to publish - # create events and append to list - for j in range(randint(1, 3)): - sample_members = sample(team_members, k=randint(1, 9)) # select random subset of team members - event = EventGridEvent( - subject="Door1", - data={"team": sample_members}, - event_type="Azure.Sdk.Demo", - data_version="2.0" - ) - event_list.append(event) - - # publish list of events - client.send(event_list) - print("Batch of size {} published".format(len(event_list))) - time.sleep(randint(1, 5)) +def publish_event(): + # publish events + while True: + + event_list = [] # list of events to publish + # create events and append to list + for j in range(randint(1, 3)): + sample_members = sample(team_members, k=randint(1, 9)) # select random subset of team members + event = EventGridEvent( + subject="Door1", + data={"team": sample_members}, + event_type="Azure.Sdk.Demo", + data_version="2.0" + ) + event_list.append(event) + + # publish list of events + client.send(event_list) + print("Batch of size {} published".format(len(event_list))) + time.sleep(randint(1, 5)) + +if __name__ == '__main__': + publish_event() \ No newline at end of file diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py index 80ba720ccfd6..5f8024b42e3e 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py @@ -1,12 +1,19 @@ -import sys +""" +FILE: publish_with_shared_access_signature_sample.py +DESCRIPTION: + These samples demonstrate creating a list of CloudEvents and publish them + using the shared access signature for authentication. +USAGE: + python publish_with_shared_access_signature_sample.py + Set the environment variables with your own values before running the sample: + 1) CLOUD_ACCESS_KEY - The access key of your eventgrid account. + 2) CLOUD_TOPIC_HOSTNAME - The topic hostname. Typically it exists in the format + "..eventgrid.azure.net". +""" import os from random import randint, sample import time -PACKAGE_PARENT = '..' -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) -sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) - from dateutil.tz import tzutc from datetime import timedelta import datetime as dt @@ -25,21 +32,25 @@ team_members = ["Josh", "Kerri", "Kieran", "Laurent", "Lily", "Matt", "Soren", "Srikanta", "Swathi"] # possible values for data field -# publish events -while True: - - event_list = [] # list of events to publish - # create events and append to list - for j in range(randint(1, 3)): - sample_members = sample(team_members, k=randint(1, 9)) # select random subset of team members - event = CloudEvent( - type="Azure.Sdk.Demo", - source="https://egdemo.dev/demowithsignature", - data={"team": sample_members} - ) - event_list.append(event) - - # publish list of events - client.send(event_list) - print("Batch of size {} published".format(len(event_list))) - time.sleep(randint(1, 5)) +def publish_event(): + # publish events + for _ in range(10): + + event_list = [] # list of events to publish + # create events and append to list + for j in range(randint(1, 3)): + sample_members = sample(team_members, k=randint(1, 9)) # select random subset of team members + event = CloudEvent( + type="Azure.Sdk.Demo", + source="https://egdemo.dev/demowithsignature", + data={"team": sample_members} + ) + event_list.append(event) + + # publish list of events + client.send(event_list) + print("Batch of size {} published".format(len(event_list))) + time.sleep(randint(1, 5)) + +if __name__ == '__main__': + publish_event() From 75478f3afcbbc69b86b301178b34f04a16ff9ca6 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 4 Sep 2020 00:45:32 -0700 Subject: [PATCH 2/5] Apply suggestions from code review --- .../publish_cloud_events_to_domain_topic_sample.py | 2 +- .../publish_custom_schema_events_to_topic_sample.py | 2 +- .../publish_event_grid_events_to_custom_topic_sample.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py index 082d43827854..78d3e93cf973 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py @@ -51,4 +51,4 @@ def publish_event(): time.sleep(randint(1, 5)) if __name__ == '__main__': - publish_event() \ No newline at end of file + publish_event() diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py index 3741ab373435..0a05c65d506a 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py @@ -52,4 +52,4 @@ def publish_event(): if __name__ == '__main__': - publish_event() \ No newline at end of file + publish_event() 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/publish_samples/publish_event_grid_events_to_custom_topic_sample.py index 733222b6eb3e..f0ae21e91dff 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py @@ -48,4 +48,4 @@ def publish_event(): time.sleep(randint(1, 5)) if __name__ == '__main__': - publish_event() \ No newline at end of file + publish_event() From 2d48fbf54b26feacebde063ecc5f86b406a63b63 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Thu, 3 Sep 2020 22:10:41 -0700 Subject: [PATCH 3/5] few more docstrings --- .../consume_samples/consume_cloud_custom_data_sample.py | 2 +- .../consume_eg_storage_blob_created_data_sample.py | 2 +- .../e2e_samples/consume_cloud_events_from_eventhub.py | 6 +----- .../consume_cloud_events_from_service_bus_queue.py | 2 +- .../e2e_samples/consume_cloud_events_from_storage_queue.py | 2 +- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py index 30398f9b583a..3f5f7f8da283 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py @@ -1,7 +1,7 @@ """ FILE: consume_cloud_custom_data_sample.py DESCRIPTION: - These samples demonstrate creating a list of CloudEvents and sending then as a list. + These samples demonstrate consuming custom cloud data USAGE: python consume_cloud_custom_data_sample.py Set the environment variables with your own values before running the sample: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py index 152b2a6920de..894a471a354c 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py @@ -1,7 +1,7 @@ """ FILE: consume_eg_storage_blob_created_data_sample.py DESCRIPTION: - These samples demonstrate creating a list of CloudEvents and sending then as a list. + These samples demonstrate consuming custom eventgrid event data. USAGE: python consume_eg_storage_blob_created_data_sample.py Set the environment variables with your own values before running the sample: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py index 5e7a6ffd9f85..fd820ea90d87 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py @@ -1,7 +1,7 @@ """ FILE: consume_cloud_events_from_eventhub.py DESCRIPTION: - These samples demonstrate creating a list of CloudEvents and sending then as a list. + These samples demonstrate receiving events from an Event Hub. USAGE: python consume_cloud_events_from_eventhub.py Set the environment variables with your own values before running the sample: @@ -13,10 +13,6 @@ from azure.eventgrid import EventGridConsumer, CloudEvent, EventGridEvent from azure.eventhub import EventHubConsumerClient -""" -An example to show receiving events from an Event Hub. -""" - CONNECTION_STR = os.environ["EVENT_HUB_CONN_STR"] EVENTHUB_NAME = os.environ["EVENTHUB_NAME"] diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py index aa8263d4bc3d..26b627179ea4 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py @@ -1,7 +1,7 @@ """ FILE: consume_cloud_events_from_eventhub.py DESCRIPTION: - These samples demonstrate creating a list of CloudEvents and sending then as a list. + These samples demonstrate receiving events from Service Bus. USAGE: python consume_cloud_events_from_eventhub.py Set the environment variables with your own values before running the sample: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py index b1e57e9e7e1e..db341bd55572 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py @@ -1,7 +1,7 @@ """ FILE: consume_cloud_events_from_eventhub.py DESCRIPTION: - These samples demonstrate creating a list of CloudEvents and sending then as a list. + These samples demonstrate receiving events from a Storage Queue. USAGE: python consume_cloud_events_from_eventhub.py Set the environment variables with your own values before running the sample: From 09e53d9370563ed96abf682147c7d68ce868f87d Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Thu, 3 Sep 2020 22:15:26 -0700 Subject: [PATCH 4/5] decode --- .../samples/champion_scenarios/cs3_consume_system_events.py | 2 +- .../samples/champion_scenarios/cs4_consume_custom_events.py | 2 +- .../cs6_consume_events_using_cloud_events_1.0_schema.py | 2 +- .../consume_samples/consume_cloud_custom_data_sample.py | 6 +++--- .../consume_eg_storage_blob_created_data_sample.py | 6 +++--- .../e2e_samples/consume_cloud_events_from_eventhub.py | 2 +- .../consume_cloud_events_from_service_bus_queue.py | 5 +++-- .../e2e_samples/consume_cloud_events_from_storage_queue.py | 5 +++-- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py index 5f46ea50bcd2..f07298151ddc 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py @@ -11,7 +11,7 @@ consumer = EventGridConsumer() # returns List[DeserializedEvent] -deserialized_events = consumer.deserialize_events(service_bus_received_message) +deserialized_events = consumer.decode_eventgrid_event(service_bus_received_message) # EventGridEvent schema, Storage.BlobCreated event for event in deserialized_events: diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py index ea5799322088..fd4666b0ba4f 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py @@ -11,7 +11,7 @@ consumer = EventGridConsumer() # returns List[DeserializedEvent] -deserialized_events = consumer.deserialize_events(service_bus_received_message) +deserialized_events = consumer.decode_eventgrid_event(service_bus_received_message) # EventGridEvent schema, with custom event type for event in deserialized_events: diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py index 278efccdea7d..6d871bbb10ac 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py @@ -11,7 +11,7 @@ consumer = EventGridConsumer() # returns List[DeserializedEvent] -deserialized_events = consumer.deserialize_events(service_bus_received_message) +deserialized_events = consumer.decode_eventgrid_event(service_bus_received_message) # CloudEvent schema for event in deserialized_events: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py index 3f5f7f8da283..94fc68b80a89 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py @@ -22,9 +22,9 @@ cloud_custom_bytes = bytes(cloud_custom_string, "utf-8") client = EventGridConsumer() -deserialized_dict_event = client.deserialize_event(cloud_custom_dict) -deserialized_str_event = client.deserialize_event(cloud_custom_string) -deserialized_bytes_event = client.deserialize_event(cloud_custom_bytes) +deserialized_dict_event = client.decode_cloud_event(cloud_custom_dict) +deserialized_str_event = client.decode_cloud_event(cloud_custom_string) +deserialized_bytes_event = client.decode_cloud_event(cloud_custom_bytes) print(deserialized_bytes_event.model == deserialized_str_event.model) print(deserialized_bytes_event.model == deserialized_dict_event.model) \ No newline at end of file diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py index 894a471a354c..3ce2ebeecf02 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py @@ -36,9 +36,9 @@ eg_storage_bytes = bytes(eg_storage_string, "utf-8") client = EventGridConsumer() -deserialized_dict_event = client.deserialize_event(eg_storage_dict) -deserialized_str_event = client.deserialize_event(eg_storage_string) -deserialized_bytes_event = client.deserialize_event(eg_storage_bytes) +deserialized_dict_event = client.decode_eventgrid_event(eg_storage_dict) +deserialized_str_event = client.decode_eventgrid_event(eg_storage_string) +deserialized_bytes_event = client.decode_eventgrid_event(eg_storage_bytes) print(deserialized_bytes_event.model == deserialized_str_event.model) print(deserialized_bytes_event.model == deserialized_dict_event.model) diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py index fd820ea90d87..4ea4fb633644 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py @@ -20,7 +20,7 @@ def on_event(partition_context, event): dict_event = event.body_as_json()[0] - deserialized_event = eg_consumer.deserialize_event(dict_event) + deserialized_event = eg_consumer.decode_eventgrid_event(dict_event) if deserialized_event.model.__class__ == CloudEvent: dict_event = deserialized_event.to_json() print("event.type: {}\n".format(dict_event["type"])) diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py index 26b627179ea4..92a324185483 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py @@ -28,13 +28,14 @@ print("number of messages: {}".format(len(msgs))) for msg in msgs: # receive single dict message - deserialized_event = consumer.deserialize_event(str(msg)) - if deserialized_event.model.__class__ == CloudEvent: + if 'specversion' in msg: + deserialized_event = consumer.decode_cloud_event(str(msg)) dict_event = deserialized_event.to_json() print("event.to_json(): {}\n".format(dict_event)) print("model: {}\n".format(deserialized_event.model)) print("model.data: {}\n".format(deserialized_event.model.data)) else: + deserialized_event = consumer.decode_eventgrid_event(str(msg)) dict_event = deserialized_event.to_json() print("event.to_json(): {}\n".format(dict_event)) print("model: {}\n".format(deserialized_event.model)) diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py index db341bd55572..5ee6b808a3f7 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py @@ -23,14 +23,15 @@ msgs = queue_client.receive_messages() for msg in msgs: # receive single dict message - deserialized_event = consumer.deserialize_event(b64decode(msg.content)) - if deserialized_event.model.__class__ == CloudEvent: + if 'specversion' in msg: + deserialized_event = consumer.decode_cloud_event(b64decode(msg.content)) dict_event = deserialized_event.to_json() print("event.type: {}\n".format(dict_event["type"])) print("event.to_json(): {}\n".format(dict_event)) print("model: {}\n".format(deserialized_event.model)) print("model.data: {}\n".format(deserialized_event.model.data)) else: + deserialized_event = consumer.decode_eventgrid_event(b64decode(msg.content)) dict_event = deserialized_event.to_json() print("event.to_json(): {}\n".format(dict_event)) print("model: {}\n".format(deserialized_event.model)) From da6ce52b6e74d7d0e4ed77d5af328dcf13eb2a90 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 4 Sep 2020 10:21:49 -0700 Subject: [PATCH 5/5] add licesnse --- .../cs1_publish_custom_events_to_a_topic.py | 5 +++++ .../cs1b_publish_custom_events_to_a_topic_with_signature.py | 5 +++++ .../cs2_publish_custom_events_to_a_domain_topic.py | 5 +++++ .../samples/champion_scenarios/cs3_consume_system_events.py | 5 +++++ .../samples/champion_scenarios/cs4_consume_custom_events.py | 5 +++++ .../cs5_publish_events_using_cloud_events_1.0_schema.py | 5 +++++ .../cs6_consume_events_using_cloud_events_1.0_schema.py | 5 +++++ .../consume_samples/consume_cloud_custom_data_sample.py | 5 +++++ .../consume_eg_storage_blob_created_data_sample.py | 5 +++++ .../e2e_samples/consume_cloud_events_from_eventhub.py | 5 +++++ .../consume_cloud_events_from_service_bus_queue.py | 5 +++++ .../e2e_samples/consume_cloud_events_from_storage_queue.py | 5 +++++ .../publish_cloud_events_to_custom_topic_sample.py | 5 +++++ .../publish_cloud_events_to_domain_topic_sample.py | 5 +++++ .../publish_custom_schema_events_to_topic_sample.py | 5 +++++ .../publish_event_grid_events_to_custom_topic_sample.py | 5 +++++ .../publish_with_shared_access_signature_sample.py | 5 +++++ 17 files changed, 85 insertions(+) diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py index 91753f083946..9fb0cd9e559e 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: cs1_publish_custom_events_to_a_topic.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py index a635b7ef5d2c..fc28c92e0726 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: cs1b_publish_custom_events_to_a_topic_with_signature.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py index a6b0e666dd98..0cbb9397c0fc 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs2_publish_custom_events_to_a_domain_topic.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: cs2_publish_custom_events_to_a_domain_topic.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py index f07298151ddc..1e325bfc0666 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs3_consume_system_events.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: cs3_consume_system_events.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py index fd4666b0ba4f..ea2fed0e3976 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs4_consume_custom_events.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: cs4_consume_custom_events.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py index 84a6e01435d1..674a3851b495 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: cs5_publish_events_using_cloud_events_1.0_schema.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py index 6d871bbb10ac..886b96d6b50e 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py +++ b/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs6_consume_events_using_cloud_events_1.0_schema.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: cs6_consume_events_using_cloud_events_1.0_schema.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py index 94fc68b80a89..9553dce745f6 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_cloud_custom_data_sample.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: consume_cloud_custom_data_sample.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py index 3ce2ebeecf02..5a57a4ce9a38 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/consume_eg_storage_blob_created_data_sample.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: consume_eg_storage_blob_created_data_sample.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py index 4ea4fb633644..556e3a6beb19 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_eventhub.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: consume_cloud_events_from_eventhub.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py index 92a324185483..17e902ef0ebf 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_service_bus_queue.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: consume_cloud_events_from_eventhub.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py index 5ee6b808a3f7..29e6247ca044 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py +++ b/sdk/eventgrid/azure-eventgrid/samples/consume_samples/e2e_samples/consume_cloud_events_from_storage_queue.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: consume_cloud_events_from_eventhub.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py index 787acb01cfed..c538cd235d73 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_custom_topic_sample.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: publish_cloud_events_to_custom_topic_sample.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py index 78d3e93cf973..54b5d23b1c8b 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_cloud_events_to_domain_topic_sample.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: publish_cloud_events_to_domain_topic_sample.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py index 0a05c65d506a..4396938d8ee1 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_custom_schema_events_to_topic_sample.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: publish_custom_schema_events_to_topic_sample.py DESCRIPTION: 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/publish_samples/publish_event_grid_events_to_custom_topic_sample.py index f0ae21e91dff..d10b5ca6e76e 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_event_grid_events_to_custom_topic_sample.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: publish_event_grid_events_to_custom_topic_sample.py DESCRIPTION: diff --git a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py index 5f8024b42e3e..ba88862b9629 100644 --- a/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py +++ b/sdk/eventgrid/azure-eventgrid/samples/publish_samples/publish_with_shared_access_signature_sample.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- """ FILE: publish_with_shared_access_signature_sample.py DESCRIPTION: