Allow raw ip addresses

This commit is contained in:
2026-08-20 09:32:04 +02:00
parent 0fed855cf7
commit 86e644410b
5 changed files with 82 additions and 15 deletions
+17 -4
View File
@@ -5,6 +5,8 @@ from typing import List, Optional
import yaml
from . import dns_resolver
class ConfigError(Exception):
"""Raised for any problem with the config file's contents."""
@@ -16,9 +18,12 @@ class Endpoint:
host: str
scheme: str # "http" or "https"
port: int
dns_server: str # DNS server used to resolve `host` — the system/router
# resolver is never consulted, see app/dns_resolver.py
expected_status: int
# DNS server used to resolve `host` — the system/router resolver is
# never consulted, see app/dns_resolver.py. Optional (and unused) when
# `host` is already a literal IP address, since there's nothing to
# resolve in that case.
dns_server: Optional[str] = None
path: str = "/"
timeout_seconds: Optional[float] = None
verify_tls: bool = True # set False for endpoints with self-signed certs
@@ -103,14 +108,22 @@ def load_config(path: str) -> AppConfig:
f"{ctx} ('{name}'): scheme must be 'http' or 'https', got '{scheme}'"
)
host = _require(ep, "host", ctx)
dns_server = ep.get("dns_server") or None
if not dns_resolver.is_ip_literal(host) and not dns_server:
raise ConfigError(
f"{ctx} ('{name}'): 'dns_server' is required when 'host' is not "
"a literal IP address"
)
timeout = ep.get("timeout_seconds")
endpoints.append(
Endpoint(
name=name,
host=_require(ep, "host", ctx),
host=host,
scheme=scheme,
port=int(_require(ep, "port", ctx)),
dns_server=_require(ep, "dns_server", ctx),
dns_server=dns_server,
expected_status=int(_require(ep, "expected_status", ctx)),
path=ep.get("path", "/"),
timeout_seconds=float(timeout) if timeout else None,