From 1c800b49d8a2ef956128d293959149e319baa3f7 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 25 Jan 2021 12:02:55 -0800 Subject: [PATCH 1/2] rename to generate_sas --- sdk/eventgrid/azure-eventgrid/CHANGELOG.md | 1 + sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py | 4 ++-- sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py | 2 +- .../cs1b_publish_custom_events_to_a_topic_with_signature.py | 4 ++-- .../publish_with_shared_access_signature_sample.py | 4 ++-- .../azure-eventgrid/tests/test_eg_publisher_client.py | 4 ++-- .../azure-eventgrid/tests/test_eg_publisher_client_async.py | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/sdk/eventgrid/azure-eventgrid/CHANGELOG.md b/sdk/eventgrid/azure-eventgrid/CHANGELOG.md index 3067c83116b7..d6feaf2222cb 100644 --- a/sdk/eventgrid/azure-eventgrid/CHANGELOG.md +++ b/sdk/eventgrid/azure-eventgrid/CHANGELOG.md @@ -11,6 +11,7 @@ - The `send` method in the `EventGridPubliserClient` is now replaced by the `send_events`. - `topic_hostname` is renamed to `endpoint` in the `EventGridPublisherClient`. - `data` is now a required param for `CloudEvent`. + - `generate_shared_access_signature` is now renamed to `generate_sas` **Bug Fixes** - `EventGridEvent` has two additional required positional parameters namely, `data` and `data_version`. diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py index 51feb54d8776..2685b6fd6780 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py @@ -6,11 +6,11 @@ from ._publisher_client import EventGridPublisherClient from ._consumer import EventGridDeserializer -from ._helpers import generate_shared_access_signature +from ._helpers import generate_sas from ._models import CloudEvent, CustomEvent, EventGridEvent from ._version import VERSION __all__ = ['EventGridPublisherClient', 'EventGridDeserializer', - 'CloudEvent', 'CustomEvent', 'EventGridEvent', 'generate_shared_access_signature' + 'CloudEvent', 'CustomEvent', 'EventGridEvent', 'generate_sas' ] __version__ = VERSION diff --git a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py index b955ad7e3b03..6031491d89d0 100644 --- a/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py +++ b/sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: from datetime import datetime -def generate_shared_access_signature(endpoint, shared_access_key, expiration_date_utc, **kwargs): +def generate_sas(endpoint, shared_access_key, expiration_date_utc, **kwargs): # type: (str, str, datetime, Any) -> str """ Helper method to generate shared access signature given hostname, key, and expiration date. :param str endpoint: The topic endpoint to send the events to. 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 37fe967dcf2b..84bd8d0ce325 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 @@ -15,7 +15,7 @@ "..eventgrid.azure.net". """ import os -from azure.eventgrid import EventGridPublisherClient, EventGridEvent, generate_shared_access_signature +from azure.eventgrid import EventGridPublisherClient, EventGridEvent, generate_sas from azure.core.credentials import AzureKeyCredential, AzureSasCredential from datetime import datetime, timedelta @@ -23,7 +23,7 @@ endpoint = os.environ["EG_TOPIC_HOSTNAME"] expiration_date_utc = datetime.utcnow() + timedelta(hours=1) -signature = generate_shared_access_signature(endpoint, topic_key, expiration_date_utc) +signature = generate_sas(endpoint, topic_key, expiration_date_utc) credential = AzureSasCredential(signature) client = EventGridPublisherClient(endpoint, credential) 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 dde9dda4d703..dafddd78680f 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 @@ -21,13 +21,13 @@ from datetime import datetime, timedelta from azure.core.credentials import AzureSasCredential -from azure.eventgrid import EventGridPublisherClient, CloudEvent, generate_shared_access_signature +from azure.eventgrid import EventGridPublisherClient, CloudEvent, generate_sas key = os.environ["CLOUD_ACCESS_KEY"] endpoint = os.environ["CLOUD_TOPIC_HOSTNAME"] expiration_date_utc = datetime.utcnow() + timedelta(hours=1) -signature = generate_shared_access_signature(endpoint, key, expiration_date_utc) +signature = generate_sas(endpoint, key, expiration_date_utc) # authenticate client credential = AzureSasCredential(signature) diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py index d55c9c71a6f3..490b94a57175 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client.py @@ -16,7 +16,7 @@ from azure_devtools.scenario_tests import ReplayableTest from azure.core.credentials import AzureKeyCredential, AzureSasCredential -from azure.eventgrid import EventGridPublisherClient, CloudEvent, EventGridEvent, CustomEvent, generate_shared_access_signature +from azure.eventgrid import EventGridPublisherClient, CloudEvent, EventGridEvent, CustomEvent, generate_sas from eventgrid_preparer import ( CachedEventGridTopicPreparer @@ -197,7 +197,7 @@ def test_send_cloud_event_dict(self, resource_group, eventgrid_topic, eventgrid_ @CachedEventGridTopicPreparer(name_prefix='eventgridtest') def test_send_signature_credential(self, resource_group, eventgrid_topic, eventgrid_topic_primary_key, eventgrid_topic_endpoint): expiration_date_utc = dt.datetime.now(UTC()) + timedelta(hours=1) - signature = generate_shared_access_signature(eventgrid_topic_endpoint, eventgrid_topic_primary_key, expiration_date_utc) + signature = generate_sas(eventgrid_topic_endpoint, eventgrid_topic_primary_key, expiration_date_utc) credential = AzureSasCredential(signature) client = EventGridPublisherClient(eventgrid_topic_endpoint, credential) eg_event = EventGridEvent( diff --git a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py index fd801f452b16..66164fc898e3 100644 --- a/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py +++ b/sdk/eventgrid/azure-eventgrid/tests/test_eg_publisher_client_async.py @@ -17,7 +17,7 @@ from azure_devtools.scenario_tests import ReplayableTest from azure.core.credentials import AzureKeyCredential, AzureSasCredential -from azure.eventgrid import CloudEvent, EventGridEvent, CustomEvent, generate_shared_access_signature +from azure.eventgrid import CloudEvent, EventGridEvent, CustomEvent, generate_sas from azure.eventgrid.aio import EventGridPublisherClient from eventgrid_preparer import ( @@ -216,7 +216,7 @@ async def test_send_cloud_event_data_none(self, resource_group, eventgrid_topic, @pytest.mark.asyncio async def test_send_signature_credential(self, resource_group, eventgrid_topic, eventgrid_topic_primary_key, eventgrid_topic_endpoint): expiration_date_utc = dt.datetime.now(UTC()) + timedelta(hours=1) - signature = generate_shared_access_signature(eventgrid_topic_endpoint, eventgrid_topic_primary_key, expiration_date_utc) + signature = generate_sas(eventgrid_topic_endpoint, eventgrid_topic_primary_key, expiration_date_utc) credential = AzureSasCredential(signature) client = EventGridPublisherClient(eventgrid_topic_endpoint, credential) eg_event = EventGridEvent( From 2fadb2d79077f97fe44cd2e894ba1cedd5cb34c0 Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Mon, 25 Jan 2021 12:08:44 -0800 Subject: [PATCH 2/2] Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md Co-authored-by: Adam Ling (MSFT) --- sdk/eventgrid/azure-eventgrid/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/eventgrid/azure-eventgrid/CHANGELOG.md b/sdk/eventgrid/azure-eventgrid/CHANGELOG.md index d6feaf2222cb..f8922f12c804 100644 --- a/sdk/eventgrid/azure-eventgrid/CHANGELOG.md +++ b/sdk/eventgrid/azure-eventgrid/CHANGELOG.md @@ -11,7 +11,7 @@ - The `send` method in the `EventGridPubliserClient` is now replaced by the `send_events`. - `topic_hostname` is renamed to `endpoint` in the `EventGridPublisherClient`. - `data` is now a required param for `CloudEvent`. - - `generate_shared_access_signature` is now renamed to `generate_sas` + - `azure.eventgrid.generate_shared_access_signature` method is now renamed to `generate_sas`. **Bug Fixes** - `EventGridEvent` has two additional required positional parameters namely, `data` and `data_version`.