Fix wrong variable.
Add zone validation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import subprocess
|
||||
import dns.zone
|
||||
|
||||
from pathlib import Path
|
||||
from datetime import datetime, UTC
|
||||
@@ -62,8 +63,6 @@ def extract_domain_from_path(path: str) -> str|None:
|
||||
name = Path(path).name
|
||||
name_no_ext = name.rstrip(".zone")
|
||||
|
||||
candidates = set()
|
||||
|
||||
if DOMAIN_FRAGMENT_RE.search(name_no_ext):
|
||||
found = DOMAIN_FRAGMENT_RE.findall(name_no_ext)
|
||||
for f in found:
|
||||
@@ -71,6 +70,15 @@ def extract_domain_from_path(path: str) -> str|None:
|
||||
|
||||
return None
|
||||
|
||||
def validate_zone(zone_name, content) -> bool:
|
||||
try:
|
||||
dns.zone.from_text(content, zone_name, relativize=False)
|
||||
logging.info(f"Zone {zone_name} parsed successfully")
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.error(f"Parse failed for zone {zone_name}")
|
||||
return False
|
||||
|
||||
def export_single_zone(trigger_path: str) -> list[Path]:
|
||||
logging.info(f"Starting export of single zone for trigger path {trigger_path})")
|
||||
ensure_git_repo()
|
||||
@@ -88,7 +96,7 @@ def export_single_zone(trigger_path: str) -> list[Path]:
|
||||
if zone_name == domain:
|
||||
logging.info(f"Single matching zone found: {zone_name}")
|
||||
try:
|
||||
content = export_zone(zone)
|
||||
content = export_zone(zone_name)
|
||||
out = write_zone_export(zone_name, content)
|
||||
commit_and_push([out], trigger_path)
|
||||
return [out]
|
||||
@@ -118,7 +126,7 @@ def export_all_zones(trigger_path: str ="filesystem-change") -> list[Path]:
|
||||
# zone may be a dict with keys like 'id' and 'domain' — adapt to your API result shape
|
||||
zone_name = z.get("name")
|
||||
try:
|
||||
content = export_zone(z)
|
||||
content = export_zone(zone_name)
|
||||
out = write_zone_export(zone_name, content)
|
||||
written_files.append(out)
|
||||
except Exception as e:
|
||||
|
Reference in New Issue
Block a user