Skip to content

Commit

Permalink
ensure valid tags is populated on user gets too
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Dec 17, 2024
1 parent bbc93a9 commit 6167182
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
16 changes: 8 additions & 8 deletions cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,41 @@ func init() {

err := registerNodeCmd.MarkFlagRequired("user")
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
registerNodeCmd.Flags().StringP("key", "k", "", "Key")
err = registerNodeCmd.MarkFlagRequired("key")
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
nodeCmd.AddCommand(registerNodeCmd)

expireNodeCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
err = expireNodeCmd.MarkFlagRequired("identifier")
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
nodeCmd.AddCommand(expireNodeCmd)

renameNodeCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
err = renameNodeCmd.MarkFlagRequired("identifier")
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
nodeCmd.AddCommand(renameNodeCmd)

deleteNodeCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
err = deleteNodeCmd.MarkFlagRequired("identifier")
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
nodeCmd.AddCommand(deleteNodeCmd)

moveNodeCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")

err = moveNodeCmd.MarkFlagRequired("identifier")
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}

moveNodeCmd.Flags().StringP("user", "u", "", "New user")
Expand All @@ -85,15 +85,15 @@ func init() {

err = moveNodeCmd.MarkFlagRequired("user")
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
nodeCmd.AddCommand(moveNodeCmd)

tagCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")

err = tagCmd.MarkFlagRequired("identifier")
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err.Error())
}
tagCmd.Flags().
StringSliceP("tags", "t", []string{}, "List of tags to add to the node")
Expand Down
25 changes: 10 additions & 15 deletions hscontrol/grpcv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/puzpuzpuz/xsync/v3"
"github.com/rs/zerolog/log"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -21,6 +22,7 @@ import (

v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/juanfont/headscale/hscontrol/db"
"github.com/juanfont/headscale/hscontrol/policy"
"github.com/juanfont/headscale/hscontrol/types"
"github.com/juanfont/headscale/hscontrol/util"
)
Expand Down Expand Up @@ -457,19 +459,7 @@ func (api headscaleV1APIServer) ListNodes(
return nil, err
}

response := make([]*v1.Node, len(nodes))
for index, node := range nodes {
resp := node.Proto()

// Populate the online field based on
// currently connected nodes.
if val, ok := isLikelyConnected.Load(node.ID); ok && val {
resp.Online = true
}

response[index] = resp
}

response := nodesToProto(api.h.polMan, isLikelyConnected, nodes)
return &v1.ListNodesResponse{Nodes: response}, nil
}

Expand All @@ -482,6 +472,11 @@ func (api headscaleV1APIServer) ListNodes(
return nodes[i].ID < nodes[j].ID
})

response := nodesToProto(api.h.polMan, isLikelyConnected, nodes)
return &v1.ListNodesResponse{Nodes: response}, nil
}

func nodesToProto(polMan policy.PolicyManager, isLikelyConnected *xsync.MapOf[types.NodeID, bool], nodes types.Nodes) []*v1.Node {
response := make([]*v1.Node, len(nodes))
for index, node := range nodes {
resp := node.Proto()
Expand All @@ -492,12 +487,12 @@ func (api headscaleV1APIServer) ListNodes(
resp.Online = true
}

validTags := api.h.polMan.Tags(node)
validTags := polMan.Tags(node)
resp.ValidTags = validTags
response[index] = resp
}

return &v1.ListNodesResponse{Nodes: response}, nil
return response
}

func (api headscaleV1APIServer) MoveNode(
Expand Down

0 comments on commit 6167182

Please sign in to comment.