Compare commits

..
1 Commits
Author SHA1 Message Date
Sven Luethi 6ac1548eef modified: src/netbox_plugin_bind_provisioner/__init__.py
modified:   src/netbox_plugin_bind_provisioner/management/commands/bind-transfer-endpoint.py
Improve TXT record formating.
2025-12-01 19:22:11 +01:00
2 changed files with 7 additions and 6 deletions

No files matched your search

@@ -5,7 +5,7 @@ from django.utils.translation import gettext_lazy as _
from django.dispatch import receiver
from django.conf import settings
__version__ = "1.0.2"
__version__ = "1.0.3"
logger = logging.getLogger(__name__)
@@ -251,16 +251,17 @@ class DNSBaseRequestHandler(socketserver.BaseRequestHandler):
# from cutting it up:
value = record.value
if rdtype == dns.rdatatype.TXT:
if not value.startswith('"') and not value.endswith('"'):
value = value.replace('"', '\\"')
if len(value) <= 255:
value = f'"{value}"'
else:
if value.startswith('"') and value.endswith('"'):
value = value[1:-1].replace('" "', '').replace('"', '\"')
if len(value) > 255:
# This is a bug fix for netbox. If netbox allowed for
# an unquoted value to be larger then 255 characters,
# it misunderstood everything behind a ; as a comment.
chunks = ['"{}"'.format(value[i:i+255]) for i in range(0, len(value), 255)]
value = " ".join(chunks)
else:
value = f'"{value}"'
rdata = dns.rdata.from_text(
dns.rdataclass.IN,