Skip to content

Commit

Permalink
sort output of api lists by ID
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
  • Loading branch information
kradalby committed Feb 16, 2024
1 parent da45a20 commit 6f2deb1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions hscontrol/grpcv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package hscontrol
import (
"context"
"fmt"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -98,6 +99,10 @@ func (api headscaleV1APIServer) ListUsers(
response[index] = user.Proto()
}

sort.Slice(response, func(i, j int) bool {
return response[i].Id < response[j].Id
})

log.Trace().Caller().Interface("users", response).Msg("")

return &v1.ListUsersResponse{Users: response}, nil
Expand Down Expand Up @@ -168,6 +173,10 @@ func (api headscaleV1APIServer) ListPreAuthKeys(
response[index] = key.Proto()
}

sort.Slice(response, func(i, j int) bool {
return response[i].Id < response[j].Id
})

return &v1.ListPreAuthKeysResponse{PreAuthKeys: response}, nil
}

Expand Down Expand Up @@ -422,6 +431,10 @@ func (api headscaleV1APIServer) ListNodes(
return nil, err
}

sort.Slice(nodes, func(i, j int) bool {
return nodes[i].ID < nodes[j].ID
})

response := make([]*v1.Node, len(nodes))
for index, node := range nodes {
resp := node.Proto()
Expand Down Expand Up @@ -606,6 +619,10 @@ func (api headscaleV1APIServer) ListApiKeys(
response[index] = key.Proto()
}

sort.Slice(response, func(i, j int) bool {
return response[i].Id < response[j].Id
})

return &v1.ListApiKeysResponse{ApiKeys: response}, nil
}

Expand Down

0 comments on commit 6f2deb1

Please sign in to comment.