forked from TheSmallHanCat/flow2api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
59 lines (55 loc) · 2.44 KB
/
Copy pathconfig.py
File metadata and controls
59 lines (55 loc) · 2.44 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
import os
from dataclasses import dataclass
from typing import Literal
@dataclass
class Settings:
# Flow2API remote_browser_api_key must match (Bearer)
flow2api_bearer: str
# Previous bearer accepted during rotation window.
flow2api_bearer_previous: str
# WebSocket agents send this in register
agent_device_token: str
agent_auth_mode: Literal["legacy", "keygen", "dual"]
keygen_verify_mode: Literal["jwt", "introspection"]
keygen_api_url: str
keygen_account: str
keygen_api_token: str
keygen_public_key: str
keygen_issuer: str
keygen_audience: str
keygen_leeway_seconds: int
host: str
port: int
solve_timeout_seconds: int
def load_settings() -> Settings:
raw_timeout = os.environ.get("SOLVE_TIMEOUT_SECONDS")
t = 120
if raw_timeout:
t = max(5, int(raw_timeout))
auth_mode = (os.environ.get("GATEWAY_AGENT_AUTH_MODE") or "legacy").strip().lower()
if auth_mode not in {"legacy", "keygen", "dual"}:
auth_mode = "legacy"
verify_mode = (os.environ.get("KEYGEN_VERIFY_MODE") or "jwt").strip().lower()
if verify_mode not in {"jwt", "introspection"}:
verify_mode = "jwt"
raw_leeway = os.environ.get("KEYGEN_LEEWAY_SECONDS")
leeway_seconds = 10
if raw_leeway:
leeway_seconds = max(0, int(raw_leeway))
return Settings(
flow2api_bearer=(os.environ.get("GATEWAY_FLOW2API_BEARER") or "").strip(),
flow2api_bearer_previous=(os.environ.get("GATEWAY_FLOW2API_BEARER_PREVIOUS") or "").strip(),
agent_device_token=(os.environ.get("GATEWAY_AGENT_DEVICE_TOKEN") or "").strip(),
agent_auth_mode=auth_mode, # type: ignore[arg-type]
keygen_verify_mode=verify_mode, # type: ignore[arg-type]
keygen_api_url=(os.environ.get("KEYGEN_API_URL") or "https://api.keygen.sh").strip(),
keygen_account=(os.environ.get("KEYGEN_ACCOUNT") or "").strip(),
keygen_api_token=(os.environ.get("KEYGEN_API_TOKEN") or "").strip(),
keygen_public_key=(os.environ.get("KEYGEN_PUBLIC_KEY") or "").strip(),
keygen_issuer=(os.environ.get("KEYGEN_ISSUER") or "https://api.keygen.sh").strip(),
keygen_audience=(os.environ.get("KEYGEN_AUDIENCE") or "flow2api-agent-gateway").strip(),
keygen_leeway_seconds=leeway_seconds,
host=(os.environ.get("GATEWAY_HOST") or "0.0.0.0").strip() or "0.0.0.0",
port=int(os.environ.get("GATEWAY_PORT") or "9080"),
solve_timeout_seconds=t,
)