feat: env var overrides for Mealie/Tandoor connection settings
MEALIE_URL, MEALIE_API_KEY, TANDOOR_URL, TANDOOR_API_KEY env vars now take priority over config.json values when set. Useful for Kubernetes deployments where secrets are injected as env vars. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+18
-1
@@ -19,13 +19,26 @@ _DEFAULTS = {
|
||||
"tandoor_api_key": "",
|
||||
}
|
||||
|
||||
# Environment variable overrides for connection settings.
|
||||
# When set, these take priority over values stored in config.json.
|
||||
_ENV_OVERRIDES = {
|
||||
"mealie_url": os.environ.get("MEALIE_URL", "").strip().rstrip("/"),
|
||||
"mealie_api_key": os.environ.get("MEALIE_API_KEY", "").strip(),
|
||||
"tandoor_url": os.environ.get("TANDOOR_URL", "").strip().rstrip("/"),
|
||||
"tandoor_api_key": os.environ.get("TANDOOR_API_KEY", "").strip(),
|
||||
}
|
||||
|
||||
|
||||
def _ensure_dir():
|
||||
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def load() -> dict:
|
||||
"""Return the current config dict, merged with defaults."""
|
||||
"""Return the current config dict, merged with defaults.
|
||||
|
||||
Environment variables (MEALIE_URL, MEALIE_API_KEY, TANDOOR_URL,
|
||||
TANDOOR_API_KEY) take priority over file-based values when set.
|
||||
"""
|
||||
cfg = dict(_DEFAULTS)
|
||||
if CONFIG_FILE.exists():
|
||||
try:
|
||||
@@ -33,6 +46,10 @@ def load() -> dict:
|
||||
cfg.update(json.load(f))
|
||||
except (json.JSONDecodeError, OSError):
|
||||
pass
|
||||
# Apply env overrides (only non-empty values).
|
||||
for key, val in _ENV_OVERRIDES.items():
|
||||
if val:
|
||||
cfg[key] = val
|
||||
return cfg
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user