feat: add invalid and valid tags to grpc response

This commit is contained in:
Adrien Raffin-Caboisse 2022-04-16 12:20:58 +02:00
parent 587bdc75de
commit db1528bc73
No known key found for this signature in database
GPG key ID: 7FB60532DEBEAD6A
2 changed files with 37 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package headscale
import (
"database/sql/driver"
"errors"
"fmt"
"sort"
"strconv"
@ -660,6 +661,37 @@ func (machine *Machine) toProto() *v1.Machine {
return machineProto
}
// getTags will return the tags of the current machine
func getTags(aclPolicy ACLPolicy, machine Machine, stripEmailDomain bool) (validTags []string, invalidTags []string) {
validTagMap := make(map[string]bool)
invalidTagMap := make(map[string]bool)
for _, tag := range machine.HostInfo.RequestTags {
owners, err := expandTagOwners(aclPolicy, tag, stripEmailDomain)
if errors.Is(err, errInvalidTag) {
invalidTags = append(invalidTags, tag)
}
var found bool
for _, owner := range owners {
if machine.Namespace.Name == owner {
found = true
}
}
if found {
validTagMap[tag] = true
} else {
invalidTagMap[tag] = true
}
}
for tag := range invalidTagMap {
invalidTags = append(invalidTags, tag)
}
for tag := range validTagMap {
validTags = append(validTags, tag)
}
return
}
func (h *Headscale) RegisterMachineFromAuthCallback(
machineKeyStr string,
namespaceName string,