Make displayName include basedomain if set

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2022-11-22 17:36:19 +01:00 committed by Juan Font
parent e7f322b9b6
commit 99e33181b2
3 changed files with 13 additions and 4 deletions

View File

@ -35,7 +35,7 @@ func (h *Headscale) generateMapResponse(
return nil, err return nil, err
} }
profiles := getMapResponseUserProfiles(*machine, peers) profiles := h.getMapResponseUserProfiles(*machine, peers)
nodePeers, err := peers.toNodes(h.cfg.BaseDomain, h.cfg.DNSConfig) nodePeers, err := peers.toNodes(h.cfg.BaseDomain, h.cfg.DNSConfig)
if err != nil { if err != nil {

View File

@ -211,7 +211,10 @@ func (n *Namespace) toLogin() *tailcfg.Login {
return &login return &login
} }
func getMapResponseUserProfiles(machine Machine, peers Machines) []tailcfg.UserProfile { func (h *Headscale) getMapResponseUserProfiles(
machine Machine,
peers Machines,
) []tailcfg.UserProfile {
namespaceMap := make(map[string]Namespace) namespaceMap := make(map[string]Namespace)
namespaceMap[machine.Namespace.Name] = machine.Namespace namespaceMap[machine.Namespace.Name] = machine.Namespace
for _, peer := range peers { for _, peer := range peers {
@ -220,11 +223,17 @@ func getMapResponseUserProfiles(machine Machine, peers Machines) []tailcfg.UserP
profiles := []tailcfg.UserProfile{} profiles := []tailcfg.UserProfile{}
for _, namespace := range namespaceMap { for _, namespace := range namespaceMap {
displayName := namespace.Name
if h.cfg.BaseDomain != "" {
displayName = fmt.Sprintf("%s@%s", namespace.Name, h.cfg.BaseDomain)
}
profiles = append(profiles, profiles = append(profiles,
tailcfg.UserProfile{ tailcfg.UserProfile{
ID: tailcfg.UserID(namespace.ID), ID: tailcfg.UserID(namespace.ID),
LoginName: namespace.Name, LoginName: namespace.Name,
DisplayName: namespace.Name, DisplayName: displayName,
}) })
} }

View File

@ -209,7 +209,7 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) {
peersOfMachine1InShared1, err := app.getPeers(machineInShared1) peersOfMachine1InShared1, err := app.getPeers(machineInShared1)
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)
userProfiles := getMapResponseUserProfiles( userProfiles := app.getMapResponseUserProfiles(
*machineInShared1, *machineInShared1,
peersOfMachine1InShared1, peersOfMachine1InShared1,
) )