Files
PY_PROXY/config.py
Jonatan Rek f601bb3fc8 Progress
2026-03-02 12:16:00 +01:00

32 lines
1.0 KiB
Python

from dataclasses import dataclass, field
import yaml
@dataclass
class ProxyRoute:
domain: str
target_host: str
target_port: int
containers: list[str] = field(default_factory=list)
timeout_seconds: int = 0 # idle timeout before stopping container (0 = never)
load_seconds: int = 0 # seconds to wait after starting container
def load_config(path: str) -> dict[str, ProxyRoute]:
"""Parse config.yml and return dict of domain -> ProxyRoute."""
with open(path) as f:
data = yaml.safe_load(f)
routes: dict[str, ProxyRoute] = {}
for h in data.get('proxy_hosts', []):
containers = [c['container_name'] for c in h.get('containers', [])]
route = ProxyRoute(
domain=h['domain'],
target_host=h['proxy_host'],
target_port=h['proxy_port'],
containers=containers,
timeout_seconds=h.get('proxy_timeout_seconds', 0),
load_seconds=h.get('proxy_load_seconds', 0),
)
routes[route.domain] = route
return routes