ipn: add ability to name profiles
Updates #713 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
33520920c3
commit
575fd5f22b
|
@ -53,6 +53,7 @@ var _PrefsCloneNeedsRegeneration = Prefs(struct {
|
|||
NoSNAT bool
|
||||
NetfilterMode preftype.NetfilterMode
|
||||
OperatorUser string
|
||||
ProfileName string
|
||||
Persist *persist.Persist
|
||||
}{})
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ func (v PrefsView) AdvertiseRoutes() views.IPPrefixSlice {
|
|||
func (v PrefsView) NoSNAT() bool { return v.ж.NoSNAT }
|
||||
func (v PrefsView) NetfilterMode() preftype.NetfilterMode { return v.ж.NetfilterMode }
|
||||
func (v PrefsView) OperatorUser() string { return v.ж.OperatorUser }
|
||||
func (v PrefsView) ProfileName() string { return v.ж.ProfileName }
|
||||
func (v PrefsView) Persist() *persist.Persist {
|
||||
if v.ж.Persist == nil {
|
||||
return nil
|
||||
|
@ -116,6 +117,7 @@ var _PrefsViewNeedsRegeneration = Prefs(struct {
|
|||
NoSNAT bool
|
||||
NetfilterMode preftype.NetfilterMode
|
||||
OperatorUser string
|
||||
ProfileName string
|
||||
Persist *persist.Persist
|
||||
}{})
|
||||
|
||||
|
|
|
@ -174,9 +174,13 @@ func (pm *profileManager) SetPrefs(prefsIn ipn.PrefsView) error {
|
|||
}
|
||||
cp.LocalUserID = pm.currentUserID
|
||||
}
|
||||
if prefs.ProfileName() != "" {
|
||||
cp.Name = prefs.ProfileName()
|
||||
} else {
|
||||
cp.Name = up.LoginName
|
||||
}
|
||||
cp.UserProfile = newPersist.UserProfile
|
||||
cp.NodeID = newPersist.NodeID
|
||||
cp.Name = up.LoginName
|
||||
pm.knownProfiles[cp.ID] = cp
|
||||
pm.currentProfile = cp
|
||||
if err := pm.writeKnownProfiles(); err != nil {
|
||||
|
|
|
@ -190,6 +190,11 @@ type Prefs struct {
|
|||
// operate tailscaled without being root or using sudo.
|
||||
OperatorUser string `json:",omitempty"`
|
||||
|
||||
// ProfileName is the desired name of the profile. If empty, then the users
|
||||
// LoginName is used. It is only used for display purposes in the client UI
|
||||
// and CLI.
|
||||
ProfileName string `json:",omitempty"`
|
||||
|
||||
// The Persist field is named 'Config' in the file for backward
|
||||
// compatibility with earlier versions.
|
||||
// TODO(apenwarr): We should move this out of here, it's not a pref.
|
||||
|
@ -222,6 +227,7 @@ type MaskedPrefs struct {
|
|||
NoSNATSet bool `json:",omitempty"`
|
||||
NetfilterModeSet bool `json:",omitempty"`
|
||||
OperatorUserSet bool `json:",omitempty"`
|
||||
ProfileNameSet bool `json:",omitempty"`
|
||||
}
|
||||
|
||||
// ApplyEdits mutates p, assigning fields from m.Prefs for each MaskedPrefs
|
||||
|
@ -406,7 +412,8 @@ func (p *Prefs) Equals(p2 *Prefs) bool {
|
|||
p.ForceDaemon == p2.ForceDaemon &&
|
||||
compareIPNets(p.AdvertiseRoutes, p2.AdvertiseRoutes) &&
|
||||
compareStrings(p.AdvertiseTags, p2.AdvertiseTags) &&
|
||||
p.Persist.Equals(p2.Persist)
|
||||
p.Persist.Equals(p2.Persist) &&
|
||||
p.ProfileName == p2.ProfileName
|
||||
}
|
||||
|
||||
func compareIPNets(a, b []netip.Prefix) bool {
|
||||
|
|
|
@ -56,6 +56,7 @@ func TestPrefsEqual(t *testing.T) {
|
|||
"NoSNAT",
|
||||
"NetfilterMode",
|
||||
"OperatorUser",
|
||||
"ProfileName",
|
||||
"Persist",
|
||||
}
|
||||
if have := fieldsOf(reflect.TypeOf(Prefs{})); !reflect.DeepEqual(have, prefsHandles) {
|
||||
|
@ -272,6 +273,16 @@ func TestPrefsEqual(t *testing.T) {
|
|||
&Prefs{Persist: &persist.Persist{LoginName: "dave"}},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&Prefs{ProfileName: "work"},
|
||||
&Prefs{ProfileName: "work"},
|
||||
true,
|
||||
},
|
||||
{
|
||||
&Prefs{ProfileName: "work"},
|
||||
&Prefs{ProfileName: "home"},
|
||||
false,
|
||||
},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
got := tt.a.Equals(tt.b)
|
||||
|
|
Loading…
Reference in New Issue