Players get a fast TTL-backed homepage (local profile / Cloudflare D1) with dense UI polish; login unlocks /home without blocking on every OpenDota refresh. Co-authored-by: Cursor <cursoragent@cursor.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
"""Put STEAM_API_KEY on climperor-player-sync from staged temp or env."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
WORKER = Path(__file__).resolve().parent / "player-sync"
|
|
STAGED = Path(__file__).resolve().parents[1] / ".refresh" / "steam_key.tmp"
|
|
|
|
|
|
def put_secret(name: str, value: str, env: dict) -> int:
|
|
print(f"putting secret {name} …", flush=True)
|
|
proc = subprocess.run(
|
|
f"npx --yes wrangler@3 secret put {name}",
|
|
cwd=str(WORKER),
|
|
env=env,
|
|
shell=True,
|
|
input=value + "\n",
|
|
text=True,
|
|
capture_output=True,
|
|
)
|
|
if proc.returncode != 0:
|
|
print(proc.stderr or proc.stdout, file=sys.stderr)
|
|
return proc.returncode
|
|
|
|
|
|
def main() -> int:
|
|
email = os.environ.get("CLOUDFLARE_EMAIL") or os.environ.get(
|
|
"KEYZOO_ASSET_META_USERNAME"
|
|
)
|
|
cf_key = os.environ.get("CLOUDFLARE_API_KEY") or os.environ.get(
|
|
"KEYZOO_ASSET_SECRET_GLOBAL_API_KEY"
|
|
)
|
|
steam = (
|
|
os.environ.get("STEAM_API_KEY")
|
|
or os.environ.get("KEYZOO_ASSET_SECRET_WEB_API_KEY")
|
|
or ""
|
|
).strip()
|
|
if not steam and STAGED.is_file():
|
|
steam = STAGED.read_text(encoding="utf-8").strip()
|
|
try:
|
|
STAGED.unlink()
|
|
except OSError:
|
|
pass
|
|
if not email or not cf_key:
|
|
print("missing Cloudflare credentials", file=sys.stderr)
|
|
return 2
|
|
if not steam:
|
|
print("missing STEAM_API_KEY (stage via _stage_steam_key.py first)", file=sys.stderr)
|
|
return 2
|
|
env = os.environ.copy()
|
|
env["CLOUDFLARE_EMAIL"] = email
|
|
env["CLOUDFLARE_API_KEY"] = cf_key
|
|
env["CLOUDFLARE_ACCOUNT_ID"] = "510534f7f6284344aadaf2f5a0794d48"
|
|
code = put_secret("STEAM_API_KEY", steam, env)
|
|
print("ok" if code == 0 else "failed", flush=True)
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|