"""Configuration loader. Reads the same JSON config format as the Node.js app: CTEWARD_ST_LEXWARE_CONFIG env var or /etc/cteward/st-lexware.json Applies the same defaults as startup.js: mssql={}, server={}, auth={}, auth.bots={}, auth.flags={} """ import json import os _DEFAULT_CONFIG_PATH = '/etc/cteward-ng/config.json' def load_config(config_path=None): """Load and apply defaults to the JSON configuration. Mirrors the config loading in startup.js lines 16-28. """ path = config_path or os.environ.get( 'CTEWARD_ST_LEXWARE_CONFIG', _DEFAULT_CONFIG_PATH ) config = {} try: with open(path, 'r') as fh: config = json.load(fh) except (FileNotFoundError, json.JSONDecodeError) as exc: # Same behavior as Node.js: print warning, use defaults print(f"Can't load configfile '{path}': {exc}") # Apply defaults (mirrors startup.js) config.setdefault('mssql', {}) config.setdefault('server', {}) config.setdefault('auth', {}) config['auth'].setdefault('bots', {}) config['auth'].setdefault('flags', {}) return config