- Notifications
You must be signed in to change notification settings - Fork126
[PECO-1857] Use SSL options with HTTPS connection pool#425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
646cb1d [PECO-1857] Use SSL options with HTTPS connection pool
kravets-levkoa7be4cc Some cleanup
kravets-levko6f224b3 Resolve circular dependencies
kravets-levko296b02f Update existing tests
kravets-levkoaf91cf0 Fix MyPy issues
kravets-levkod15d4f8 Fix `_tls_no_verify` handling
kravets-levko07989bc Add tests
kravets-levkoFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
41 changes: 25 additions & 16 deletionssrc/databricks/sql/auth/thrift_http_client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| import base64 | ||
| import logging | ||
| import urllib.parse | ||
| from typing import Dict, Union, Optional | ||
| import six | ||
| import thrift | ||
| import ssl | ||
| import warnings | ||
| from http.client import HTTPResponse | ||
| @@ -16,6 +14,9 @@ | ||
| from urllib3 import HTTPConnectionPool, HTTPSConnectionPool, ProxyManager | ||
| from urllib3.util import make_headers | ||
| from databricks.sql.auth.retry import CommandType, DatabricksRetryPolicy | ||
| from databricks.sql.types import SSLOptions | ||
| logger = logging.getLogger(__name__) | ||
| class THttpClient(thrift.transport.THttpClient.THttpClient): | ||
| @@ -25,13 +26,12 @@ def __init__( | ||
| uri_or_host, | ||
| port=None, | ||
| path=None, | ||
| ssl_options: Optional[SSLOptions] = None, | ||
| max_connections: int = 1, | ||
| retry_policy: Union[DatabricksRetryPolicy, int] = 0, | ||
| ): | ||
| self._ssl_options = ssl_options | ||
| if port is not None: | ||
| warnings.warn( | ||
| "Please use the THttpClient('http{s}://host:port/path') constructor", | ||
| @@ -48,13 +48,11 @@ def __init__( | ||
| self.scheme = parsed.scheme | ||
| assert self.scheme in ("http", "https") | ||
| if self.scheme == "https": | ||
| if self._ssl_options is not None: | ||
| # TODO: Not sure if those options are used anywhere - need to double-check | ||
kravets-levko marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| self.certfile = self._ssl_options.tls_client_cert_file | ||
| self.keyfile = self._ssl_options.tls_client_cert_key_file | ||
| self.context = self._ssl_options.create_ssl_context() | ||
| self.port = parsed.port | ||
| self.host = parsed.hostname | ||
| self.path = parsed.path | ||
| @@ -109,12 +107,23 @@ def startRetryTimer(self): | ||
| def open(self): | ||
| # self.__pool replaces the self.__http used by the original THttpClient | ||
| _pool_kwargs = {"maxsize": self.max_connections} | ||
| if self.scheme == "http": | ||
| pool_class = HTTPConnectionPool | ||
| elif self.scheme == "https": | ||
| pool_class = HTTPSConnectionPool | ||
| _pool_kwargs.update( | ||
| { | ||
| "cert_reqs": ssl.CERT_REQUIRED | ||
| if self._ssl_options.tls_verify | ||
| else ssl.CERT_NONE, | ||
| "ca_certs": self._ssl_options.tls_trusted_ca_file, | ||
| "cert_file": self._ssl_options.tls_client_cert_file, | ||
| "key_file": self._ssl_options.tls_client_cert_key_file, | ||
| "key_password": self._ssl_options.tls_client_cert_key_password, | ||
| } | ||
| ) | ||
| if self.using_proxy(): | ||
| proxy_manager = ProxyManager( | ||
18 changes: 16 additions & 2 deletionssrc/databricks/sql/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletionssrc/databricks/sql/cloudfetch/download_manager.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletionssrc/databricks/sql/cloudfetch/downloader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
43 changes: 6 additions & 37 deletionssrc/databricks/sql/thrift_backend.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletionssrc/databricks/sql/types.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.