Skip to content

Commit

Permalink
revert: change from repr to string in changeset
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Schaller <[email protected]>
  • Loading branch information
olofvndrhr committed Mar 1, 2024
1 parent 696d2a2 commit 8d29b5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
22 changes: 17 additions & 5 deletions dev/zones/example.com.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
---
? ''
: ttl: 172800
type: NS
values:
- ns1.example.com.
- ns3.example.com.
: - ttl: 172800
type: NS
values:
- ns1.example.com.
- ns2.example.com.
- type: TXT
value: v=spf1 include:example.com -all
_ts3._udp:
type: SRV
value:
port: 9987
priority: 0
target: example.com.
weight: 5
abc:
type: CNAME
value: def.example.com.
ns1:
type: A
value: 192.168.1.1
Expand Down
15 changes: 8 additions & 7 deletions src/octodns_netbox_dns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _escape_semicolon(self, value: str) -> str:
return fixed

def _unescape_semicolon(self, value: str) -> str:
fixed = value.replace(r"\;", ";")
fixed = value.replace(r"\\", "\\").replace(r"\;", ";")
self.log.debug(rf"in='{value}', unescaped='{fixed}'")
return fixed

Expand Down Expand Up @@ -317,18 +317,19 @@ def _format_changeset(self, change: Any) -> set[str]:
"""
match change:
case octodns.record.ValueMixin():
changeset = {str(change.value)}
changeset = {repr(change.value)[1:-1]}
case octodns.record.ValuesMixin():
changeset = {str(v) for v in change.values}

changeset = {repr(v)[1:-1] for v in change.values}
case _:
raise ValueError

if change._type not in ["TXT", "SPF"]:
self.log.debug(f"{changeset=}")
return changeset

escaped_changeset = {self._unescape_semicolon(n) for n in changeset}
return escaped_changeset
unescaped_changeset = {self._unescape_semicolon(n) for n in changeset}
self.log.debug(f"{unescaped_changeset=}")
return unescaped_changeset

def _include_change(self, change: octodns.record.change.Change) -> bool:
"""filter out record types which the provider can't create in netbox
Expand Down Expand Up @@ -414,7 +415,7 @@ def _apply(self, plan: octodns.provider.plan.Plan) -> None:
nb_record.delete()
if nb_record.value in to_update:
self.log.debug(
rf"MODIFY {nb_record.type} {nb_record.name} {nb_record.value}"
rf"MODIFY (ttl) {nb_record.type} {nb_record.name} {nb_record.value}"
)
nb_record.ttl = change.new.ttl
nb_record.save()
Expand Down

0 comments on commit 8d29b5e

Please sign in to comment.