diff --git a/api_common.go b/api_common.go index b4983cc..9e7ff48 100644 --- a/api_common.go +++ b/api_common.go @@ -35,7 +35,7 @@ func (h *Headscale) generateMapResponse( return nil, err } - profiles := getMapResponseUserProfiles(*machine, peers) + profiles := h.getMapResponseUserProfiles(*machine, peers) nodePeers, err := peers.toNodes(h.cfg.BaseDomain, h.cfg.DNSConfig) if err != nil { diff --git a/namespaces.go b/namespaces.go index d169881..87d319c 100644 --- a/namespaces.go +++ b/namespaces.go @@ -211,7 +211,10 @@ func (n *Namespace) toLogin() *tailcfg.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[machine.Namespace.Name] = machine.Namespace for _, peer := range peers { @@ -220,11 +223,17 @@ func getMapResponseUserProfiles(machine Machine, peers Machines) []tailcfg.UserP profiles := []tailcfg.UserProfile{} for _, namespace := range namespaceMap { + displayName := namespace.Name + + if h.cfg.BaseDomain != "" { + displayName = fmt.Sprintf("%s@%s", namespace.Name, h.cfg.BaseDomain) + } + profiles = append(profiles, tailcfg.UserProfile{ ID: tailcfg.UserID(namespace.ID), LoginName: namespace.Name, - DisplayName: namespace.Name, + DisplayName: displayName, }) } diff --git a/namespaces_test.go b/namespaces_test.go index f990724..f88cc8f 100644 --- a/namespaces_test.go +++ b/namespaces_test.go @@ -209,7 +209,7 @@ func (s *Suite) TestGetMapResponseUserProfiles(c *check.C) { peersOfMachine1InShared1, err := app.getPeers(machineInShared1) c.Assert(err, check.IsNil) - userProfiles := getMapResponseUserProfiles( + userProfiles := app.getMapResponseUserProfiles( *machineInShared1, peersOfMachine1InShared1, )