mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-09 15:44:33 -04:00
tailcfg,types/netmap: add (visible) Services to SelfNode Caps (#19335)
Updates #40052 Signed-off-by: Adriano Sela Aviles <adriano@tailscale.com>
This commit is contained in:
committed by
GitHub
parent
674f866ecc
commit
4fcce6000d
@@ -146,6 +146,27 @@ func (nm *NetworkMap) GetIPVIPServiceMap() IPServiceMappings {
|
||||
return res
|
||||
}
|
||||
|
||||
// Services returns the Services visible (accessible) to this node,
|
||||
// decoded from [tailcfg.NodeAttrPrefixServices]+serviceName entries in the
|
||||
// self node's CapMap. Returns nil if nm is nil or SelfNode is invalid.
|
||||
func (nm *NetworkMap) Services() map[tailcfg.ServiceName]tailcfg.ServiceDetails {
|
||||
if nm == nil || !nm.SelfNode.Valid() {
|
||||
return nil
|
||||
}
|
||||
result := make(map[tailcfg.ServiceName]tailcfg.ServiceDetails)
|
||||
for cap := range nm.SelfNode.CapMap().All() {
|
||||
if !strings.HasPrefix(string(cap), string(tailcfg.NodeAttrPrefixServices)) {
|
||||
continue
|
||||
}
|
||||
svcs, err := tailcfg.UnmarshalNodeCapViewJSON[tailcfg.ServiceDetails](nm.SelfNode.CapMap(), cap)
|
||||
if err != nil || len(svcs) < 1 {
|
||||
continue
|
||||
}
|
||||
result[svcs[0].Name] = svcs[0]
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// SelfNodeOrZero returns the self node, or a zero value if nm is nil.
|
||||
func (nm *NetworkMap) SelfNodeOrZero() tailcfg.NodeView {
|
||||
if nm == nil {
|
||||
|
||||
Reference in New Issue
Block a user