mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-04 04:34:07 +09:00
api/v2: list devices sorted by name
SaaS sorts by name. NodeStore order moved on every write, so order-sensitive Terraform configs showed changes.
This commit is contained in:
1 parent
88339d8ff1
commit
e99d8f3f88
2 files changed
+16
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package apiv2
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"context"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
@@ -175,6 +176,11 @@ func registerDevices(api huma.API, b Backend) {
|
||||
out.Body.Devices = append(out.Body.Devices, deviceFromView(node, allFields, b.Cfg.BaseDomain))
|
||||
}
|
||||
|
||||
// The NodeStore holds no order, and Tailscale lists devices by name.
|
||||
slices.SortFunc(out.Body.Devices, func(a, b Device) int {
|
||||
return cmp.Compare(a.Name, b.Name)
|
||||
})
|
||||
|
||||
return out, nil
|
||||
})
|
||||
|
||||
|
||||
@@ -851,6 +851,16 @@ func (r *apiReplay) deviceListChecks(t *testing.T, a testcapture.Action, resp []
|
||||
wantBy, gotBy := byLabel(want.Devices), byLabel(got.Devices)
|
||||
checks := []apiCheck{{"listed", sortedStrings(slices.Collect(maps.Keys(wantBy))), sortedStrings(slices.Collect(maps.Keys(gotBy)))}}
|
||||
|
||||
order := func(devs []apiBody) string {
|
||||
labels := make([]string, 0, len(devs))
|
||||
for _, d := range devs {
|
||||
labels = append(labels, r.label("device", d.ID))
|
||||
}
|
||||
|
||||
return strings.Join(labels, ",")
|
||||
}
|
||||
checks = append(checks, apiCheck{"order", order(want.Devices), order(got.Devices)})
|
||||
|
||||
for _, l := range slices.Sorted(maps.Keys(wantBy)) {
|
||||
g, ok := gotBy[l]
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user