Add automatic CPA Management API import after mint

Upload xai-*.json to POST /v0/management/auth-files when cpa_auto_import_remote is enabled. Failures are logged only and never block registration.
This commit is contained in:
chaos committed 2026-07-11 17:47:34 +08:00
1 parent d8e65ae4ef
commit 0d8265de03
5 files changed
+299 -1

No files matched your search

+20
View File
@@ -25,6 +25,7 @@ if str(_ROOT) not in sys.path:
sys.path.insert(0, str(_ROOT))
from cpa_xai import existing_cpa_emails, mint_and_export, parse_accounts_file # noqa: E402
from cpa_export import maybe_import_cpa_auth_remote # noqa: E402
def main() -> int:
@@ -87,6 +88,7 @@ def main() -> int:
help="Always open fresh Chromium (default)",
)
args = ap.parse_args()
args._register_cfg = {}
if args.headless:
args.headed = False
@@ -108,6 +110,7 @@ def main() -> int:
args.proxy = (cfg.get("cpa_proxy") or cfg.get("proxy") or "").strip()
if not args.cpa_dir:
args.cpa_dir = (cfg.get("cpa_hotload_dir") or "").strip()
args._register_cfg = cfg
except Exception as e: # noqa: BLE001
print(f"warn: read config proxy failed: {e}", flush=True)
if not args.proxy:
@@ -176,6 +179,23 @@ def main() -> int:
shutil.copy2(src, dst)
os.chmod(dst, 0o600)
print(f"copied -> {dst}", flush=True)
# optional remote Management API import (config-gated; never fails the mint)
try:
reg_cfg = getattr(args, "_register_cfg", None) or {}
remote = maybe_import_cpa_auth_remote(
r["path"],
config=reg_cfg,
log_callback=lambda m: print(m, flush=True),
)
if remote.get("ok"):
print(
f"remote import ok -> {remote.get('base')} name={remote.get('name')}",
flush=True,
)
elif not remote.get("skipped"):
print(f"remote import failed: {remote.get('error')}", flush=True)
except Exception as e: # noqa: BLE001
print(f"remote import unexpected error: {e}", flush=True)
else:
fail_n += 1
if args.fail_log: