Repository navigation
Expand file tree
/
Copy pathsync_oauth.py
More file actions
executable file
·127 lines (115 loc) · 4.01 KB
/
Copy pathsync_oauth.py
File metadata and controls
executable file
·127 lines (115 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
"""Distribute the shared OAuth source into self-contained MCP packages."""
from __future__ import annotations
import argparse
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SOURCE = Path("shared/oauth.py")
HEADER = "# Generated from shared/oauth.py by scripts/sync_oauth.py; do not edit.\n\n"
STATE_SOURCE = Path("shared/oauth_state.py")
STATE_HEADER = (
"# Generated from shared/oauth_state.py by scripts/sync_oauth.py; do not edit.\n\n"
)
DEPLOY_SOURCE = Path("shared/deploy_oauth_state.sh")
SHARED_SERVERS = (
"aichat",
"face",
"fish",
"flux",
"glm",
"grok",
"hailuo",
"hcaptcha",
"image2text",
"kling",
"luma",
"maestro",
"minimax",
"nanobanana",
"openai",
"producer",
"qwen-image",
"recaptcha",
"seedance",
"seedream",
"serp",
"shorturl",
"sora",
"suno",
"turnstile",
"veo",
"wan",
"webextrator",
)
# These implementations have different behavior and must not be overwritten.
LOCAL_SERVERS = {
"acedatacloud": "PlatformToken instead of an API Credential",
"digitalhuman": "redirect validation and revoked-token tracking",
"happyhorse": "redirect validation and revoked-token tracking",
"midjourney": "distinct callback/token-exchange implementation",
}
STATE_SERVERS = (*SHARED_SERVERS, "digitalhuman", "happyhorse", "midjourney")
DEPLOY_SERVERS = tuple(
server
for server in STATE_SERVERS
if server
not in {"digitalhuman", "hcaptcha", "image2text", "recaptcha", "sora", "turnstile"}
)
def sync(root: Path = ROOT, *, check: bool = False) -> list[Path]:
"""Return stale package paths; update them unless this is a check-only run."""
expected = set(SHARED_SERVERS) | LOCAL_SERVERS.keys()
discovered = {path.parent.parent.name for path in root.glob("*/core/oauth.py")}
if discovered != expected:
raise ValueError(
"OAuth inventory changed; classify new servers before syncing. "
f"Unclassified: {sorted(discovered - expected)}; "
f"missing: {sorted(expected - discovered)}"
)
rendered = HEADER.encode() + (root / SOURCE).read_bytes()
rendered_state = STATE_HEADER.encode() + (root / STATE_SOURCE).read_bytes()
rendered_deploy = (root / DEPLOY_SOURCE).read_bytes()
stale = []
for server in SHARED_SERVERS:
relative = Path(server) / "core/oauth.py"
target = root / relative
if target.read_bytes() != rendered:
stale.append(relative)
if not check:
target.write_bytes(rendered)
for server in STATE_SERVERS:
relative = Path(server) / "core/oauth_state.py"
target = root / relative
if not target.exists() or target.read_bytes() != rendered_state:
stale.append(relative)
if not check:
target.write_bytes(rendered_state)
for server in DEPLOY_SERVERS:
relative = Path(server) / "deploy/oauth-state.sh"
target = root / relative
if not target.exists() or target.read_bytes() != rendered_deploy:
stale.append(relative)
if not check:
target.parent.mkdir(parents=True, exist_ok=True)
target.write_bytes(rendered_deploy)
return stale
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--check", action="store_true", help="Fail on stale copies without writing"
)
args = parser.parse_args()
try:
stale = sync(check=args.check)
except ValueError as error:
parser.exit(1, f"{error}\n")
if args.check and stale:
print("Shared OAuth copies are stale; run python3 scripts/sync_oauth.py:")
for path in stale:
print(f" {path}")
return 1
print(
f"Shared OAuth: {len(SHARED_SERVERS)} providers, {len(STATE_SERVERS)} stores, and {len(DEPLOY_SERVERS)} deploy helpers checked; {len(stale)} copies updated"
)
return 0
if __name__ == "__main__":
raise SystemExit(main())