Skip to content

Commit 61a8ed5

Browse files
committed
pipe proxy override through connection and clients
1 parent 3f6834c commit 61a8ed5

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/databricks/sql/auth/thrift_http_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
import logging
33
import urllib.parse
4-
from typing import Dict, Union
4+
from typing import Dict, Optional, Union
55

66
import six
77
import thrift
@@ -31,6 +31,7 @@ def __init__(
3131
ssl_context=None,
3232
max_connections: int = 1,
3333
retry_policy: Union[DatabricksRetryPolicy, int] = 0,
34+
proxies: Optional[Dict[str, str]] = None,
3435
):
3536
if port is not None:
3637
warnings.warn(
@@ -60,8 +61,11 @@ def __init__(
6061
self.path = parsed.path
6162
if parsed.query:
6263
self.path += "?%s" % parsed.query
64+
65+
if proxies is None:
66+
proxies = urllib.request.getproxies()
6367
try:
64-
proxy = urllib.request.getproxies()[self.scheme]
68+
proxy = proxies[self.scheme]
6569
except KeyError:
6670
proxy = None
6771
else:

src/databricks/sql/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def read(self) -> Optional[OAuthToken]:
160160
STRUCT is returned as Dict[str, Any]
161161
ARRAY is returned as numpy.ndarray
162162
When False, complex types are returned as a strings. These are generally deserializable as JSON.
163+
:param proxies: An optional dictionary mapping protocol to the URL of the proxy.
163164
"""
164165

165166
# Internal arguments in **kwargs:
@@ -208,6 +209,7 @@ def read(self) -> Optional[OAuthToken]:
208209
self.port = kwargs.get("_port", 443)
209210
self.disable_pandas = kwargs.get("_disable_pandas", False)
210211
self.lz4_compression = kwargs.get("enable_query_result_lz4_compression", True)
212+
self.proxies = kwargs.get("proxies")
211213

212214
auth_provider = get_python_sql_connector_auth_provider(
213215
server_hostname, **kwargs
@@ -648,7 +650,7 @@ def _handle_staging_put(
648650
raise Error("Cannot perform PUT without specifying a local_file")
649651

650652
with open(local_file, "rb") as fh:
651-
r = requests.put(url=presigned_url, data=fh, headers=headers)
653+
r = requests.put(url=presigned_url, data=fh, headers=headers, proxies=self.connection.proxies)
652654

653655
# fmt: off
654656
# Design borrowed from: https://stackoverflow.com/a/2342589/5093960
@@ -682,7 +684,7 @@ def _handle_staging_get(
682684
if local_file is None:
683685
raise Error("Cannot perform GET without specifying a local_file")
684686

685-
r = requests.get(url=presigned_url, headers=headers)
687+
r = requests.get(url=presigned_url, headers=headers, proxies=self.connection.proxies)
686688

687689
# response.ok verifies the status code is not between 400-600.
688690
# Any 2xx or 3xx will evaluate r.ok == True
@@ -697,7 +699,7 @@ def _handle_staging_get(
697699
def _handle_staging_remove(self, presigned_url: str, headers: dict = None):
698700
"""Make an HTTP DELETE request to the presigned_url"""
699701

700-
r = requests.delete(url=presigned_url, headers=headers)
702+
r = requests.delete(url=presigned_url, headers=headers, proxies=self.connection.proxies)
701703

702704
if not r.ok:
703705
raise Error(

src/databricks/sql/thrift_backend.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import uuid
77
import threading
88
from ssl import CERT_NONE, CERT_REQUIRED, create_default_context
9-
from typing import List, Union
9+
from typing import List, Union, Optional, Dict
1010

1111
import pyarrow
1212
import thrift.transport.THttpClient
@@ -218,6 +218,9 @@ def __init__(
218218

219219
additional_transport_args["retry_policy"] = self.retry_policy
220220

221+
if "proxies" in kwargs:
222+
additional_transport_args["proxies"] = kwargs["proxies"]
223+
221224
self._transport = databricks.sql.auth.thrift_http_client.THttpClient(
222225
auth_provider=self._auth_provider,
223226
uri_or_host=uri,

0 commit comments

Comments
 (0)