| 123456789101112131415161718192021 |
- import json, re, sys
- # stdin管道接收响应(宿主curl | 容器python)
- raw = sys.stdin.read()
- d = json.loads(raw)
- text = json.dumps(d.get("data", {}))
- m = re.search(r"sk-[A-Za-z0-9_-]{20,}", text)
- tok = m.group(0) if m else ""
- print("got_len:", len(tok))
- if tok:
- p = "/opt/data/fmode-identity.json"
- ident = json.load(open(p))
- ident["newapi_token"] = tok
- json.dump(ident, open(p, "w"), ensure_ascii=False, indent=2)
- cfg = open("/opt/data/config.yaml").read()
- if "api_key:" in cfg:
- cfg = re.sub(r"( api_key: ).*", lambda _: " api_key: " + tok, cfg, count=1)
- open("/opt/data/config.yaml", "w").write(cfg)
- print("identity+config updated")
- else:
- print("NO_TOKEN in response, keys:", list(d.get("data", {}).keys()))
|