From 6422cdf576e624022d735ca732314565b03e6412 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 25 Nov 2024 10:03:34 +0100 Subject: [PATCH] add users string method Signed-off-by: Kristoffer Dalby --- hscontrol/types/users.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/hscontrol/types/users.go b/hscontrol/types/users.go index 60fbbeda..688e90ec 100644 --- a/hscontrol/types/users.go +++ b/hscontrol/types/users.go @@ -3,8 +3,10 @@ package types import ( "cmp" "database/sql" + "fmt" "net/mail" "strconv" + "strings" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/juanfont/headscale/hscontrol/util" @@ -15,6 +17,19 @@ import ( type UserID uint64 +type Users []User + +func (u Users) String() string { + var sb strings.Builder + sb.WriteString("[ ") + for _, user := range u { + fmt.Fprintf(&sb, "%d: %s, ", user.ID, user.Name) + } + sb.WriteString(" ]") + + return sb.String() +} + // User is the way Headscale implements the concept of users in Tailscale // // At the end of the day, users in Tailscale are some kind of 'bubbles' or users @@ -57,7 +72,12 @@ type User struct { // should be used throughout headscale, in information returned to the // user and the Policy engine. func (u *User) Username() string { - return cmp.Or(u.Email, u.Name, u.ProviderIdentifier.String, strconv.FormatUint(uint64(u.ID), 10)) + return cmp.Or( + u.Email, + u.Name, + u.ProviderIdentifier.String, + strconv.FormatUint(uint64(u.ID), 10), + ) } // DisplayNameOrUsername returns the DisplayName if it exists, otherwise