Skip to content

Commit

Permalink
Add the client cert and key support to HttpTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
grammy-jiang committed Jul 9, 2024
1 parent 54b32f2 commit 002897f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sentry_sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ def __init__(
http_proxy=options["http_proxy"],
https_proxy=options["https_proxy"],
ca_certs=options["ca_certs"],
cert_file=options["cert_file"] if "cert_file" in options else None,
key_file=options["key_file"] if "key_file" in options else None,
proxy_headers=options["proxy_headers"],
)

Expand Down Expand Up @@ -450,8 +452,8 @@ def _send_envelope(
)
return None

def _get_pool_options(self, ca_certs):
# type: (Optional[Any]) -> Dict[str, Any]
def _get_pool_options(self, ca_certs, cert_file, key_file):
# type: (Optional[Any], Optional[Any], Optional[Any]) -> Dict[str, Any]
options = {
"num_pools": self._num_pools,
"cert_reqs": "CERT_REQUIRED",
Expand Down Expand Up @@ -481,6 +483,9 @@ def _get_pool_options(self, ca_certs):
or certifi.where()
)

options["cert_file"] = cert_file or os.environ.get("CLIENT_CERT_FILE")
options["key_file"] = key_file or os.environ.get("CLIENT_KEY_FILE")

return options

def _in_no_proxy(self, parsed_dsn):
Expand All @@ -500,6 +505,8 @@ def _make_pool(
http_proxy, # type: Optional[str]
https_proxy, # type: Optional[str]
ca_certs, # type: Optional[Any]
cert_file, # type: Optional[Any]
key_file, # type: Optional[Any]
proxy_headers, # type: Optional[Dict[str, str]]
):
# type: (...) -> Union[PoolManager, ProxyManager]
Expand All @@ -514,7 +521,7 @@ def _make_pool(
if not proxy and (http_proxy != ""):
proxy = http_proxy or (not no_proxy and getproxies().get("http"))

opts = self._get_pool_options(ca_certs)
opts = self._get_pool_options(ca_certs, cert_file, key_file)

if proxy:
if proxy_headers:
Expand Down

0 comments on commit 002897f

Please sign in to comment.