Skip to content

Commit

Permalink
rename to generate_sas (Azure#16330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakshith Bhyravabhotla authored Jan 25, 2021
1 parent 0ae2052 commit 8c725c5
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions sdk/eventgrid/azure-eventgrid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
- `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`.
Expand Down
4 changes: 2 additions & 2 deletions sdk/eventgrid/azure-eventgrid/azure/eventgrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"<YOUR-TOPIC-NAME>.<REGION-NAME>.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

topic_key = os.environ["EG_ACCESS_KEY"]
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8c725c5

Please sign in to comment.