modified: src/netbox_plugin_bind_provisioner/management/commands/bind-transfer-endpoint.py

Slight changes to previous commit:

1. Stop converting the zone ID to string for catalog zone PTR record creation
   and simply use its int type.

2. Extend padding of ID in catalog zone PTR record from 6 digits to 9.
   Auto-incrementing of zone IDs may create larger IDs then expected if the
   turn-over of zones is high. Precautionary measure.

3. Fix catalog zone SOA record creation - A slight mistake was introduced in
   previous commit that would render the set the MNAME field to
   "invalid.zones.catz." rather than the intended "invalid." value.

4. Run code through black formater to stay compliant.
This commit is contained in:
Sven Luethi committed 2026-01-09 13:36:08 +01:00
1 parent 1375bbb7e3
commit 55d891f38c
1 file changed
+8 -10
@@ -1,7 +1,6 @@
import logging import logging
import socketserver import socketserver
import os import os
#import re
import threading import threading
import dns.query import dns.query
import dns.message import dns.message
@@ -14,7 +13,6 @@ import dns.rdtypes
import dns.exception import dns.exception
import dns.renderer import dns.renderer
# from hashlib import sha256
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
@@ -109,11 +107,9 @@ class CatalogZone:
for nb_zone in nb_zones: for nb_zone in nb_zones:
ttl = 0 ttl = 0
qname = dns.name.from_text(nb_zone.name, dns.name.root) qname = dns.name.from_text(nb_zone.name, dns.name.root)
# zone_id = sha256(qname.to_text().encode()).hexdigest()[0:63]
zone_id = str(nb_zone.id)
# Create PTR record # Create PTR record
p_name = f"zid-{zone_id:>06}" p_name = f"zid-{nb_zone.id:09d}"
ptr_name = dns.name.from_text(p_name, ptr_base) ptr_name = dns.name.from_text(p_name, ptr_base)
assert ptr_name.is_subdomain(origin) assert ptr_name.is_subdomain(origin)
rdata = dns.rdata.from_text( rdata = dns.rdata.from_text(
@@ -145,8 +141,8 @@ class CatalogZone:
ttl = 0 ttl = 0
rclass = dns.rdataclass.IN rclass = dns.rdataclass.IN
rtype = dns.rdatatype.SOA rtype = dns.rdatatype.SOA
mname = dns.name.from_text("invalid.", origin) mname = dns.name.from_text("invalid", dns.name.root)
rname = dns.name.from_text("invalid.", origin) rname = dns.name.from_text("invalid", dns.name.root)
serial = cls._serial_obj.value serial = cls._serial_obj.value
refresh = 60 refresh = 60
retry = 10 retry = 10
@@ -236,13 +232,16 @@ class DNSBaseRequestHandler(socketserver.BaseRequestHandler):
value = record.value value = record.value
if rdtype == dns.rdatatype.TXT: if rdtype == dns.rdatatype.TXT:
if value.startswith('"') and value.endswith('"'): if value.startswith('"') and value.endswith('"'):
value = value[1:-1].replace('" "', '').replace('"', '\"') value = value[1:-1].replace('" "', "").replace('"', '"')
if len(value) > 255: if len(value) > 255:
# This is a bug fix for netbox. If netbox allowed for # This is a bug fix for netbox. If netbox allowed for
# an unquoted value to be larger then 255 characters, # an unquoted value to be larger then 255 characters,
# it misunderstood everything behind a ; as a comment. # it misunderstood everything behind a ; as a comment.
chunks = ['"{}"'.format(value[i:i+255]) for i in range(0, len(value), 255)] chunks = [
'"{}"'.format(value[i : i + 255])
for i in range(0, len(value), 255)
]
value = " ".join(chunks) value = " ".join(chunks)
else: else:
value = f'"{value}"' value = f'"{value}"'
@@ -284,7 +283,6 @@ class DNSBaseRequestHandler(socketserver.BaseRequestHandler):
zone.replace_rdataset(name, rdataset) zone.replace_rdataset(name, rdataset)
return zone return zone
def denyRequestBadTSIG(self, wire, tsig_error: dns.rcode): def denyRequestBadTSIG(self, wire, tsig_error: dns.rcode):
# Use empty keyring to parse TSIG without validating # Use empty keyring to parse TSIG without validating
query = dns.message.from_wire( query = dns.message.from_wire(