From cb2e0cd5c722d11c07f10c19b741b2763d208f24 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 16 Apr 2025 11:14:18 +0200 Subject: [PATCH] types/node: add helper funcs for node tags Signed-off-by: Kristoffer Dalby --- hscontrol/types/node.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hscontrol/types/node.go b/hscontrol/types/node.go index 2e6a0eeb..52651aaf 100644 --- a/hscontrol/types/node.go +++ b/hscontrol/types/node.go @@ -5,6 +5,7 @@ import ( "fmt" "net/netip" "slices" + "sort" "strconv" "strings" "time" @@ -190,19 +191,26 @@ func (node *Node) IsTagged() bool { // Currently, this function only handles tags set // via CLI ("forced tags" and preauthkeys) func (node *Node) HasTag(tag string) bool { - if slices.Contains(node.ForcedTags, tag) { - return true - } + return slices.Contains(node.Tags(), tag) +} - if node.AuthKey != nil && slices.Contains(node.AuthKey.Tags, tag) { - return true +func (node *Node) Tags() []string { + var tags []string + + if node.AuthKey != nil { + tags = append(tags, node.AuthKey.Tags...) } // TODO(kradalby): Figure out how tagging should work // and hostinfo.requestedtags. // Do this in other work. + // #2417 - return false + tags = append(tags, node.ForcedTags...) + sort.Strings(tags) + tags = slices.Compact(tags) + + return tags } func (node *Node) RequestTags() []string {