Added tests, solved some bugs, and code reorg

This commit is contained in:
Juan Font Alonso
2021-10-17 23:58:09 +02:00
parent 687e8d12be
commit 01a5fe3c51
5 changed files with 389 additions and 23 deletions

View File

@@ -216,3 +216,22 @@ func (n *Namespace) toUser() *tailcfg.User {
}
return &u
}
func getMapResponseUserProfiles(m Machine, peers Machines) []tailcfg.UserProfile {
namespaceMap := make(map[string]Namespace)
namespaceMap[m.Namespace.Name] = m.Namespace
for _, p := range peers {
namespaceMap[p.Namespace.Name] = p.Namespace // not worth checking if already is there
}
profiles := []tailcfg.UserProfile{}
for _, namespace := range namespaceMap {
profiles = append(profiles,
tailcfg.UserProfile{
ID: tailcfg.UserID(namespace.ID),
LoginName: namespace.Name,
DisplayName: namespace.Name,
})
}
return profiles
}