Commit 5a8c988
authored
feat!: DNS-scoped token auth, per-record IP cache, explicit ip4/ip6 (#166)
* feat!: DNS-scoped token auth, per-record IP cache, ip6 and zone params
Closes #151.
Auth: the worker now authenticates with the API token alone. Basic
credentials still work exactly as UniFi sends them, but the username
portion is ignored; raw Bearer tokens are accepted for direct callers.
The SDK never receives an email (it only ever paired one with the
legacy global key anyway).
KV: cache keys move from ip:<email> to ip:<hostname>:<recordType> with
JSON {ip, updatedAt} values and a 30-day expirationTtl on every write,
so stale identities can no longer accumulate (the original #151
complaint). The skip decision is per record: requests where every
record matches its cached IP return without touching the zones API,
and partially cached requests only process the pending records. This
also fixes adding a new hostname while the IP is unchanged, which the
per-user key silently skipped.
Updates and notifications key off the actual DNS delta: when the
existing record already holds the target IP, no update call is made
and no notification fires; the cache is refreshed silently. ntfy
messages cover only records that actually changed.
New query parameters: ip6 adds an AAAA record per hostname for
dual-stack callers (upstream #207 parity); zone optionally restricts
record matching to one zone for parity with UniFi's native Cloudflare
DDNS scoping. Multi-zone discovery remains the default.
Migration: legacy last_ip and ip:<email> KV keys are never read again;
sweep them once with wrangler kv key delete (the namespace is a pure
cache, so wiping it entirely is also safe).
BREAKING CHANGE: Authorization headers must use the Basic scheme (as
UniFi does) or a raw Bearer token; Bearer-wrapped base64 credentials
are no longer accepted. The JSON response no longer includes
previousIp; data.records entries carry per-record updated flags.
* feat!: explicit ip4/ip6 parameters, drop legacy ip/myip/hostname
ip4 and ip6 are now the only address parameters: literals validate
against their family, and auto takes the connecting IP only when it
matches the slot's family, silently skipping otherwise so dual-stack
UniFi devices can send ip4=%i&ip6=auto without flapping (inadyn has a
single %i substitution and no IPv6 variable; verified against inadyn
2.13.0 on the target UDM). hostnames= is the sole hostname parameter.
BREAKING CHANGE: ip, myip, and hostname query parameters are removed;
the ip=auto 500-on-undeterminable path is gone (auto slots skip, and a
request with no resolvable slot is a 422).1 parent 568cf1f commit 5a8c988
6 files changed
Lines changed: 874 additions & 382 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | | - | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
29 | | - | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
109 | | - | |
| 110 | + | |
110 | 111 | | |
111 | | - | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
0 commit comments