"""Configuration loader for the Farm Manager server. Reads node definitions from a JSON config file. The path defaults to ``/app/config.json`` but can be overridden via the ``CONFIG_PATH`` environment variable. """ import json import os _config = None def _load_config(): global _config if _config is None: config_path = os.environ.get("CONFIG_PATH", "/app/config.json") with open(config_path) as f: _config = json.load(f) return _config def get_nodes() -> list[dict]: """Return the list of node definitions from the config file.""" return _load_config()["nodes"] def get_node_url(node_name: str) -> str | None: """Return the agent base URL for *node_name*, or ``None`` if unknown.""" for node in get_nodes(): if node["name"] == node_name: return f"http://{node['host']}:{node['agent_port']}" return None