mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-11 07:59:08 +02:00
Change resolve handle order and fix server merge problems
This commit is contained in:
@@ -575,8 +575,8 @@ func (s *ServiceManager) activeProfileID() (ID, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ResolveProfile turns a user-supplied handle into a Profile. Resolution
|
// ResolveProfile turns a user-supplied handle into a Profile. Resolution
|
||||||
// precedence is: exact ID match, then unique ID prefix, then unique exact
|
// precedence is: exact ID match, then unique exact name, then unique ID
|
||||||
// name. Ambiguous matches return *ErrAmbiguousHandle so callers can
|
// prefix. Ambiguous matches return *ErrAmbiguousHandle so callers can
|
||||||
// surface the candidates.
|
// surface the candidates.
|
||||||
func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, error) {
|
func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, error) {
|
||||||
if handle == "" {
|
if handle == "" {
|
||||||
@@ -594,6 +594,23 @@ func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nameMatches []Profile
|
||||||
|
for i := range profiles {
|
||||||
|
if profiles[i].Name == handle {
|
||||||
|
nameMatches = append(nameMatches, profiles[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(nameMatches) == 1 {
|
||||||
|
return &nameMatches[0], nil
|
||||||
|
}
|
||||||
|
if len(nameMatches) > 1 {
|
||||||
|
return nil, &ErrAmbiguousHandle{
|
||||||
|
Handle: handle,
|
||||||
|
Candidates: nameMatches,
|
||||||
|
Kind: AmbiguityKindName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ID prefix match. Skip the default profile so `select d` does not
|
// ID prefix match. Skip the default profile so `select d` does not
|
||||||
// accidentally pick it via prefix.
|
// accidentally pick it via prefix.
|
||||||
var prefixMatches []Profile
|
var prefixMatches []Profile
|
||||||
@@ -616,22 +633,5 @@ func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var nameMatches []Profile
|
|
||||||
for i := range profiles {
|
|
||||||
if profiles[i].Name == handle {
|
|
||||||
nameMatches = append(nameMatches, profiles[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(nameMatches) == 1 {
|
|
||||||
return &nameMatches[0], nil
|
|
||||||
}
|
|
||||||
if len(nameMatches) > 1 {
|
|
||||||
return nil, &ErrAmbiguousHandle{
|
|
||||||
Handle: handle,
|
|
||||||
Candidates: nameMatches,
|
|
||||||
Kind: AmbiguityKindName,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, ErrProfileNotFound
|
return nil, ErrProfileNotFound
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ type Server struct {
|
|||||||
// changed by connectWithRetryRuns goroutine exit — for that
|
// changed by connectWithRetryRuns goroutine exit — for that
|
||||||
// (goroutine-still-alive) check, see connectionGoroutineRunning() which
|
// (goroutine-still-alive) check, see connectionGoroutineRunning() which
|
||||||
// derives from clientGiveUpChan close state. Protected by s.mutex.
|
// derives from clientGiveUpChan close state. Protected by s.mutex.
|
||||||
clientRunning bool
|
clientRunning bool
|
||||||
clientRunningChan chan struct{}
|
clientRunningChan chan struct{}
|
||||||
clientGiveUpChan chan struct{} // closed when connectWithRetryRuns goroutine exits
|
clientGiveUpChan chan struct{} // closed when connectWithRetryRuns goroutine exits
|
||||||
|
|
||||||
@@ -375,7 +375,7 @@ func (s *Server) SetConfig(callerCtx context.Context, msg *proto.SetConfigReques
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := setConfigInputFromRequest(msg)
|
config, err := s.setConfigInputFromRequest(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -398,17 +398,18 @@ func (s *Server) SetConfig(callerCtx context.Context, msg *proto.SetConfigReques
|
|||||||
// field is its own optional case. Returns the resolved ConfigInput
|
// field is its own optional case. Returns the resolved ConfigInput
|
||||||
// and a non-nil error only when the active profile file path cannot
|
// and a non-nil error only when the active profile file path cannot
|
||||||
// be determined.
|
// be determined.
|
||||||
func setConfigInputFromRequest(msg *proto.SetConfigRequest) (profilemanager.ConfigInput, error) {
|
func (s *Server) setConfigInputFromRequest(msg *proto.SetConfigRequest) (profilemanager.ConfigInput, error) {
|
||||||
var config profilemanager.ConfigInput
|
var config profilemanager.ConfigInput
|
||||||
|
|
||||||
resolved, err := s.resolveProfileHandle(msg.ProfileName, msg.Username)
|
resolved, err := s.resolveProfileHandle(msg.ProfileName, msg.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed to resolve profile %q: %v", msg.ProfileName, err)
|
log.Errorf("failed to resolve profile %q: %v", msg.ProfileName, err)
|
||||||
return nil, err
|
return config, err
|
||||||
}
|
}
|
||||||
profPath := resolved.Path
|
profPath := resolved.Path
|
||||||
if profPath == "" {
|
if profPath == "" {
|
||||||
profPath = profilemanager.DefaultConfigPath
|
profPath = profilemanager.DefaultConfigPath
|
||||||
|
}
|
||||||
config.ConfigPath = profPath
|
config.ConfigPath = profPath
|
||||||
|
|
||||||
if msg.ManagementUrl != "" {
|
if msg.ManagementUrl != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user