fix(cloudflared): query DNS per hostname and validate config.yml first

The overwrite guard listed the zone's first 100 records only, so a
record further on went unseen. It now queries each ingress hostname by
name and compares names case-insensitively, and the prune listing pages
through result_info.total_pages. Query values are urlencoded. The
template task validates config.yml with cloudflared before it replaces
the file; the rendered content is unchanged. The API stub filters by
name and pages to match.

Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
Defame1297 committed 2026-11-23 14:55:59 +00:00
1 parent fd1e9b67dd
commit eaa5d2f4ee
2 files changed
+80 -33

No files matched your search

@@ -44,13 +44,14 @@ class Handler(BaseHTTPRequestHandler):
state_dir = "."
# Quiet: the requests go to requests.log instead of stderr.
def log_message(self, format, *args):
def log_message(self, *args):
pass
def _send(self, status, result=None):
body = json.dumps(
{"success": status == 200, "errors": [], "result": result}
).encode()
def _send(self, status, result=None, result_info=None):
reply = {"success": status == 200, "errors": [], "result": result}
if result_info is not None:
reply["result_info"] = result_info
body = json.dumps(reply).encode()
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
@@ -83,12 +84,7 @@ class Handler(BaseHTTPRequestHandler):
return self._tunnel(match.group(2))
match = RECORDS_PATH.match(path)
if self.command == "GET" and match and match.group(1) == ZONE_ID:
records = [
r
for r in RECORDS
if all(r.get(k) == query[k] for k in ("type", "content") if k in query)
]
return self._send(200, records)
return self._records(query)
if self.command == "GET" and path == "/zones":
zones = (
[{"id": ZONE_ID, "name": ZONE_NAME}]
@@ -98,6 +94,26 @@ class Handler(BaseHTTPRequestHandler):
return self._send(200, zones)
return self._send(404)
# Filters by name (case-insensitive, as DNS names are), type and content, and pages.
def _records(self, query):
records = [
r
for r in RECORDS
if ("name" not in query or r["name"].lower() == query["name"].lower())
and all(r[k] == query[k] for k in ("type", "content") if k in query)
]
per_page = int(query.get("per_page", "100"))
page = int(query.get("page", "1"))
total_pages = max(1, -(-len(records) // per_page))
chunk = records[(page - 1) * per_page : page * per_page]
info = {
"page": page,
"per_page": per_page,
"total_count": len(records),
"total_pages": total_pages,
}
return self._send(200, chunk, info)
def _tunnel(self, tunnel_id):
if tunnel_id is None and self.command == "POST":
return self._create()