use env vars for secrets (ETHICA_TOKEN/HOME/INTERVAL override config)

This commit is contained in:
2026-06-15 19:44:21 +02:00
parent 5c213972b6
commit f694a63518
5 changed files with 26 additions and 10 deletions
+10 -6
View File
@@ -309,14 +309,18 @@ def main():
print(f"Config not found: {args.config}", file=sys.stderr)
sys.exit(1)
token = cfg.get("token", "")
home = cfg.get("home", "https://ethica.no")
interval = int(cfg.get("interval", 60))
widgets = cfg.get("widgets", [])
# Env vars override config file — keeps secrets out of the yml.
# ETHICA_TOKEN : company API token (required)
# ETHICA_HOME : home URL (optional, default https://ethica.no)
# ETHICA_INTERVAL: collection interval in seconds (optional)
token = os.environ.get("ETHICA_TOKEN") or cfg.get("token", "")
home = os.environ.get("ETHICA_HOME") or cfg.get("home", "https://ethica.no")
interval = int(os.environ.get("ETHICA_INTERVAL") or cfg.get("interval", 60))
widgets = cfg.get("widgets", [])
if not token or token == "REPLACE_ME":
print("Set 'token' in your config (Company → API in the admin panel).",
file=sys.stderr)
print("Set ETHICA_TOKEN env var or 'token' in config "
"(Company → API tab in the admin panel).", file=sys.stderr)
sys.exit(1)
if not widgets:
print("No widgets configured — nothing to do.", file=sys.stderr)