mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-08 00:21:23 +01:00
resolve a remote by id or partial id
This commit is contained in:
parent
c8b8f78249
commit
83974e10dd
@ -126,7 +126,7 @@ func resolveRemoteArg(remoteArg string) (*sstore.RemotePtrType, error) {
|
|||||||
if rrUser != "" {
|
if rrUser != "" {
|
||||||
return nil, fmt.Errorf("remoteusers not supported")
|
return nil, fmt.Errorf("remoteusers not supported")
|
||||||
}
|
}
|
||||||
msh := remote.GetRemoteByName(rrRemote)
|
msh := remote.GetRemoteByArg(rrRemote)
|
||||||
if msh == nil {
|
if msh == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -220,12 +221,22 @@ func ArchiveRemote(ctx context.Context, remoteId string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRemoteByName(name string) *MShellProc {
|
var partialUUIDRe = regexp.MustCompile("^[0-9a-f]{8}$")
|
||||||
|
|
||||||
|
func isPartialUUID(s string) bool {
|
||||||
|
return partialUUIDRe.MatchString(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetRemoteByArg(arg string) *MShellProc {
|
||||||
GlobalStore.Lock.Lock()
|
GlobalStore.Lock.Lock()
|
||||||
defer GlobalStore.Lock.Unlock()
|
defer GlobalStore.Lock.Unlock()
|
||||||
|
isPuid := isPartialUUID(arg)
|
||||||
for _, msh := range GlobalStore.Map {
|
for _, msh := range GlobalStore.Map {
|
||||||
rcopy := msh.GetRemoteCopy()
|
rcopy := msh.GetRemoteCopy()
|
||||||
if rcopy.RemoteAlias == name || rcopy.RemoteCanonicalName == name {
|
if rcopy.RemoteAlias == arg || rcopy.RemoteCanonicalName == arg || rcopy.RemoteId == arg {
|
||||||
|
return msh
|
||||||
|
}
|
||||||
|
if isPuid && strings.HasPrefix(rcopy.RemoteId, arg) {
|
||||||
return msh
|
return msh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user