change app dns bind behavior

This commit is contained in:
leo committed 2026-11-22 22:44:47 +02:00
1 parent dd50a0d05e
commit 40a8ed23cd
17 files changed
+1440 -104

No files matched your search

+19 -4
View File
@@ -31,6 +31,7 @@ class Route:
path: str
handler: Callable[[Call], Any] | Any
status: int = 200
raw: bool = False
class FakeTransport:
@@ -42,27 +43,38 @@ class FakeTransport:
self.routes.append(Route(method.upper(), path, response, status))
return self
def add_text(
self, method: str, path: str, text: str, *, status: int = 200
) -> "FakeTransport":
self.routes.append(Route(method.upper(), path, text, status, raw=True))
return self
# -- Transport protocol --------------------------------------------
def request(self, method, url, headers, body, timeout) -> Response:
split = urllib.parse.urlsplit(url)
call = Call(
method=method,
url=url,
path=split.path,
path=split.path or "/",
query=urllib.parse.parse_qs(split.query),
body=json.loads(body.decode("utf-8")) if body else None,
)
self.calls.append(call)
for route in reversed(self.routes):
if route.method == method and route.path == split.path:
if route.method == method and route.path == (split.path or "/"):
payload = route.handler(call) if callable(route.handler) else route.handler
status = route.status
if isinstance(payload, tuple) and len(payload) == 2:
status, payload = payload
body = (
payload.encode("utf-8")
if route.raw
else json.dumps(payload).encode("utf-8")
)
return Response(
status=status,
body=json.dumps(payload).encode("utf-8"),
headers={"content-type": "application/json"},
body=body,
headers={"content-type": "text/plain" if route.raw else "application/json"},
)
return Response(
status=404,
@@ -153,6 +165,7 @@ def make_config(
proxmox: dict[str, Any] | None = None,
general: dict[str, Any] | None = None,
cloudflare: dict[str, Any] | None = None,
dns: dict[str, Any] | None = None,
state: dict[str, Any] | None = None,
**webserver: Any,
) -> Config:
@@ -164,6 +177,7 @@ def make_config(
"token_secret": "pve-secret",
},
"cloudflare": {"api_token": "cf-token", "proxied": True},
"dns": {"target": "guest"},
"webserver": {
"kind": "nginx",
"mode": "local",
@@ -174,6 +188,7 @@ def make_config(
("general", general),
("proxmox", proxmox),
("cloudflare", cloudflare),
("dns", dns),
("state", state),
):
if values: