Skip to content

Commit

Permalink
always normalize zones
Browse files Browse the repository at this point in the history
  • Loading branch information
elipsion committed Aug 8, 2024
1 parent 96d4bff commit f1f6602
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/octodns_netbox_dns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ def __init__(
self.make_absolute = make_absolute
self.disable_ptr = disable_ptr

def _make_absolute(self, value: str) -> str:
def _make_absolute(self, value: str, force : bool = False) -> str:
"""return dns name with trailing dot to make it absolute
@param value: dns record value
@param force: when `True`, disregard configuration option `make_absolute`
@return: absolute dns record value
"""
if not self.make_absolute or value.endswith("."):
if value.endswith("."):
return value

if not (self.make_absolute or force):
return value

absolute_value = value + "."
Expand Down Expand Up @@ -438,5 +443,6 @@ def list_zones(self) -> list[str]:
"""
query_params = {"status": "active", **self.nb_view}
zones = self.api.plugins.netbox_dns.zones.filter(**query_params)
zones = [self._make_absolute(z.name, True) for z in zones]

return sorted([self._make_absolute(z.name) for z in zones])
return sorted(zones)
20 changes: 18 additions & 2 deletions tests/test_make_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,33 @@
}


def test1():
def test_absolute():
nbdns = NetBoxDNSProvider(**DEFAULT_CONFIG)
rcd = "example.com"
absolute = nbdns._make_absolute(rcd)

assert absolute == "example.com."


def test2():
def test_noop():
nbdns = NetBoxDNSProvider(**DEFAULT_CONFIG)
rcd = "example.com."
absolute = nbdns._make_absolute(rcd)

assert absolute == "example.com."

def test_disabled():
args = {**DEFAULT_CONFIG, "make_absolute": False}
nbdns = NetBoxDNSProvider(**args)
rcd = "example.com"
relative = nbdns._make_absolute(rcd, force=False)

assert relative == "example.com"

def test_force():
args = {**DEFAULT_CONFIG, "make_absolute": False}
nbdns = NetBoxDNSProvider(**args)
rcd = "example.com"
absolute = nbdns._make_absolute(rcd, force=True)

assert absolute == "example.com."

0 comments on commit f1f6602

Please sign in to comment.