Skip to content

Commit 4c3f329

Browse files
Updated config to take proxy configuration from env vars
1 parent a148edd commit 4c3f329

2 files changed

Lines changed: 50 additions & 5 deletions

File tree

src/conductor/asyncio_client/configuration/configuration.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
import logging
45
import os
56
from typing import Any, Dict, Optional, Union
@@ -94,8 +95,20 @@ def __init__(
9495
Default polling interval for workers in seconds.
9596
default_domain : str, optional
9697
Default domain for workers.
98+
proxy : str, optional
99+
Proxy URL for HTTP requests. If not provided, reads from CONDUCTOR_PROXY env var.
100+
proxy_headers : Dict[str, str], optional
101+
Headers to send with proxy requests. If not provided, reads from CONDUCTOR_PROXY_HEADERS env var.
97102
**kwargs : Any
98103
Additional parameters passed to HttpConfiguration.
104+
105+
Environment Variables:
106+
---------------------
107+
CONDUCTOR_SERVER_URL: Server URL (e.g., http://localhost:8080/api)
108+
CONDUCTOR_AUTH_KEY: Authentication key ID
109+
CONDUCTOR_AUTH_SECRET: Authentication key secret
110+
CONDUCTOR_PROXY: Proxy URL for HTTP requests
111+
CONDUCTOR_PROXY_HEADERS: Proxy headers as JSON string or single header value
99112
"""
100113

101114
# Resolve server URL from parameter or environment variable
@@ -139,8 +152,18 @@ def __init__(
139152
if self.__ui_host is None:
140153
self.__ui_host = self.server_url.replace("/api", "")
141154

142-
self.proxy = proxy
155+
# Proxy configuration - can be set via parameter or environment variable
156+
self.proxy = proxy or os.getenv("CONDUCTOR_PROXY")
157+
# Proxy headers - can be set via parameter or environment variable
143158
self.proxy_headers = proxy_headers
159+
if not self.proxy_headers and os.getenv("CONDUCTOR_PROXY_HEADERS"):
160+
try:
161+
self.proxy_headers = json.loads(os.getenv("CONDUCTOR_PROXY_HEADERS"))
162+
except (json.JSONDecodeError, TypeError):
163+
# If JSON parsing fails, treat as a single header value
164+
self.proxy_headers = {
165+
"Authorization": os.getenv("CONDUCTOR_PROXY_HEADERS")
166+
}
144167

145168
self.logger_format = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"
146169

@@ -164,6 +187,12 @@ def __init__(
164187
**kwargs,
165188
)
166189

190+
# Set proxy configuration on the HTTP config
191+
if self.proxy:
192+
self._http_config.proxy = self.proxy
193+
if self.proxy_headers:
194+
self._http_config.proxy_headers = self.proxy_headers
195+
167196
# Debug switch and logging setup
168197
self.__debug = debug
169198
if self.__debug:

src/conductor/client/configuration/configuration.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
import logging
45
import os
56
import time
@@ -25,7 +26,7 @@ def __init__(
2526
):
2627
"""
2728
Initialize Conductor client configuration.
28-
29+
2930
Args:
3031
base_url: Base URL of the Conductor server (will append /api)
3132
debug: Enable debug logging
@@ -34,6 +35,13 @@ def __init__(
3435
auth_token_ttl_min: Authentication token time-to-live in minutes
3536
proxy: Proxy URL for HTTP requests (supports http, https, socks4, socks5)
3637
proxy_headers: Headers to send with proxy requests (e.g., authentication)
38+
39+
Environment Variables:
40+
CONDUCTOR_SERVER_URL: Server URL (e.g., http://localhost:8080/api)
41+
CONDUCTOR_AUTH_KEY: Authentication key ID
42+
CONDUCTOR_AUTH_SECRET: Authentication key secret
43+
CONDUCTOR_PROXY: Proxy URL for HTTP requests
44+
CONDUCTOR_PROXY_HEADERS: Proxy headers as JSON string or single header value
3745
"""
3846
if server_api_url is not None:
3947
self.host = server_api_url
@@ -81,10 +89,18 @@ def __init__(
8189
# Set this to True/False to enable/disable SSL hostname verification.
8290
self.assert_hostname = None
8391

84-
# Proxy URL
85-
self.proxy = proxy
86-
# Proxy headers
92+
# Proxy configuration - can be set via parameter or environment variable
93+
self.proxy = proxy or os.getenv("CONDUCTOR_PROXY")
94+
# Proxy headers - can be set via parameter or environment variable
8795
self.proxy_headers = proxy_headers
96+
if not self.proxy_headers and os.getenv("CONDUCTOR_PROXY_HEADERS"):
97+
try:
98+
self.proxy_headers = json.loads(os.getenv("CONDUCTOR_PROXY_HEADERS"))
99+
except (json.JSONDecodeError, TypeError):
100+
# If JSON parsing fails, treat as a single header value
101+
self.proxy_headers = {
102+
"Authorization": os.getenv("CONDUCTOR_PROXY_HEADERS")
103+
}
88104
# Safe chars for path_param
89105
self.safe_chars_for_path_param = ""
90106

0 commit comments

Comments
 (0)