Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Added HTTP proxy support
Browse files Browse the repository at this point in the history
Fix for issue #41
  • Loading branch information
annatisch committed Jul 26, 2018
1 parent 62c8e83 commit 35e1a67
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
6 changes: 4 additions & 2 deletions azure/eventhub/_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ def _create_auth(self, username=None, password=None): # pylint: disable=no-self
username = username or self._auth_config['username']
password = password or self._auth_config['password']
if "@sas.root" in username:
return authentication.SASLPlain(self.address.hostname, username, password)
return authentication.SASTokenAsync.from_shared_access_key(self.auth_uri, username, password, timeout=60)
return authentication.SASLPlain(
self.address.hostname, username, password, http_proxy=self.http_proxy)
return authentication.SASTokenAsync.from_shared_access_key(
self.auth_uri, username, password, timeout=60, http_proxy=self.http_proxy)

async def _close_clients_async(self):
"""
Expand Down
13 changes: 10 additions & 3 deletions azure/eventhub/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class EventHubClient(object):
events to and receiving events from the Azure Event Hubs service.
"""

def __init__(self, address, username=None, password=None, debug=False):
def __init__(self, address, username=None, password=None, debug=False, http_proxy=None):
"""
Constructs a new EventHubClient with the given address URL.
Expand All @@ -105,10 +105,15 @@ def __init__(self, address, username=None, password=None, debug=False):
:param debug: Whether to output network trace logs to the logger. Default
is `False`.
:type debug: bool
:param http_proxy: HTTP proxy settings. This must be a dictionary with the following
keys: 'proxy_hostname' (str value) and 'proxy_port' (int value).
Additionally the following keys may also be present: 'username', 'password'.
:type http_proxy: dict[str, Any]
"""
self.container_id = "eventhub.pysdk-" + str(uuid.uuid4())[:8]
self.address = urlparse(address)
self.eh_name = self.address.path.lstrip('/')
self.http_proxy = http_proxy
self.mgmt_target = "amqps://{}/{}".format(self.address.hostname, self.eh_name)
url_username = unquote_plus(self.address.username) if self.address.username else None
username = username or url_username
Expand Down Expand Up @@ -169,8 +174,10 @@ def _create_auth(self, username=None, password=None):
username = username or self._auth_config['username']
password = password or self._auth_config['password']
if "@sas.root" in username:
return authentication.SASLPlain(self.address.hostname, username, password)
return authentication.SASTokenAuth.from_shared_access_key(self.auth_uri, username, password, timeout=60)
return authentication.SASLPlain(
self.address.hostname, username, password, http_proxy=self.http_proxy)
return authentication.SASTokenAuth.from_shared_access_key(
self.auth_uri, username, password, timeout=60, http_proxy=self.http_proxy)

def create_properties(self): # pylint: disable=no-self-use
"""
Expand Down
3 changes: 2 additions & 1 deletion azure/eventprocessorhost/eh_partition_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ async def open_clients_async(self):
# Create event hub client and receive handler and set options
self.eh_client = EventHubClientAsync(
self.host.eh_config.client_address,
debug=self.host.eph_options.debug_trace)
debug=self.host.eph_options.debug_trace,
http_proxy=self.host.eph_options.http_proxy)
self.partition_receive_handler = self.eh_client.add_async_receiver(
self.partition_context.consumer_group_name,
self.partition_context.partition_id,
Expand Down
1 change: 1 addition & 0 deletions azure/eventprocessorhost/eph.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ def __init__(self):
self.release_pump_on_timeout = False
self.initial_offset_provider = "-1"
self.debug_trace = False
self.http_proxy = None
3 changes: 2 additions & 1 deletion azure/eventprocessorhost/partition_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async def get_partition_ids_async(self):
try:
eh_client = EventHubClientAsync(
self.host.eh_config.client_address,
debug=self.host.eph_options.debug_trace)
debug=self.host.eph_options.debug_trace,
http_proxy=self.host.eph_options.http_proxy)
try:
eh_info = await eh_client.get_eventhub_info_async()
self.partition_ids = eh_info['partition_ids']
Expand Down

0 comments on commit 35e1a67

Please sign in to comment.