Skip to content

Commit cb6bd6b

Browse files
committed
chore: add ca bundle discovery helper
1 parent 157a1e7 commit cb6bd6b

5 files changed

Lines changed: 33 additions & 18 deletions

File tree

packages/uipath-platform/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-platform"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
description = "HTTP client library for programmatic access to UiPath Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

packages/uipath-platform/src/uipath/platform/common/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ._execution_context import UiPathExecutionContext
1919
from ._external_application_service import ExternalApplicationService
2020
from ._folder_context import FolderContext, header_folder
21-
from ._http_config import get_httpx_client_kwargs
21+
from ._http_config import get_ca_bundle_path, get_httpx_client_kwargs
2222
from ._models import Endpoint, RequestSpec
2323
from ._service_url_overrides import inject_routing_headers, resolve_service_url
2424
from ._span_utils import UiPathSpan, _SpanUtils
@@ -92,6 +92,7 @@
9292
"Endpoint",
9393
"UiPathUrl",
9494
"user_agent_value",
95+
"get_ca_bundle_path",
9596
"get_httpx_client_kwargs",
9697
"resource_override",
9798
"header_folder",

packages/uipath-platform/src/uipath/platform/common/_http_config.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,40 @@ def expand_path(path):
1414
return path
1515

1616

17-
def create_ssl_context():
18-
# Try truststore first (system certificates)
17+
def get_ca_bundle_path() -> str | None:
18+
"""Resolve CA bundle path from environment variables.
19+
20+
Returns None if SSL verification is disabled via UIPATH_DISABLE_SSL_VERIFY.
21+
Otherwise returns the CA bundle path with priority:
22+
SSL_CERT_FILE > REQUESTS_CA_BUNDLE > certifi default.
23+
"""
24+
disable_ssl_env = os.environ.get("UIPATH_DISABLE_SSL_VERIFY", "").lower()
25+
if disable_ssl_env in ("1", "true", "yes", "on"):
26+
return None
27+
28+
import certifi
29+
30+
ssl_cert_file = expand_path(os.environ.get("SSL_CERT_FILE"))
31+
requests_ca_bundle = expand_path(os.environ.get("REQUESTS_CA_BUNDLE"))
32+
33+
return ssl_cert_file or requests_ca_bundle or certifi.where()
34+
35+
36+
def create_ssl_context(cafile: str):
37+
"""Create an SSL context for httpx clients.
38+
39+
Args:
40+
cafile: Path to the CA bundle file.
41+
"""
1942
try:
2043
import truststore
2144

2245
return truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
2346
except ImportError:
24-
# Fallback to manual certificate configuration
25-
import certifi
26-
27-
ssl_cert_file = expand_path(os.environ.get("SSL_CERT_FILE"))
28-
requests_ca_bundle = expand_path(os.environ.get("REQUESTS_CA_BUNDLE"))
2947
ssl_cert_dir = expand_path(os.environ.get("SSL_CERT_DIR"))
3048

3149
return ssl.create_default_context(
32-
cafile=ssl_cert_file or requests_ca_bundle or certifi.where(),
50+
cafile=cafile,
3351
capath=ssl_cert_dir,
3452
)
3553

@@ -44,13 +62,9 @@ def get_httpx_client_kwargs(
4462
Caller headers take priority on key conflicts.
4563
"""
4664
client_kwargs: Dict[str, Any] = {"follow_redirects": True, "timeout": 30.0}
47-
disable_ssl_env = os.environ.get("UIPATH_DISABLE_SSL_VERIFY", "").lower()
48-
disable_ssl_from_env = disable_ssl_env in ("1", "true", "yes", "on")
4965

50-
if disable_ssl_from_env:
51-
client_kwargs["verify"] = False
52-
else:
53-
client_kwargs["verify"] = create_ssl_context()
66+
ca_bundle = get_ca_bundle_path()
67+
client_kwargs["verify"] = create_ssl_context(ca_bundle) if ca_bundle else False
5468

5569
from ._config import UiPathConfig
5670
from .constants import HEADER_LICENSING_CONTEXT

packages/uipath-platform/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uipath/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)