mirror of
https://github.com/juanfont/headscale.git
synced 2025-08-01 13:46:49 +02:00
types/node: add helper funcs for node tags
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
0fbe392499
commit
cb2e0cd5c7
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -190,19 +191,26 @@ func (node *Node) IsTagged() bool {
|
|||||||
// Currently, this function only handles tags set
|
// Currently, this function only handles tags set
|
||||||
// via CLI ("forced tags" and preauthkeys)
|
// via CLI ("forced tags" and preauthkeys)
|
||||||
func (node *Node) HasTag(tag string) bool {
|
func (node *Node) HasTag(tag string) bool {
|
||||||
if slices.Contains(node.ForcedTags, tag) {
|
return slices.Contains(node.Tags(), tag)
|
||||||
return true
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if node.AuthKey != nil && slices.Contains(node.AuthKey.Tags, tag) {
|
func (node *Node) Tags() []string {
|
||||||
return true
|
var tags []string
|
||||||
|
|
||||||
|
if node.AuthKey != nil {
|
||||||
|
tags = append(tags, node.AuthKey.Tags...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(kradalby): Figure out how tagging should work
|
// TODO(kradalby): Figure out how tagging should work
|
||||||
// and hostinfo.requestedtags.
|
// and hostinfo.requestedtags.
|
||||||
// Do this in other work.
|
// 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 {
|
func (node *Node) RequestTags() []string {
|
||||||
|
Loading…
Reference in New Issue
Block a user