Skip to content

Commit 411c0ef

Browse files
author
Rakshith Bhyravabhotla
authored
Naming Feedback - part 2 (Azure#16210)
* reorder * Naming feedback - part 2 * cahngelog * Update sdk/eventgrid/azure-eventgrid/CHANGELOG.md
1 parent 989edaf commit 411c0ef

15 files changed

+67
-66
lines changed

sdk/eventgrid/azure-eventgrid/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- `EventGridConsumer` is now renamed to `EventGridDeserializer`.
88
- `decode_cloud_event` is renamed to `deserialize_cloud_events`.
99
- `decode_eventgrid_event` is renamed to `deserialize_eventgrid_events`.
10+
- `topic_hostname` is renamed to `endpoint` in the `EventGridPublisherClient`.
1011

1112
**Bug Fixes**
1213
- `EventGridEvent` has two additional required positional parameters namely, `data` and `data_version`.

sdk/eventgrid/azure-eventgrid/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ az eventgrid domain --create --location <location> --resource-group <resource-gr
3535

3636
### Authenticate the client
3737
In order to interact with the Event Grid service, you will need to create an instance of a client.
38-
A **topic_hostname** and **credential** are necessary to instantiate the client object.
38+
An **endpoint** and **credential** are necessary to instantiate the client object.
3939

4040
#### Looking up the endpoint
4141
You can find the endpoint and the hostname on the Azure portal.
@@ -49,9 +49,9 @@ pass the key as a string into an instance of [AzureKeyCredential][azure-key-cred
4949
from azure.core.credentials import AzureKeyCredential
5050
from azure.eventgrid import EventGridPublisherClient
5151

52-
topic_hostname = "https://<name>.<region>.eventgrid.azure.net"
52+
endpoint = "https://<name>.<region>.eventgrid.azure.net"
5353
credential = AzureKeyCredential("<api_key>")
54-
eg_publisher_client = EventGridPublisherClient(topic_hostname, credential)
54+
eg_publisher_client = EventGridPublisherClient(endpoint, credential)
5555
```
5656

5757
## Key concepts
@@ -84,17 +84,17 @@ from azure.core.credentials import AzureKeyCredential
8484
from azure.eventgrid import EventGridPublisherClient, EventGridEvent
8585

8686
key = os.environ["EG_ACCESS_KEY"]
87-
topic_hostname = os.environ["EG_TOPIC_HOSTNAME"]
87+
endpoint = os.environ["EG_TOPIC_HOSTNAME"]
8888

8989
event = EventGridEvent(
90-
subject="Door1",
9190
data={"team": "azure-sdk"},
91+
subject="Door1",
9292
event_type="Azure.Sdk.Demo",
9393
data_version="2.0"
9494
)
9595

9696
credential = AzureKeyCredential(key)
97-
client = EventGridPublisherClient(topic_hostname, credential)
97+
client = EventGridPublisherClient(endpoint, credential)
9898

9999
client.send(event)
100100
```
@@ -109,7 +109,7 @@ from azure.core.credentials import AzureKeyCredential
109109
from azure.eventgrid import EventGridPublisherClient, CloudEvent
110110

111111
key = os.environ["CLOUD_ACCESS_KEY"]
112-
topic_hostname = os.environ["CLOUD_TOPIC_HOSTNAME"]
112+
endpoint = os.environ["CLOUD_TOPIC_HOSTNAME"]
113113

114114
event = CloudEvent(
115115
type="Azure.Sdk.Sample",
@@ -118,7 +118,7 @@ event = CloudEvent(
118118
)
119119

120120
credential = AzureKeyCredential(key)
121-
client = EventGridPublisherClient(topic_hostname, credential)
121+
client = EventGridPublisherClient(endpoint, credential)
122122

123123
client.send(event)
124124
```

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_helpers.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
if TYPE_CHECKING:
2121
from datetime import datetime
2222

23-
def generate_shared_access_signature(topic_hostname, shared_access_key, expiration_date_utc, **kwargs):
23+
def generate_shared_access_signature(endpoint, shared_access_key, expiration_date_utc, **kwargs):
2424
# type: (str, str, datetime, Any) -> str
2525
""" Helper method to generate shared access signature given hostname, key, and expiration date.
26-
:param str topic_hostname: The topic endpoint to send the events to.
26+
:param str endpoint: The topic endpoint to send the events to.
2727
Similar to <YOUR-TOPIC-NAME>.<YOUR-REGION-NAME>-1.eventgrid.azure.net
2828
:param str shared_access_key: The shared access key to be used for generating the token
2929
:param datetime.datetime expiration_date_utc: The expiration datetime in UTC for the signature.
@@ -32,39 +32,39 @@ def generate_shared_access_signature(topic_hostname, shared_access_key, expirati
3232
:rtype: str
3333
"""
3434

35-
full_topic_hostname = _get_full_topic_hostname(topic_hostname)
35+
full_endpoint = _get_full_endpoint(endpoint)
3636

37-
full_topic_hostname = "{}?apiVersion={}".format(
38-
full_topic_hostname,
37+
full_endpoint = "{}?apiVersion={}".format(
38+
full_endpoint,
3939
kwargs.get('api_version', None) or constants.DEFAULT_API_VERSION
4040
)
41-
encoded_resource = quote(full_topic_hostname, safe=constants.SAFE_ENCODE)
41+
encoded_resource = quote(full_endpoint, safe=constants.SAFE_ENCODE)
4242
encoded_expiration_utc = quote(str(expiration_date_utc), safe=constants.SAFE_ENCODE)
4343

4444
unsigned_sas = "r={}&e={}".format(encoded_resource, encoded_expiration_utc)
4545
signature = quote(_generate_hmac(shared_access_key, unsigned_sas), safe=constants.SAFE_ENCODE)
4646
signed_sas = "{}&s={}".format(unsigned_sas, signature)
4747
return signed_sas
4848

49-
def _get_topic_hostname_only_fqdn(topic_hostname):
50-
if topic_hostname.startswith('http://'):
49+
def _get_endpoint_only_fqdn(endpoint):
50+
if endpoint.startswith('http://'):
5151
raise ValueError("HTTP is not supported. Only HTTPS is supported.")
52-
if topic_hostname.startswith('https://'):
53-
topic_hostname = topic_hostname.replace("https://", "")
54-
if topic_hostname.endswith("/api/events"):
55-
topic_hostname = topic_hostname.replace("/api/events", "")
52+
if endpoint.startswith('https://'):
53+
endpoint = endpoint.replace("https://", "")
54+
if endpoint.endswith("/api/events"):
55+
endpoint = endpoint.replace("/api/events", "")
5656

57-
return topic_hostname
57+
return endpoint
5858

59-
def _get_full_topic_hostname(topic_hostname):
60-
if topic_hostname.startswith('http://'):
59+
def _get_full_endpoint(endpoint):
60+
if endpoint.startswith('http://'):
6161
raise ValueError("HTTP is not supported. Only HTTPS is supported.")
62-
if not topic_hostname.startswith('https://'):
63-
topic_hostname = "https://{}".format(topic_hostname)
64-
if not topic_hostname.endswith("/api/events"):
65-
topic_hostname = "{}/api/events".format(topic_hostname)
62+
if not endpoint.startswith('https://'):
63+
endpoint = "https://{}".format(endpoint)
64+
if not endpoint.endswith("/api/events"):
65+
endpoint = "{}/api/events".format(endpoint)
6666

67-
return topic_hostname
67+
return endpoint
6868

6969
def _generate_hmac(key, message):
7070
decoded_key = base64.b64decode(key)

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ class EventGridEvent(InternalEventGridEvent, EventMixin):
180180
'data_version': {'key': 'dataVersion', 'type': 'str'},
181181
}
182182

183-
def __init__(self, subject, event_type, data, data_version, **kwargs):
184-
# type: (str, str, object, str, Any) -> None
183+
def __init__(self, data, subject, event_type, data_version, **kwargs):
184+
# type: (object, str, str, str, Any) -> None
185185
kwargs.setdefault('id', uuid.uuid4())
186186
kwargs.setdefault('subject', subject)
187187
kwargs.setdefault("event_type", event_type)

sdk/eventgrid/azure-eventgrid/azure/eventgrid/_publisher_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from ._models import CloudEvent, EventGridEvent, CustomEvent
2626
from ._helpers import (
27-
_get_topic_hostname_only_fqdn,
27+
_get_endpoint_only_fqdn,
2828
_get_authentication_policy,
2929
_is_cloud_event,
3030
_eventgrid_data_typecheck
@@ -59,17 +59,17 @@
5959
class EventGridPublisherClient(object):
6060
"""EventGrid Python Publisher Client.
6161
62-
:param str topic_hostname: The topic endpoint to send the events to.
62+
:param str endpoint: The topic endpoint to send the events to.
6363
:param credential: The credential object used for authentication which
6464
implements SAS key authentication or SAS token authentication.
6565
:type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.AzureSasCredential
6666
"""
6767

68-
def __init__(self, topic_hostname, credential, **kwargs):
68+
def __init__(self, endpoint, credential, **kwargs):
6969
# type: (str, Union[AzureKeyCredential, AzureSasCredential], Any) -> None
70-
topic_hostname = _get_topic_hostname_only_fqdn(topic_hostname)
70+
endpoint = _get_endpoint_only_fqdn(endpoint)
7171

72-
self._topic_hostname = topic_hostname
72+
self._endpoint = endpoint
7373
self._client = EventGridPublisherClientImpl(
7474
policies=EventGridPublisherClient._policies(credential, **kwargs),
7575
**kwargs
@@ -120,17 +120,17 @@ def send(self, events, **kwargs):
120120
pass # means it's a dictionary
121121
kwargs.setdefault("content_type", "application/cloudevents-batch+json; charset=utf-8")
122122
self._client.publish_cloud_event_events(
123-
self._topic_hostname,
123+
self._endpoint,
124124
cast(List[InternalCloudEvent], events),
125125
**kwargs
126126
)
127127
elif all(isinstance(e, EventGridEvent) for e in events) or all(isinstance(e, dict) for e in events):
128128
kwargs.setdefault("content_type", "application/json; charset=utf-8")
129129
for event in events:
130130
_eventgrid_data_typecheck(event)
131-
self._client.publish_events(self._topic_hostname, cast(List[InternalEventGridEvent], events), **kwargs)
131+
self._client.publish_events(self._endpoint, cast(List[InternalEventGridEvent], events), **kwargs)
132132
elif all(isinstance(e, CustomEvent) for e in events):
133133
serialized_events = [dict(e) for e in events] # type: ignore
134-
self._client.publish_custom_event_events(self._topic_hostname, cast(List, serialized_events), **kwargs)
134+
self._client.publish_custom_event_events(self._endpoint, cast(List, serialized_events), **kwargs)
135135
else:
136136
raise ValueError("Event schema is not correct.")

sdk/eventgrid/azure-eventgrid/azure/eventgrid/aio/_publisher_client_async.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .._policies import CloudEventDistributedTracingPolicy
2626
from .._models import CloudEvent, EventGridEvent, CustomEvent
2727
from .._helpers import (
28-
_get_topic_hostname_only_fqdn,
28+
_get_endpoint_only_fqdn,
2929
_get_authentication_policy,
3030
_is_cloud_event,
3131
_eventgrid_data_typecheck
@@ -55,23 +55,23 @@
5555
class EventGridPublisherClient():
5656
"""Asynchronous EventGrid Python Publisher Client.
5757
58-
:param str topic_hostname: The topic endpoint to send the events to.
58+
:param str endpoint: The topic endpoint to send the events to.
5959
:param credential: The credential object used for authentication which implements
6060
SAS key authentication or SAS token authentication.
6161
:type credential: ~azure.core.credentials.AzureKeyCredential or ~azure.core.credentials.AzureSasCredential
6262
"""
6363

6464
def __init__(
6565
self,
66-
topic_hostname: str,
66+
endpoint: str,
6767
credential: Union[AzureKeyCredential, AzureSasCredential],
6868
**kwargs: Any) -> None:
6969
self._client = EventGridPublisherClientAsync(
7070
policies=EventGridPublisherClient._policies(credential, **kwargs),
7171
**kwargs
7272
)
73-
topic_hostname = _get_topic_hostname_only_fqdn(topic_hostname)
74-
self._topic_hostname = topic_hostname
73+
endpoint = _get_endpoint_only_fqdn(endpoint)
74+
self._endpoint = endpoint
7575

7676
@staticmethod
7777
def _policies(
@@ -124,7 +124,7 @@ async def send(
124124
pass # means it's a dictionary
125125
kwargs.setdefault("content_type", "application/cloudevents-batch+json; charset=utf-8")
126126
await self._client.publish_cloud_event_events(
127-
self._topic_hostname,
127+
self._endpoint,
128128
cast(List[InternalCloudEvent], events),
129129
**kwargs
130130
)
@@ -133,14 +133,14 @@ async def send(
133133
for event in events:
134134
_eventgrid_data_typecheck(event)
135135
await self._client.publish_events(
136-
self._topic_hostname,
136+
self._endpoint,
137137
cast(List[InternalEventGridEvent], events),
138138
**kwargs
139139
)
140140
elif all(isinstance(e, CustomEvent) for e in events):
141141
serialized_events = [dict(e) for e in events] # type: ignore
142142
await self._client.publish_custom_event_events(
143-
self._topic_hostname,
143+
self._endpoint,
144144
cast(List, serialized_events),
145145
**kwargs
146146
)

sdk/eventgrid/azure-eventgrid/migration_guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cloud_event = {
6363

6464
| In v1.3 | Equivalent in v2.0 | Sample |
6565
|---|---|---|
66-
|`EventGridClient(credentials)`|`EventGridPublisherClient(topic_hostname, credential)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py)|
66+
|`EventGridClient(credentials)`|`EventGridPublisherClient(endpoint, credential)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py)|
6767

6868
* Additionally, we now have an `EventGridDeserializer` that should be used to deserialize the events. This class is used only to decode data into a `CloudEvent` or an `EventGridEvent`. Hence, there are no credentials required to construct this as shown below.
6969

@@ -79,7 +79,7 @@ The `publish_events` API is replaced with `send` in v2.0. Additionally, `send` A
7979

8080
| In v1.3 | Equivalent in v2.0 | Sample |
8181
|---|---|---|
82-
|`EventGridClient(credentials).publish_events(topic_hostname, events)`|`EventGridPublisherClient(topic_hostname, credential).send(events)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py)|
82+
|`EventGridClient(credentials).publish_events(topic_hostname, events)`|`EventGridPublisherClient(endpoint, credential).send(events)`|[Sample for client construction](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py)|
8383

8484
### Consuming Events
8585

sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1_publish_custom_events_to_a_topic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
from azure.core.credentials import AzureKeyCredential
2020

2121
topic_key = os.environ["EG_ACCESS_KEY"]
22-
topic_hostname = os.environ["EG_TOPIC_HOSTNAME"]
22+
endpoint = os.environ["EG_TOPIC_HOSTNAME"]
2323

2424
credential = AzureKeyCredential(topic_key)
25-
client = EventGridPublisherClient(topic_hostname, credential)
25+
client = EventGridPublisherClient(endpoint, credential)
2626

2727
client.send([
2828
EventGridEvent(

sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs1b_publish_custom_events_to_a_topic_with_signature.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
from datetime import datetime, timedelta
2121

2222
topic_key = os.environ["EG_ACCESS_KEY"]
23-
topic_hostname = os.environ["EG_TOPIC_HOSTNAME"]
23+
endpoint = os.environ["EG_TOPIC_HOSTNAME"]
2424
expiration_date_utc = datetime.utcnow() + timedelta(hours=1)
2525

26-
signature = generate_shared_access_signature(topic_hostname, topic_key, expiration_date_utc)
26+
signature = generate_shared_access_signature(endpoint, topic_key, expiration_date_utc)
2727
credential = AzureSasCredential(signature)
28-
client = EventGridPublisherClient(topic_hostname, credential)
28+
client = EventGridPublisherClient(endpoint, credential)
2929

3030
client.send([
3131
EventGridEvent(

sdk/eventgrid/azure-eventgrid/samples/champion_scenarios/cs5_publish_events_using_cloud_events_1.0_schema.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
from azure.core.credentials import AzureKeyCredential
2020

2121
topic_key = os.environ["CLOUD_ACCESS_KEY"]
22-
topic_hostname = os.environ["CLOUD_TOPIC_HOSTNAME"]
22+
endpoint = os.environ["CLOUD_TOPIC_HOSTNAME"]
2323

2424
credential = AzureKeyCredential(topic_key)
25-
client = EventGridPublisherClient(topic_hostname, credential)
25+
client = EventGridPublisherClient(endpoint, credential)
2626

2727
client.send([
2828
CloudEvent(

0 commit comments

Comments
 (0)