mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-12 05:37:32 +00:00
cmd/tailscale/cli: add ability to set short names for profiles
This adds a `--nickname` flag to `tailscale login|set`. Updates #713 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
@@ -2109,6 +2109,9 @@ func (b *LocalBackend) checkPrefsLocked(p *ipn.Prefs) error {
|
||||
// Keep this one just for testing.
|
||||
errs = append(errs, errors.New("bad hostname [test]"))
|
||||
}
|
||||
if err := b.checkProfileNameLocked(p); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
if err := b.checkSSHPrefsLocked(p); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
@@ -2226,6 +2229,23 @@ func (b *LocalBackend) EditPrefs(mp *ipn.MaskedPrefs) (ipn.PrefsView, error) {
|
||||
return stripKeysFromPrefs(newPrefs), nil
|
||||
}
|
||||
|
||||
func (b *LocalBackend) checkProfileNameLocked(p *ipn.Prefs) error {
|
||||
if p.ProfileName == "" {
|
||||
// It is always okay to clear the profile name.
|
||||
return nil
|
||||
}
|
||||
id := b.pm.ProfileIDForName(p.ProfileName)
|
||||
if id == "" {
|
||||
// No profile with that name exists. That's fine.
|
||||
return nil
|
||||
}
|
||||
if id != b.pm.CurrentProfile().ID {
|
||||
// Name is already in use by another profile.
|
||||
return fmt.Errorf("profile name %q already in use", p.ProfileName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetPrefs saves new user preferences and propagates them throughout
|
||||
// the system. Implements Backend.
|
||||
func (b *LocalBackend) SetPrefs(newp *ipn.Prefs) {
|
||||
|
@@ -96,6 +96,16 @@ func (pm *profileManager) findProfilesByUserID(userID tailcfg.UserID) []*ipn.Log
|
||||
return out
|
||||
}
|
||||
|
||||
// ProfileIDForName returns the profile ID for the profile with the
|
||||
// given name. It returns "" if no such profile exists.
|
||||
func (pm *profileManager) ProfileIDForName(name string) ipn.ProfileID {
|
||||
p := pm.findProfileByName(name)
|
||||
if p == nil {
|
||||
return ""
|
||||
}
|
||||
return p.ID
|
||||
}
|
||||
|
||||
func (pm *profileManager) findProfileByName(name string) *ipn.LoginProfile {
|
||||
for _, p := range pm.knownProfiles {
|
||||
if p.Name == name {
|
||||
|
Reference in New Issue
Block a user