Skip to content

Commit 35e1a67

Browse files
committed
Added HTTP proxy support
Fix for issue Azure#41
1 parent 62c8e83 commit 35e1a67

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

azure/eventhub/_async/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ def _create_auth(self, username=None, password=None): # pylint: disable=no-self
5555
username = username or self._auth_config['username']
5656
password = password or self._auth_config['password']
5757
if "@sas.root" in username:
58-
return authentication.SASLPlain(self.address.hostname, username, password)
59-
return authentication.SASTokenAsync.from_shared_access_key(self.auth_uri, username, password, timeout=60)
58+
return authentication.SASLPlain(
59+
self.address.hostname, username, password, http_proxy=self.http_proxy)
60+
return authentication.SASTokenAsync.from_shared_access_key(
61+
self.auth_uri, username, password, timeout=60, http_proxy=self.http_proxy)
6062

6163
async def _close_clients_async(self):
6264
"""

azure/eventhub/client.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class EventHubClient(object):
8989
events to and receiving events from the Azure Event Hubs service.
9090
"""
9191

92-
def __init__(self, address, username=None, password=None, debug=False):
92+
def __init__(self, address, username=None, password=None, debug=False, http_proxy=None):
9393
"""
9494
Constructs a new EventHubClient with the given address URL.
9595
@@ -105,10 +105,15 @@ def __init__(self, address, username=None, password=None, debug=False):
105105
:param debug: Whether to output network trace logs to the logger. Default
106106
is `False`.
107107
:type debug: bool
108+
:param http_proxy: HTTP proxy settings. This must be a dictionary with the following
109+
keys: 'proxy_hostname' (str value) and 'proxy_port' (int value).
110+
Additionally the following keys may also be present: 'username', 'password'.
111+
:type http_proxy: dict[str, Any]
108112
"""
109113
self.container_id = "eventhub.pysdk-" + str(uuid.uuid4())[:8]
110114
self.address = urlparse(address)
111115
self.eh_name = self.address.path.lstrip('/')
116+
self.http_proxy = http_proxy
112117
self.mgmt_target = "amqps://{}/{}".format(self.address.hostname, self.eh_name)
113118
url_username = unquote_plus(self.address.username) if self.address.username else None
114119
username = username or url_username
@@ -169,8 +174,10 @@ def _create_auth(self, username=None, password=None):
169174
username = username or self._auth_config['username']
170175
password = password or self._auth_config['password']
171176
if "@sas.root" in username:
172-
return authentication.SASLPlain(self.address.hostname, username, password)
173-
return authentication.SASTokenAuth.from_shared_access_key(self.auth_uri, username, password, timeout=60)
177+
return authentication.SASLPlain(
178+
self.address.hostname, username, password, http_proxy=self.http_proxy)
179+
return authentication.SASTokenAuth.from_shared_access_key(
180+
self.auth_uri, username, password, timeout=60, http_proxy=self.http_proxy)
174181

175182
def create_properties(self): # pylint: disable=no-self-use
176183
"""

azure/eventprocessorhost/eh_partition_pump.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ async def open_clients_async(self):
6666
# Create event hub client and receive handler and set options
6767
self.eh_client = EventHubClientAsync(
6868
self.host.eh_config.client_address,
69-
debug=self.host.eph_options.debug_trace)
69+
debug=self.host.eph_options.debug_trace,
70+
http_proxy=self.host.eph_options.http_proxy)
7071
self.partition_receive_handler = self.eh_client.add_async_receiver(
7172
self.partition_context.consumer_group_name,
7273
self.partition_context.partition_id,

azure/eventprocessorhost/eph.py

+1
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ def __init__(self):
7373
self.release_pump_on_timeout = False
7474
self.initial_offset_provider = "-1"
7575
self.debug_trace = False
76+
self.http_proxy = None

azure/eventprocessorhost/partition_manager.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ async def get_partition_ids_async(self):
3838
try:
3939
eh_client = EventHubClientAsync(
4040
self.host.eh_config.client_address,
41-
debug=self.host.eph_options.debug_trace)
41+
debug=self.host.eph_options.debug_trace,
42+
http_proxy=self.host.eph_options.http_proxy)
4243
try:
4344
eh_info = await eh_client.get_eventhub_info_async()
4445
self.partition_ids = eh_info['partition_ids']

0 commit comments

Comments
 (0)