ipn/ipnlocal: add support for multiple user profiles

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2022-11-09 10:58:10 +05:00
committed by Maisem Ali
parent c9d6a9cb4d
commit 4d330bac14
29 changed files with 1106 additions and 436 deletions

View File

@@ -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 {

View File

@@ -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
}{})

View File

@@ -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 {

View File

@@ -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
}{})