Skip to content

Commit 5771ed1

Browse files
authored
[SB/EH] comment custom endpoint doc (#38516)
* start * custom endpoint over amqp * fix * config * doc * eventhub fix * mypy * custom port 2 * why blakc rynning here ok?
1 parent d9db4dd commit 5771ed1

File tree

24 files changed

+84
-15
lines changed

24 files changed

+84
-15
lines changed

sdk/eventhub/azure-eventhub-checkpointstoreblob-aio/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pylint = true
77
latestdependency = false
88
mindependency = false
99
whl_no_aio = false
10+
black = false

sdk/eventhub/azure-eventhub-checkpointstoreblob/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pyright = false
44
type_check_samples = false
55
verifytypes = false
66
pylint = true
7+
black = false

sdk/eventhub/azure-eventhub-checkpointstoretable/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pyright = false
44
type_check_samples = false
55
verifytypes = false
66
pylint = false
7+
black = false

sdk/eventhub/azure-eventhub/azure/eventhub/_configuration.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(
2929
retry_backoff_max: int = 120,
3030
network_tracing: bool = False,
3131
http_proxy: Optional[Dict[str, Any]] = None,
32-
transport_type: TransportType = TransportType.Amqp,
32+
transport_type: Optional[TransportType] = None,
3333
auth_timeout: int = 60,
3434
prefetch: int = 300,
3535
max_batch_size: int = 300,
@@ -50,6 +50,8 @@ def __init__(
5050
self.network_tracing = network_tracing
5151
self.http_proxy = http_proxy
5252
self.transport_type = TransportType.AmqpOverWebsocket if self.http_proxy else transport_type
53+
# if transport_type is not provided, it is None, we will default to Amqp
54+
self.transport_type = self.transport_type or TransportType.Amqp
5355
self.auth_timeout = auth_timeout
5456
self.prefetch = prefetch
5557
self.max_batch_size = max_batch_size
@@ -81,9 +83,12 @@ def __init__(
8183
if self.custom_endpoint_address.find("//") == -1:
8284
self.custom_endpoint_address = "sb://" + self.custom_endpoint_address
8385
endpoint = urlparse(self.custom_endpoint_address)
84-
self.transport_type = TransportType.AmqpOverWebsocket
86+
# this line is to maintain backward compatibility for custom endpoint
87+
# if the transport_type is not provided, we will default to AmqpOverWebsocket
88+
self.transport_type = transport_type or TransportType.AmqpOverWebsocket
8589
self.custom_endpoint_hostname = endpoint.hostname
8690
if amqp_transport.KIND == "pyamqp":
91+
# if transport is amqp, we will not append this path to the final endpoint
8792
self.custom_endpoint_address += "/$servicebus/websocket"
8893
# in case proxy and custom endpoint are both provided, we default port to 443 if it's not provided
8994
self.connection_port = endpoint.port or DEFAULT_AMQP_WSS_PORT

sdk/eventhub/azure-eventhub/azure/eventhub/_consumer_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class EventHubConsumerClient(ClientBase): # pylint: disable=client-accepts-api-
116116
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
117117
the Event Hubs service, allowing network requests to be routed through any application gateways or
118118
other paths needed for the host environment. Default is None.
119+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
119120
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
120121
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
121122
:paramtype custom_endpoint_address: str or None
@@ -307,6 +308,7 @@ def from_connection_string(
307308
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
308309
the Event Hubs service, allowing network requests to be routed through any application gateways or
309310
other paths needed for the host environment. Default is None.
311+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
310312
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
311313
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
312314
:paramtype custom_endpoint_address: str or None

sdk/eventhub/azure-eventhub/azure/eventhub/_producer_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class EventHubProducerClient(ClientBase): # pylint: disable=client-accepts-api-
122122
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
123123
the Event Hubs service, allowing network requests to be routed through any application gateways or
124124
other paths needed for the host environment. Default is None.
125+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
125126
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
126127
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
127128
:paramtype custom_endpoint_address: Optional[str]
@@ -504,6 +505,7 @@ def from_connection_string(
504505
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
505506
the Event Hubs service, allowing network requests to be routed through any application gateways or
506507
other paths needed for the host environment. Default is None.
508+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
507509
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
508510
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
509511
:paramtype custom_endpoint_address: Optional[str]

sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/_connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,15 @@ def __init__( # pylint:disable=too-many-locals,too-many-statements
134134
# Custom Endpoint
135135
custom_endpoint_address = kwargs.get("custom_endpoint_address")
136136
custom_endpoint = None
137+
custom_port = None
137138
if custom_endpoint_address:
138139
custom_parsed_url = urlparse(custom_endpoint_address)
139-
custom_port = custom_parsed_url.port or WEBSOCKET_PORT
140-
custom_endpoint = f"{custom_parsed_url.hostname}:{custom_port}{custom_parsed_url.path}"
140+
if transport_type.value == TransportType.Amqp.value:
141+
custom_port = custom_parsed_url.port or SECURE_PORT
142+
custom_endpoint = f"{custom_parsed_url.hostname}"
143+
else:
144+
custom_port = custom_parsed_url.port or WEBSOCKET_PORT
145+
custom_endpoint = f"{custom_parsed_url.hostname}:{custom_port}{custom_parsed_url.path}"
141146
self._container_id = container_id or str(uuid.uuid4())
142147
self._network_trace = network_trace
143148
self._network_trace_params = {"amqpConnection": self._container_id, "amqpSession": "", "amqpLink": ""}
@@ -163,6 +168,7 @@ def __init__( # pylint:disable=too-many-locals,too-many-statements
163168
credential=kwargs["sasl_credential"],
164169
port=self._port,
165170
custom_endpoint=custom_endpoint,
171+
custom_port=custom_port,
166172
socket_timeout=self._socket_timeout,
167173
network_trace_params=self._network_trace_params,
168174
**kwargs,

sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/_transport.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,13 @@ class SSLTransport(_AbstractTransport):
491491

492492
def __init__(self, host, *, port=AMQPS_PORT, socket_timeout=None, ssl_opts=None, **kwargs):
493493
self.sslopts = ssl_opts if isinstance(ssl_opts, dict) else {}
494-
self.sslopts["server_hostname"] = host
494+
self._custom_endpoint = kwargs.get("custom_endpoint")
495+
self._custom_port = kwargs.get("custom_port")
496+
self.sslopts["server_hostname"] = self._custom_endpoint or host
495497
self._read_buffer = BytesIO()
496-
super(SSLTransport, self).__init__(host, port=port, socket_timeout=socket_timeout, **kwargs)
498+
super(SSLTransport, self).__init__(
499+
self._custom_endpoint or host, port=self._custom_port or port, socket_timeout=socket_timeout, **kwargs
500+
)
497501

498502
def _setup_transport(self):
499503
"""Wrap the socket in an SSL object."""

sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/aio/_client_async.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class AMQPClientAsync(AMQPClientSync):
122122
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
123123
the Event Hubs service, allowing network requests to be routed through any application gateways or
124124
other paths needed for the host environment. Default is None.
125+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
125126
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
126127
:paramtype custom_endpoint_address: str
127128
:keyword connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to
@@ -478,6 +479,7 @@ class SendClientAsync(SendClientSync, AMQPClientAsync):
478479
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
479480
the Event Hubs service, allowing network requests to be routed through any application gateways or
480481
other paths needed for the host environment. Default is None.
482+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
481483
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
482484
:paramtype custom_endpoint_address: str
483485
:keyword connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to
@@ -686,6 +688,7 @@ class ReceiveClientAsync(ReceiveClientSync, AMQPClientAsync):
686688
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
687689
the Event Hubs service, allowing network requests to be routed through any application gateways or
688690
other paths needed for the host environment. Default is None.
691+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
689692
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
690693
:paramtype custom_endpoint_address: str
691694
:keyword connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to

sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/aio/_connection_async.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,15 @@ def __init__( # pylint:disable=too-many-locals,too-many-statements
115115
# Custom Endpoint
116116
custom_endpoint_address = kwargs.get("custom_endpoint_address")
117117
custom_endpoint = None
118+
custom_port = None
118119
if custom_endpoint_address:
119120
custom_parsed_url = urlparse(custom_endpoint_address)
120-
custom_port = custom_parsed_url.port or WEBSOCKET_PORT
121-
custom_endpoint = f"{custom_parsed_url.hostname}:{custom_port}{custom_parsed_url.path}"
121+
if transport_type.value == TransportType.Amqp.value:
122+
custom_port = custom_parsed_url.port or SECURE_PORT
123+
custom_endpoint = f"{custom_parsed_url.hostname}"
124+
else:
125+
custom_port = custom_parsed_url.port or WEBSOCKET_PORT
126+
custom_endpoint = f"{custom_parsed_url.hostname}:{custom_port}{custom_parsed_url.path}"
122127
self._container_id: str = container_id or str(uuid.uuid4())
123128
self._network_trace = network_trace
124129
self._network_trace_params = {"amqpConnection": self._container_id, "amqpSession": "", "amqpLink": ""}
@@ -145,6 +150,7 @@ def __init__( # pylint:disable=too-many-locals,too-many-statements
145150
credential=kwargs["sasl_credential"],
146151
port=self._port,
147152
custom_endpoint=custom_endpoint,
153+
custom_port=custom_port,
148154
socket_timeout=self._socket_timeout,
149155
network_trace_params=self._network_trace_params,
150156
**kwargs,

sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/aio/_transport_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ def __init__(
226226
self.raise_on_initial_eintr = raise_on_initial_eintr
227227
self._read_buffer = BytesIO()
228228
self.host, self.port = to_host_port(host, port)
229+
self.host = kwargs.get("custom_endpoint") or self.host
230+
self.port = kwargs.get("custom_port") or self.port
229231
self.socket_settings = socket_settings
230232
self.socket_lock = asyncio.Lock()
231233
self.sslopts = ssl_opts

sdk/eventhub/azure-eventhub/azure/eventhub/_pyamqp/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class AMQPClient(object): # pylint: disable=too-many-instance-attributes
140140
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
141141
the service, allowing network requests to be routed through any application gateways or
142142
other paths needed for the host environment. Default is None.
143+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
143144
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
144145
:paramtype custom_endpoint_address: str
145146
:keyword connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to
@@ -561,6 +562,7 @@ class SendClient(AMQPClient):
561562
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
562563
the service, allowing network requests to be routed through any application gateways or
563564
other paths needed for the host environment. Default is None.
565+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
564566
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
565567
:paramtype custom_endpoint_address: str
566568
:keyword connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to
@@ -786,6 +788,7 @@ class ReceiveClient(AMQPClient): # pylint:disable=too-many-instance-attributes
786788
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
787789
the service, allowing network requests to be routed through any application gateways or
788790
other paths needed for the host environment. Default is None.
791+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
789792
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
790793
:paramtype custom_endpoint_address: str
791794
:keyword connection_verify: Path to the custom CA_BUNDLE file of the SSL certificate which is used to

sdk/eventhub/azure-eventhub/azure/eventhub/aio/_consumer_client_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class EventHubConsumerClient(ClientBaseAsync): # pylint: disable=client-accepts
128128
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
129129
the Event Hubs service, allowing network requests to be routed through any application gateways or
130130
other paths needed for the host environment. Default is None.
131+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
131132
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
132133
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
133134
:paramtype custom_endpoint_address: Optional[str]
@@ -319,6 +320,7 @@ def from_connection_string(
319320
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
320321
the Event Hubs service, allowing network requests to be routed through any application gateways or
321322
other paths needed for the host environment. Default is None.
323+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
322324
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
323325
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
324326
:paramtype custom_endpoint_address: Optional[str]

sdk/eventhub/azure-eventhub/azure/eventhub/aio/_producer_client_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class EventHubProducerClient(ClientBaseAsync): # pylint: disable=client-accepts
109109
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
110110
the Event Hubs service, allowing network requests to be routed through any application gateways or
111111
other paths needed for the host environment. Default is None.
112+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
112113
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
113114
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
114115
:paramtype custom_endpoint_address: Optional[str]
@@ -471,6 +472,7 @@ def from_connection_string(
471472
:keyword custom_endpoint_address: The custom endpoint address to use for establishing a connection to
472473
the Event Hubs service, allowing network requests to be routed through any application gateways or
473474
other paths needed for the host environment. Default is None.
475+
Unless specified otherwise, default transport type is TransportType.AmqpOverWebsockets.
474476
The format would be like "sb://<custom_endpoint_hostname>:<custom_endpoint_port>".
475477
If port is not specified in the `custom_endpoint_address`, by default port 443 will be used.
476478
:paramtype custom_endpoint_address: Optional[str]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[tool.azure-sdk-build]
22
breaking = false
3+
black = false

sdk/servicebus/azure-servicebus/azure/servicebus/_common/_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, **kwargs):
5959
if self.custom_endpoint_address.find("//") == -1:
6060
self.custom_endpoint_address = "sb://" + self.custom_endpoint_address
6161
endpoint = urlparse(self.custom_endpoint_address)
62-
self.transport_type = TransportType.AmqpOverWebsocket
62+
self.transport_type = kwargs.get("transport_type") or TransportType.AmqpOverWebsocket
6363
self.custom_endpoint_hostname = endpoint.hostname
6464
if amqp_transport.KIND == "pyamqp":
6565
self.custom_endpoint_address += "/$servicebus/websocket"

sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,15 @@ def __init__( # pylint:disable=too-many-locals,too-many-statements
134134
# Custom Endpoint
135135
custom_endpoint_address = kwargs.get("custom_endpoint_address")
136136
custom_endpoint = None
137+
custom_port = None
137138
if custom_endpoint_address:
138139
custom_parsed_url = urlparse(custom_endpoint_address)
139-
custom_port = custom_parsed_url.port or WEBSOCKET_PORT
140-
custom_endpoint = f"{custom_parsed_url.hostname}:{custom_port}{custom_parsed_url.path}"
140+
if transport_type.value == TransportType.Amqp.value:
141+
custom_port = custom_parsed_url.port or SECURE_PORT
142+
custom_endpoint = f"{custom_parsed_url.hostname}"
143+
else:
144+
custom_port = custom_parsed_url.port or WEBSOCKET_PORT
145+
custom_endpoint = f"{custom_parsed_url.hostname}:{custom_port}{custom_parsed_url.path}"
141146
self._container_id = container_id or str(uuid.uuid4())
142147
self._network_trace = network_trace
143148
self._network_trace_params = {"amqpConnection": self._container_id, "amqpSession": "", "amqpLink": ""}
@@ -163,6 +168,7 @@ def __init__( # pylint:disable=too-many-locals,too-many-statements
163168
credential=kwargs["sasl_credential"],
164169
port=self._port,
165170
custom_endpoint=custom_endpoint,
171+
custom_port=custom_port,
166172
socket_timeout=self._socket_timeout,
167173
network_trace_params=self._network_trace_params,
168174
**kwargs,

sdk/servicebus/azure-servicebus/azure/servicebus/_pyamqp/_transport.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,13 @@ class SSLTransport(_AbstractTransport):
491491

492492
def __init__(self, host, *, port=AMQPS_PORT, socket_timeout=None, ssl_opts=None, **kwargs):
493493
self.sslopts = ssl_opts if isinstance(ssl_opts, dict) else {}
494-
self.sslopts["server_hostname"] = host
494+
self._custom_endpoint = kwargs.get("custom_endpoint")
495+
self._custom_port = kwargs.get("custom_port")
496+
self.sslopts["server_hostname"] = self._custom_endpoint or host
495497
self._read_buffer = BytesIO()
496-
super(SSLTransport, self).__init__(host, port=port, socket_timeout=socket_timeout, **kwargs)
498+
super(SSLTransport, self).__init__(
499+
self._custom_endpoint or host, port=self._custom_port or port, socket_timeout=socket_timeout, **kwargs
500+
)
497501

498502
def _setup_transport(self):
499503
"""Wrap the socket in an SSL object."""

0 commit comments

Comments
 (0)