1

Extraction des secrets

This commit is contained in:
2025-11-28 13:40:20 +01:00
parent fd27dc7fb6
commit 8908c7f6cf
11 changed files with 148 additions and 26 deletions

View File

@@ -14,6 +14,25 @@ if TOOLS_DIR not in sys.path:
sys.path.append(TOOLS_DIR)
def load_env(env_path=None):
path = env_path or os.path.join(ROOT_DIR, ".env")
if not os.path.exists(path):
return
try:
with open(path, "r", encoding="utf-8") as handle:
for line in handle:
stripped = line.strip()
if not stripped or stripped.startswith("#") or "=" not in stripped:
continue
key, value = stripped.split("=", 1)
key = key.strip()
if not key or key in os.environ:
continue
os.environ[key] = value
except Exception as exc: # noqa: BLE001
print(f"Failed to load .env: {exc}", file=sys.stderr)
def load_config():
cfg_path = os.path.join(ROOT_DIR, "tools", "config.json")
try:
@@ -63,8 +82,13 @@ def main():
public_path = payload.get("publicPath")
url = payload.get("stat", {}).get("url")
load_env()
cfg = load_config()
goaccess_url = url or (cfg.get("goaccess") or {}).get("url") or ""
goaccess_url = url or os.environ.get("GOACCESS_URL") or (cfg.get("goaccess") or {}).get("url")
if not goaccess_url:
print("Missing GoAccess URL (set GOACCESS_URL or goaccess.url in tools/config.json)", file=sys.stderr)
sys.exit(1)
try:
data = fetch_goaccess(goaccess_url)