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

20
api.go
View file

@ -9,7 +9,6 @@ import (
"net/http"
"time"
"github.com/fatih/set"
"github.com/rs/zerolog/log"
"github.com/gin-gonic/gin"
@ -415,22 +414,3 @@ func (h *Headscale) handleAuthKey(c *gin.Context, db *gorm.DB, idKey wgkey.Key,
Str("ip", ip.String()).
Msg("Successfully authenticated via AuthKey")
}
func getMapResponseUserProfiles(m Machine, peers Machines) []tailcfg.UserProfile {
namespaceSet := set.New(set.ThreadSafe)
namespaceSet.Add(m.Namespace)
for _, p := range peers {
namespaceSet.Add(p.Namespace)
}
profiles := []tailcfg.UserProfile{}
for _, namespace := range namespaceSet.List() {
profiles = append(profiles,
tailcfg.UserProfile{
ID: tailcfg.UserID(namespace.(Namespace).ID),
LoginName: namespace.(Namespace).Name,
DisplayName: namespace.(Namespace).Name,
})
}
return profiles
}