mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-20 19:09:07 +01:00
feat: add invalid and valid tags to grpc response
This commit is contained in:
parent
587bdc75de
commit
db1528bc73
@ -280,7 +280,11 @@ func (api headscaleV1APIServer) ListMachines(
|
|||||||
|
|
||||||
response := make([]*v1.Machine, len(machines))
|
response := make([]*v1.Machine, len(machines))
|
||||||
for index, machine := range machines {
|
for index, machine := range machines {
|
||||||
response[index] = machine.toProto()
|
m := machine.toProto()
|
||||||
|
validTags, invalidTags := getTags(*api.h.aclPolicy, machine, api.h.cfg.OIDC.StripEmaildomain)
|
||||||
|
m.InvalidTags = invalidTags
|
||||||
|
m.ValidTags = validTags
|
||||||
|
response[index] = m
|
||||||
}
|
}
|
||||||
|
|
||||||
return &v1.ListMachinesResponse{Machines: response}, nil
|
return &v1.ListMachinesResponse{Machines: response}, nil
|
||||||
|
32
machine.go
32
machine.go
@ -2,6 +2,7 @@ package headscale
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql/driver"
|
"database/sql/driver"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -660,6 +661,37 @@ func (machine *Machine) toProto() *v1.Machine {
|
|||||||
return machineProto
|
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(
|
func (h *Headscale) RegisterMachineFromAuthCallback(
|
||||||
machineKeyStr string,
|
machineKeyStr string,
|
||||||
namespaceName string,
|
namespaceName string,
|
||||||
|
Loading…
Reference in New Issue
Block a user