""" apply service config. Personal info and WBS fields used to live here as env vars; they now come in with every /apply request as a Profile. The only remaining settings are browser + service-level knobs. """ import logging import sys from os import getenv from dotenv import load_dotenv logger = logging.getLogger("flat-apply") load_dotenv() def get_env_or_fail(key: str, default: str | None = None, required: bool = True) -> str: value = getenv(key, default) if required and value is None: logger.error(f"Missing required environment variable: {key}") sys.exit(1) return value def get_bool_env(key: str, default: str = "False") -> bool: return (getenv(key, default) or "").lower() in ("true", "1", "yes", "on") def get_int_env(key: str, default: str) -> int: v = getenv(key, default) or default try: return int(v) except ValueError: logger.error(f"Env var {key} must be int, got {v!r}") sys.exit(1) # --- Browser ----------------------------------------------------------------- HEADLESS: bool = get_bool_env("HEADLESS", "True") BROWSER_WIDTH: int = get_int_env("BROWSER_WIDTH", "600") BROWSER_HEIGHT: int = get_int_env("BROWSER_HEIGHT", "800") BROWSER_LOCALE: str = getenv("BROWSER_LOCALE", "de-DE") POST_SUBMISSION_SLEEP_MS: int = get_int_env("POST_SUBMISSION_SLEEP_MS", "0") # --- Service ----------------------------------------------------------------- INTERNAL_API_KEY: str = get_env_or_fail("INTERNAL_API_KEY") def log_settings() -> None: logger.debug("--- Settings ---") logger.debug(f"HEADLESS: {HEADLESS}") logger.debug(f"BROWSER_WIDTH: {BROWSER_WIDTH}") logger.debug(f"BROWSER_HEIGHT: {BROWSER_HEIGHT}") logger.debug(f"BROWSER_LOCALE: {BROWSER_LOCALE}") logger.debug(f"POST_SUBMISSION_SLEEP_MS: {POST_SUBMISSION_SLEEP_MS}")