From 002897fc9958998eacf31e50186b573ef6b47ef1 Mon Sep 17 00:00:00 2001 From: Grammy Jiang Date: Tue, 9 Jul 2024 21:33:48 +1000 Subject: [PATCH] Add the client cert and key support to HttpTransport --- sentry_sdk/transport.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/transport.py b/sentry_sdk/transport.py index 293dfc0e97..5120c1a5be 100644 --- a/sentry_sdk/transport.py +++ b/sentry_sdk/transport.py @@ -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"], ) @@ -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", @@ -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): @@ -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] @@ -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: