tailcfg: remove unused User fields

Fixes #14542

Change-Id: Ifeb0f90c570c1b555af761161f79df75f18ae3f9
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2025-01-06 09:54:11 -08:00 committed by Brad Fitzpatrick
parent 5da772c670
commit b90707665e
5 changed files with 20 additions and 33 deletions

View File

@ -234,12 +234,6 @@ type User struct {
DisplayName string // if non-empty overrides Login field DisplayName string // if non-empty overrides Login field
ProfilePicURL string // if non-empty overrides Login field ProfilePicURL string // if non-empty overrides Login field
Created time.Time Created time.Time
// Old, unused fields...
// TODO(bradfitz): remove, once verifying old clients don't need them.
LoginName string `json:"-"` // not stored, filled from Login // TODO REMOVE
Logins []LoginID
} }
// Login is a user from a specific identity provider, not associated with any // Login is a user from a specific identity provider, not associated with any

View File

@ -26,7 +26,6 @@ func (src *User) Clone() *User {
} }
dst := new(User) dst := new(User)
*dst = *src *dst = *src
dst.Logins = append(src.Logins[:0:0], src.Logins...)
return dst return dst
} }
@ -36,8 +35,6 @@ var _UserCloneNeedsRegeneration = User(struct {
DisplayName string DisplayName string
ProfilePicURL string ProfilePicURL string
Created time.Time Created time.Time
LoginName string
Logins []LoginID
}{}) }{})
// Clone makes a deep copy of Node. // Clone makes a deep copy of Node.
@ -302,7 +299,6 @@ func (src *RegisterResponse) Clone() *RegisterResponse {
} }
dst := new(RegisterResponse) dst := new(RegisterResponse)
*dst = *src *dst = *src
dst.User = *src.User.Clone()
dst.NodeKeySignature = append(src.NodeKeySignature[:0:0], src.NodeKeySignature...) dst.NodeKeySignature = append(src.NodeKeySignature[:0:0], src.NodeKeySignature...)
return dst return dst
} }

View File

@ -666,7 +666,6 @@ func TestCloneUser(t *testing.T) {
u *User u *User
}{ }{
{"nil_logins", &User{}}, {"nil_logins", &User{}},
{"zero_logins", &User{Logins: make([]LoginID, 0)}},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View File

@ -70,8 +70,6 @@ func (v UserView) ID() UserID { return v.ж.ID }
func (v UserView) DisplayName() string { return v.ж.DisplayName } func (v UserView) DisplayName() string { return v.ж.DisplayName }
func (v UserView) ProfilePicURL() string { return v.ж.ProfilePicURL } func (v UserView) ProfilePicURL() string { return v.ж.ProfilePicURL }
func (v UserView) Created() time.Time { return v.ж.Created } func (v UserView) Created() time.Time { return v.ж.Created }
func (v UserView) LoginName() string { return v.ж.LoginName }
func (v UserView) Logins() views.Slice[LoginID] { return views.SliceOf(v.ж.Logins) }
// A compilation failure here means this code must be regenerated, with the command at the top of this file. // A compilation failure here means this code must be regenerated, with the command at the top of this file.
var _UserViewNeedsRegeneration = User(struct { var _UserViewNeedsRegeneration = User(struct {
@ -79,8 +77,6 @@ var _UserViewNeedsRegeneration = User(struct {
DisplayName string DisplayName string
ProfilePicURL string ProfilePicURL string
Created time.Time Created time.Time
LoginName string
Logins []LoginID
}{}) }{})
// View returns a readonly view of Node. // View returns a readonly view of Node.
@ -637,7 +633,7 @@ func (v *RegisterResponseView) UnmarshalJSON(b []byte) error {
return nil return nil
} }
func (v RegisterResponseView) User() UserView { return v.ж.User.View() } func (v RegisterResponseView) User() User { return v.ж.User }
func (v RegisterResponseView) Login() Login { return v.ж.Login } func (v RegisterResponseView) Login() Login { return v.ж.Login }
func (v RegisterResponseView) NodeKeyExpired() bool { return v.ж.NodeKeyExpired } func (v RegisterResponseView) NodeKeyExpired() bool { return v.ж.NodeKeyExpired }
func (v RegisterResponseView) MachineAuthorized() bool { return v.ж.MachineAuthorized } func (v RegisterResponseView) MachineAuthorized() bool { return v.ж.MachineAuthorized }

View File

@ -6,6 +6,7 @@ package testcontrol
import ( import (
"bytes" "bytes"
"cmp"
"context" "context"
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
@ -476,13 +477,22 @@ func (s *Server) AddFakeNode() {
// TODO: send updates to other (non-fake?) nodes // TODO: send updates to other (non-fake?) nodes
} }
func (s *Server) AllUsers() (users []*tailcfg.User) { func (s *Server) allUserProfiles() (res []tailcfg.UserProfile) {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
for _, u := range s.users { for k, u := range s.users {
users = append(users, u.Clone()) up := tailcfg.UserProfile{
ID: u.ID,
DisplayName: u.DisplayName,
} }
return users if login, ok := s.logins[k]; ok {
up.LoginName = login.LoginName
up.ProfilePicURL = cmp.Or(up.ProfilePicURL, login.ProfilePicURL)
up.DisplayName = cmp.Or(up.DisplayName, login.DisplayName)
}
res = append(res, up)
}
return res
} }
func (s *Server) AllNodes() (nodes []*tailcfg.Node) { func (s *Server) AllNodes() (nodes []*tailcfg.Node) {
@ -523,9 +533,7 @@ func (s *Server) getUser(nodeKey key.NodePublic) (*tailcfg.User, *tailcfg.Login)
} }
user := &tailcfg.User{ user := &tailcfg.User{
ID: id, ID: id,
LoginName: loginName,
DisplayName: displayName, DisplayName: displayName,
Logins: []tailcfg.LoginID{login.ID},
} }
s.users[nodeKey] = user s.users[nodeKey] = user
s.logins[nodeKey] = login s.logins[nodeKey] = login
@ -1001,13 +1009,7 @@ func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse,
sort.Slice(res.Peers, func(i, j int) bool { sort.Slice(res.Peers, func(i, j int) bool {
return res.Peers[i].ID < res.Peers[j].ID return res.Peers[i].ID < res.Peers[j].ID
}) })
for _, u := range s.AllUsers() { res.UserProfiles = s.allUserProfiles()
res.UserProfiles = append(res.UserProfiles, tailcfg.UserProfile{
ID: u.ID,
LoginName: u.LoginName,
DisplayName: u.DisplayName,
})
}
v4Prefix := netip.PrefixFrom(netaddr.IPv4(100, 64, uint8(tailcfg.NodeID(user.ID)>>8), uint8(tailcfg.NodeID(user.ID))), 32) v4Prefix := netip.PrefixFrom(netaddr.IPv4(100, 64, uint8(tailcfg.NodeID(user.ID)>>8), uint8(tailcfg.NodeID(user.ID))), 32)
v6Prefix := netip.PrefixFrom(tsaddr.Tailscale4To6(v4Prefix.Addr()), 128) v6Prefix := netip.PrefixFrom(tsaddr.Tailscale4To6(v4Prefix.Addr()), 128)