mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-02 01:51:59 +00:00
ipn/ipnlocal: add support for multiple user profiles
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
@@ -8,6 +8,7 @@ package persist
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/structs"
|
||||
)
|
||||
@@ -34,6 +35,7 @@ type Persist struct {
|
||||
OldPrivateNodeKey key.NodePrivate // needed to request key rotation
|
||||
Provider string
|
||||
LoginName string
|
||||
UserProfile tailcfg.UserProfile
|
||||
}
|
||||
|
||||
// PublicNodeKey returns the public key for the node key.
|
||||
@@ -53,7 +55,8 @@ func (p *Persist) Equals(p2 *Persist) bool {
|
||||
p.PrivateNodeKey.Equal(p2.PrivateNodeKey) &&
|
||||
p.OldPrivateNodeKey.Equal(p2.OldPrivateNodeKey) &&
|
||||
p.Provider == p2.Provider &&
|
||||
p.LoginName == p2.LoginName
|
||||
p.LoginName == p2.LoginName &&
|
||||
p.UserProfile == p2.UserProfile
|
||||
}
|
||||
|
||||
func (p *Persist) Pretty() string {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
package persist
|
||||
|
||||
import (
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/structs"
|
||||
)
|
||||
@@ -30,4 +31,5 @@ var _PersistCloneNeedsRegeneration = Persist(struct {
|
||||
OldPrivateNodeKey key.NodePrivate
|
||||
Provider string
|
||||
LoginName string
|
||||
UserProfile tailcfg.UserProfile
|
||||
}{})
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
)
|
||||
|
||||
@@ -21,7 +22,7 @@ func fieldsOf(t reflect.Type) (fields []string) {
|
||||
}
|
||||
|
||||
func TestPersistEqual(t *testing.T) {
|
||||
persistHandles := []string{"LegacyFrontendPrivateMachineKey", "PrivateNodeKey", "OldPrivateNodeKey", "Provider", "LoginName"}
|
||||
persistHandles := []string{"LegacyFrontendPrivateMachineKey", "PrivateNodeKey", "OldPrivateNodeKey", "Provider", "LoginName", "UserProfile"}
|
||||
if have := fieldsOf(reflect.TypeOf(Persist{})); !reflect.DeepEqual(have, persistHandles) {
|
||||
t.Errorf("Persist.Equal check might be out of sync\nfields: %q\nhandled: %q\n",
|
||||
have, persistHandles)
|
||||
@@ -92,6 +93,25 @@ func TestPersistEqual(t *testing.T) {
|
||||
&Persist{LoginName: "foo@tailscale.com"},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&Persist{UserProfile: tailcfg.UserProfile{
|
||||
ID: tailcfg.UserID(3),
|
||||
}},
|
||||
&Persist{UserProfile: tailcfg.UserProfile{
|
||||
ID: tailcfg.UserID(3),
|
||||
}},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&Persist{UserProfile: tailcfg.UserProfile{
|
||||
ID: tailcfg.UserID(3),
|
||||
}},
|
||||
&Persist{UserProfile: tailcfg.UserProfile{
|
||||
ID: tailcfg.UserID(3),
|
||||
DisplayName: "foo",
|
||||
}},
|
||||
false,
|
||||
},
|
||||
}
|
||||
for i, test := range tests {
|
||||
if got := test.a.Equals(test.b); got != test.want {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/structs"
|
||||
)
|
||||
@@ -68,6 +69,7 @@ func (v PersistView) PrivateNodeKey() key.NodePrivate { return v.ж.PrivateNo
|
||||
func (v PersistView) OldPrivateNodeKey() key.NodePrivate { return v.ж.OldPrivateNodeKey }
|
||||
func (v PersistView) Provider() string { return v.ж.Provider }
|
||||
func (v PersistView) LoginName() string { return v.ж.LoginName }
|
||||
func (v PersistView) UserProfile() tailcfg.UserProfile { return v.ж.UserProfile }
|
||||
|
||||
// A compilation failure here means this code must be regenerated, with the command at the top of this file.
|
||||
var _PersistViewNeedsRegeneration = Persist(struct {
|
||||
@@ -77,4 +79,5 @@ var _PersistViewNeedsRegeneration = Persist(struct {
|
||||
OldPrivateNodeKey key.NodePrivate
|
||||
Provider string
|
||||
LoginName string
|
||||
UserProfile tailcfg.UserProfile
|
||||
}{})
|
||||
|
||||
Reference in New Issue
Block a user