Skip to content

feat(dns): manage static DNS records - #12

Merged
rvben merged 2 commits into
rvben:mainfrom
MelonSmasher:feat/static-dns
Sep 17, 2026
Merged

rvben merged 2 commits into
rvben:mainfrom
MelonSmasher:feat/static-dns

Conversation

@MelonSmasher

@MelonSmasher MelonSmasher commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add unifi dns list|show|create|update|delete for the controller's local static DNS records (A, AAAA, CNAME, MX, TXT, SRV; NS can be listed and deleted).
  • Talk to the official Integration DNS-policies API on Network 10.1+, and fall back to the v2 static-dns API on older firmware. Domain-forward policies are omitted.
  • Update is a native PUT on the Integration API. On v2-only controllers it deletes and recreates, because that API has no PUT. dns delete is confirmation-gated like the other destructive commands.

Test plan

  • cargo test (full suite)
  • cargo clippy --all-targets -- -D warnings
  • cargo fmt -- --check
  • Against a Network 10.6 controller: dns list, create an A record, update its value, show by name, delete with --yes (also created and deleted AAAA, CNAME, MX, TXT, and SRV; raw policies matched what the CLI sent)
  • Against a Network 8/9 controller: confirm the v2 fallback lists existing records and that update still works via delete+create
  • Piped dns delete without --yes exits 2 with kind: confirmation_required
  • unifi schema publishes the new commands, and --fields on dns list rejects unknown names

Made with Cursor

MelonSmasher and others added 2 commits September 16, 2026 14:43
Add list, show, create, update, and delete for the controller's local
static DNS records. Prefer the Integration DNS-policies API and fall
back to v2 static-dns on older firmware.

Co-authored-by: Cursor <[email protected]>
An update built from a v2 static-dns MX, TXT, or SRV record copied the
stored TTL into the write, which validate then rejected even when the
caller never passed --ttl. from_record now carries a TTL only for types
that accept one.

legacy_body stripped a trailing dot from every value, corrupting TXT data
that ends in a dot. Only hostname-shaped values are stripped now.

dns update resolves the second lookup by the id it already found rather
than re-running name resolution, and the DNS absent-endpoint check reuses
is_absent_legacy_endpoint instead of duplicating its markers.
@rvben
rvben merged commit 149edf3 into rvben:main Sep 17, 2026
@rvben

rvben commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR, @MelonSmasher. Looks good! Merged.

@rvben

rvben commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Follow-up on this: I pushed a change on top before releasing, in 0.4.3.

dns update is now refused on controllers that only serve the v2 static-dns API, instead of deleting the record and recreating it. The delete-then-create had no way to fail safely: when the create was rejected the original record was already gone, and the error reported only the failed create, so the output read as if the update had been rejected and the record left intact.

It needed no server flakiness to hit. validate() checked that SRV priority, weight and port were present but never checked their range, and they are u32, so --port 100000 passed validation, deleted the record, and was then rejected by the controller. That bound is now checked before any write starts.

Editing a record on v2 is now dns delete followed by dns create, so the destructive step is explicit and goes through the same confirmation gate as the other destructive commands.

This does not affect the path you tested. On Network 10.6 update is still the native PUT on the Integration API, unchanged. The v2 fallback still lists, creates and deletes; only in-place update is refused there, and that is the one path the test plan left unchecked.

One other fix in the same change: a record reporting a TTL of 0 was read as having no TTL, and the write path then substituted the 14400 default, so an update that never mentioned --ttl silently changed it. A 0 now round-trips.

If you do have a v2-only controller and the delete-plus-create flow is awkward in practice, say so and I will look at it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants