The repo is private, so anonymous raw URLs return 404. The hub now serves /install-probe.sh (and /install.sh) from its own checkout, open even with UI_PASSWORD, and the Add probe command fetches from there. The installers still ask for a read-only token to clone. Docs use Gitea's "Authorization: token" header and give a git-clone fallback for the hub. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.6 KiB
Python
71 lines
2.6 KiB
Python
"""Hub settings, read from the environment (.env) on each call so tests can change them."""
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
from urllib.parse import urlparse
|
|
|
|
# Empty: the probe install command fetches install-probe.sh from the hub itself (/install-probe.sh),
|
|
# which works for a private repo. Set PROBE_INSTALL_URL to use another location.
|
|
DEFAULT_PROBE_INSTALL_URL = ""
|
|
|
|
|
|
def _list(name: str, default: str) -> list[str]:
|
|
return [x.strip() for x in os.environ.get(name, default).split(",") if x.strip()]
|
|
|
|
|
|
def _num(name: str, default: float) -> float:
|
|
try:
|
|
return float(os.environ.get(name, "") or default)
|
|
except ValueError:
|
|
return default
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Settings:
|
|
ui_password: str
|
|
adguard_url: str
|
|
adguard_username: str
|
|
adguard_password: str
|
|
probe_interval: int
|
|
retention_days: float
|
|
dns_servers: list[str]
|
|
lan_dns_servers: list[str]
|
|
dns_query_name: str
|
|
wan_http_urls: list[str]
|
|
vps_url: str
|
|
slow_lan_ms: float
|
|
slow_wan_ms: float
|
|
slow_dns_ms: float
|
|
throughput_every: int
|
|
throughput_bytes: int
|
|
probe_install_url: str
|
|
hub_public_url: str
|
|
|
|
@property
|
|
def adguard_configured(self) -> bool:
|
|
return bool(self.adguard_url)
|
|
|
|
|
|
def get() -> Settings:
|
|
adguard_url = os.environ.get("ADGUARD_URL", "").strip().rstrip("/")
|
|
lan_default = urlparse(adguard_url).hostname or "" if adguard_url else ""
|
|
return Settings(
|
|
ui_password=os.environ.get("UI_PASSWORD", ""),
|
|
adguard_url=adguard_url,
|
|
adguard_username=os.environ.get("ADGUARD_USERNAME", ""),
|
|
adguard_password=os.environ.get("ADGUARD_PASSWORD", ""),
|
|
probe_interval=max(5, int(_num("PROBE_INTERVAL", 30))),
|
|
retention_days=max(1.0, _num("RETENTION_DAYS", 14)),
|
|
dns_servers=_list("DNS_SERVERS", "1.1.1.1,8.8.8.8,9.9.9.9"),
|
|
lan_dns_servers=_list("LAN_DNS_SERVERS", lan_default),
|
|
dns_query_name=os.environ.get("DNS_QUERY_NAME", "example.com").strip() or "example.com",
|
|
wan_http_urls=_list("WAN_HTTP_URLS", "http://connectivitycheck.gstatic.com/generate_204"),
|
|
vps_url=os.environ.get("VPS_URL", "").strip().rstrip("/"),
|
|
slow_lan_ms=_num("SLOW_LAN_MS", 100),
|
|
slow_wan_ms=_num("SLOW_WAN_MS", 200),
|
|
slow_dns_ms=_num("SLOW_DNS_MS", 250),
|
|
throughput_every=max(0, int(_num("THROUGHPUT_EVERY", 10))),
|
|
throughput_bytes=int(min(_num("THROUGHPUT_BYTES", 4_000_000), 50_000_000)),
|
|
probe_install_url=os.environ.get("PROBE_INSTALL_URL", DEFAULT_PROBE_INSTALL_URL).strip(),
|
|
hub_public_url=os.environ.get("HUB_PUBLIC_URL", "").strip().rstrip("/"),
|
|
)
|