Skip to content

Commit a148edd

Browse files
Added proxy configuration
1 parent 99626eb commit a148edd

4 files changed

Lines changed: 76 additions & 23 deletions

File tree

src/conductor/asyncio_client/configuration/configuration.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def __init__(
7373
ssl_ca_cert: Optional[str] = None,
7474
retries: Optional[int] = None,
7575
ca_cert_data: Optional[Union[str, bytes]] = None,
76+
proxy: Optional[str] = None,
77+
proxy_headers: Optional[Dict[str, str]] = None,
7678
**kwargs: Any,
7779
):
7880
"""
@@ -137,6 +139,9 @@ def __init__(
137139
if self.__ui_host is None:
138140
self.__ui_host = self.server_url.replace("/api", "")
139141

142+
self.proxy = proxy
143+
self.proxy_headers = proxy_headers
144+
140145
self.logger_format = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"
141146

142147
# Create the underlying HTTP configuration

src/conductor/client/adapters/api_client_adapter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def __init__(
1616
"""Initialize the API client adapter with httpx-based REST client."""
1717
super().__init__(configuration, header_name, header_value, cookie)
1818
self.rest_client = RESTClientObjectAdapter(
19-
connection=configuration.http_connection if configuration else None
19+
connection=configuration.http_connection if configuration else None,
20+
configuration=configuration,
2021
)
2122

2223
def __call_api(

src/conductor/client/adapters/rest_adapter.py

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ def __init__(self, response: Response):
2323
self.reason = response.reason_phrase
2424
self.resp = response
2525
self.headers = response.headers
26-
26+
2727
# Log HTTP protocol version
28-
http_version = getattr(response, 'http_version', 'Unknown')
29-
logger.debug(f"HTTP response received - Status: {self.status}, Protocol: {http_version}")
30-
28+
http_version = getattr(response, "http_version", "Unknown")
29+
logger.debug(
30+
f"HTTP response received - Status: {self.status}, Protocol: {http_version}"
31+
)
32+
3133
# Log HTTP/2 usage
3234
if http_version == "HTTP/2":
3335
logger.info(f"HTTP/2 connection established - URL: {response.url}")
@@ -53,12 +55,12 @@ def data(self) -> bytes:
5355
def text(self) -> str:
5456
"""Get response data as text."""
5557
return self.resp.text
56-
58+
5759
@property
5860
def http_version(self) -> str:
5961
"""Get the HTTP protocol version used."""
60-
return getattr(self.resp, 'http_version', 'Unknown')
61-
62+
return getattr(self.resp, "http_version", "Unknown")
63+
6264
def is_http2(self) -> bool:
6365
"""Check if HTTP/2 was used for this response."""
6466
return self.http_version == "HTTP/2"
@@ -67,32 +69,61 @@ def is_http2(self) -> bool:
6769
class RESTClientObjectAdapter(RESTClientObject):
6870
"""HTTP client adapter using httpx instead of requests."""
6971

70-
def __init__(self, connection: Optional[httpx.Client] = None):
71-
"""Initialize the REST client with httpx."""
72-
# Don't call super().__init__() to avoid requests initialization
73-
self.connection = connection or httpx.Client(
74-
timeout=httpx.Timeout(120.0),
75-
follow_redirects=True,
76-
limits=httpx.Limits(max_keepalive_connections=20, max_connections=100),
77-
)
72+
def __init__(self, connection: Optional[httpx.Client] = None, configuration=None):
73+
"""
74+
Initialize the REST client with httpx.
75+
76+
Args:
77+
connection: Pre-configured httpx.Client instance. If provided,
78+
proxy settings from configuration will be ignored.
79+
configuration: Configuration object containing proxy settings.
80+
Expected attributes: proxy (str), proxy_headers (dict)
81+
"""
82+
if connection is not None:
83+
self.connection = connection
84+
else:
85+
client_kwargs = {
86+
"timeout": httpx.Timeout(120.0),
87+
"follow_redirects": True,
88+
"limits": httpx.Limits(
89+
max_keepalive_connections=20, max_connections=100
90+
),
91+
}
92+
93+
if (
94+
configuration
95+
and hasattr(configuration, "proxy")
96+
and configuration.proxy
97+
):
98+
client_kwargs["proxy"] = configuration.proxy
99+
if (
100+
configuration
101+
and hasattr(configuration, "proxy_headers")
102+
and configuration.proxy_headers
103+
):
104+
client_kwargs["proxy_headers"] = configuration.proxy_headers
105+
106+
self.connection = httpx.Client(**client_kwargs)
78107

79108
def close(self):
80109
"""Close the HTTP client connection."""
81110
if hasattr(self, "connection") and self.connection:
82111
self.connection.close()
83-
112+
84113
def check_http2_support(self, url: str) -> bool:
85114
"""Check if the server supports HTTP/2 by making a test request."""
86115
try:
87116
logger.info(f"Checking HTTP/2 support for: {url}")
88117
response = self.GET(url)
89118
is_http2 = response.is_http2()
90-
119+
91120
if is_http2:
92121
logger.info(f"✓ HTTP/2 supported by {url}")
93122
else:
94-
logger.info(f"✗ HTTP/2 not supported by {url}, using {response.http_version}")
95-
123+
logger.info(
124+
f"✗ HTTP/2 not supported by {url}, using {response.http_version}"
125+
)
126+
96127
return is_http2
97128
except Exception as e:
98129
logger.error(f"Failed to check HTTP/2 support for {url}: {e}")
@@ -151,7 +182,7 @@ def request(
151182
try:
152183
# Log the request attempt
153184
logger.debug(f"Making HTTP request - Method: {method}, URL: {url}")
154-
185+
155186
# Prepare request parameters
156187
request_kwargs = {
157188
"method": method,

src/conductor/client/configuration/configuration.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import os
55
import time
6-
from typing import Optional
6+
from typing import Optional, Dict
77

88
from conductor.shared.configuration.settings.authentication_settings import (
99
AuthenticationSettings,
@@ -20,7 +20,21 @@ def __init__(
2020
authentication_settings: AuthenticationSettings = None,
2121
server_api_url: Optional[str] = None,
2222
auth_token_ttl_min: int = 45,
23+
proxy: Optional[str] = None,
24+
proxy_headers: Optional[Dict[str, str]] = None,
2325
):
26+
"""
27+
Initialize Conductor client configuration.
28+
29+
Args:
30+
base_url: Base URL of the Conductor server (will append /api)
31+
debug: Enable debug logging
32+
authentication_settings: Authentication configuration for Orkes
33+
server_api_url: Full API URL (overrides base_url)
34+
auth_token_ttl_min: Authentication token time-to-live in minutes
35+
proxy: Proxy URL for HTTP requests (supports http, https, socks4, socks5)
36+
proxy_headers: Headers to send with proxy requests (e.g., authentication)
37+
"""
2438
if server_api_url is not None:
2539
self.host = server_api_url
2640
elif base_url is not None:
@@ -68,7 +82,9 @@ def __init__(
6882
self.assert_hostname = None
6983

7084
# Proxy URL
71-
self.proxy = None
85+
self.proxy = proxy
86+
# Proxy headers
87+
self.proxy_headers = proxy_headers
7288
# Safe chars for path_param
7389
self.safe_chars_for_path_param = ""
7490

0 commit comments

Comments
 (0)