-
-
Notifications
You must be signed in to change notification settings - Fork 800
RemoteInfo Rpc #1719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RemoteInfo Rpc #1719
Changes from all commits
112780a
7a67309
3078c2a
ec1d2b0
c964a60
a36b5d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |
| "time" | ||
|
|
||
| "github.com/creack/pty" | ||
| "github.com/wavetermdev/waveterm/pkg/genconn" | ||
| "github.com/wavetermdev/waveterm/pkg/panichandler" | ||
| "github.com/wavetermdev/waveterm/pkg/remote" | ||
| "github.com/wavetermdev/waveterm/pkg/remote/conncontroller" | ||
|
|
@@ -27,6 +28,8 @@ import ( | |
| "github.com/wavetermdev/waveterm/pkg/util/utilfn" | ||
| "github.com/wavetermdev/waveterm/pkg/wavebase" | ||
| "github.com/wavetermdev/waveterm/pkg/waveobj" | ||
| "github.com/wavetermdev/waveterm/pkg/wshrpc" | ||
| "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" | ||
| "github.com/wavetermdev/waveterm/pkg/wshutil" | ||
| "github.com/wavetermdev/waveterm/pkg/wsl" | ||
| ) | ||
|
|
@@ -286,41 +289,46 @@ func StartRemoteShellProcNoWsh(termSize waveobj.TermSize, cmdStr string, cmdOpts | |
|
|
||
| func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts CommandOptsType, conn *conncontroller.SSHConn) (*ShellProc, error) { | ||
| client := conn.GetClient() | ||
| connRoute := wshutil.MakeConnectionRouteId(conn.GetName()) | ||
| rpcClient := wshclient.GetBareRpcClient() | ||
| remoteInfo, err := wshclient.RemoteGetInfoCommand(rpcClient, &wshrpc.RpcOpts{Route: connRoute, Timeout: 2000}) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to obtain client info: %w", err) | ||
| } | ||
| log.Printf("client info collected: %+#v", remoteInfo) | ||
|
|
||
| shellPath := cmdOpts.ShellPath | ||
| if shellPath == "" { | ||
| remoteShellPath, err := remote.DetectShell(client) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| shellPath = remoteShellPath | ||
| shellPath = remoteInfo.Shell | ||
| } | ||
| var shellOpts []string | ||
| var cmdCombined string | ||
| log.Printf("detected shell: %s", shellPath) | ||
| log.Printf("using shell: %s", shellPath) | ||
|
|
||
| err := remote.InstallClientRcFiles(client) | ||
| err = remote.InstallClientRcFiles(client) | ||
| if err != nil { | ||
| log.Printf("error installing rc files: %v", err) | ||
| return nil, err | ||
| } | ||
| shellOpts = append(shellOpts, cmdOpts.ShellOpts...) | ||
|
|
||
| homeDir := remote.GetHomeDir(client) | ||
|
|
||
| if cmdStr == "" { | ||
| /* transform command in order to inject environment vars */ | ||
| if isBashShell(shellPath) { | ||
| log.Printf("recognized as bash shell") | ||
| // add --rcfile | ||
| // cant set -l or -i with --rcfile | ||
| shellOpts = append(shellOpts, "--rcfile", fmt.Sprintf(`"%s"/.waveterm/%s/.bashrc`, homeDir, shellutil.BashIntegrationDir)) | ||
| bashPath := genconn.SoftQuote(fmt.Sprintf("~/.waveterm/%s/.bashrc", shellutil.BashIntegrationDir)) | ||
| shellOpts = append(shellOpts, "--rcfile", bashPath) | ||
| } else if isFishShell(shellPath) { | ||
| carg := fmt.Sprintf(`"set -x PATH \"%s\"/.waveterm/%s $PATH"`, homeDir, shellutil.WaveHomeBinDir) | ||
| fishDir := genconn.SoftQuote(fmt.Sprintf("~/.waveterm/%s", shellutil.WaveHomeBinDir)) | ||
| carg := fmt.Sprintf(`"set -x PATH %s $PATH"`, fishDir) | ||
| shellOpts = append(shellOpts, "-C", carg) | ||
| } else if remote.IsPowershell(shellPath) { | ||
| pwshPath := genconn.SoftQuote(fmt.Sprintf("~/.waveterm/%s/wavepwsh.ps1", shellutil.PwshIntegrationDir)) | ||
| // powershell is weird about quoted path executables and requires an ampersand first | ||
| shellPath = "& " + shellPath | ||
| shellOpts = append(shellOpts, "-ExecutionPolicy", "Bypass", "-NoExit", "-File", fmt.Sprintf("%s/.waveterm/%s/wavepwsh.ps1", homeDir, shellutil.PwshIntegrationDir)) | ||
| shellOpts = append(shellOpts, "-ExecutionPolicy", "Bypass", "-NoExit", "-File", pwshPath) | ||
| } else { | ||
| if cmdOpts.Login { | ||
| shellOpts = append(shellOpts, "-l") | ||
|
|
@@ -374,7 +382,8 @@ func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts Comm | |
| } | ||
|
|
||
| if isZshShell(shellPath) { | ||
| cmdCombined = fmt.Sprintf(`ZDOTDIR="%s/.waveterm/%s" %s`, homeDir, shellutil.ZshIntegrationDir, cmdCombined) | ||
| zshDir := genconn.SoftQuote(fmt.Sprintf("~/.waveterm/%s", shellutil.ZshIntegrationDir)) | ||
| cmdCombined = fmt.Sprintf(`ZDOTDIR=%s %s`, zshDir, cmdCombined) | ||
|
Comment on lines
+385
to
+386
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Environment Variable Setting Apply this diff to set for envKey, envVal := range cmdOpts.Env {
// note these might fail depending on server settings, but we still try
session.Setenv(envKey, envVal)
}
+ if isZshShell(shellPath) {
+ zshDir := genconn.SoftQuote(fmt.Sprintf("~/.waveterm/%s", shellutil.ZshIntegrationDir))
+ session.Setenv("ZDOTDIR", zshDir)
+ }
jwtToken, ok := cmdOpts.Env[wshutil.WaveJwtTokenVarName]
if !ok {
return nil, fmt.Errorf("no jwt token provided to connection")
|
||
| } | ||
|
|
||
| jwtToken, ok := cmdOpts.Env[wshutil.WaveJwtTokenVarName] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import ( | |
| "os" | ||
| "os/signal" | ||
| "runtime" | ||
| "strings" | ||
| "sync" | ||
| "sync/atomic" | ||
| "syscall" | ||
|
|
@@ -22,6 +23,7 @@ import ( | |
| "github.com/google/uuid" | ||
| "github.com/wavetermdev/waveterm/pkg/panichandler" | ||
| "github.com/wavetermdev/waveterm/pkg/util/packetparser" | ||
| "github.com/wavetermdev/waveterm/pkg/util/shellutil" | ||
| "github.com/wavetermdev/waveterm/pkg/wavebase" | ||
| "github.com/wavetermdev/waveterm/pkg/wshrpc" | ||
| "golang.org/x/term" | ||
|
|
@@ -538,13 +540,24 @@ func ExtractUnverifiedSocketName(tokenStr string) (string, error) { | |
| return sockName, nil | ||
| } | ||
|
|
||
| func GetInfo(rpcContext wshrpc.RpcContext) wshrpc.RemoteInfo { | ||
| func getShell() string { | ||
| if runtime.GOOS == "darwin" { | ||
| return shellutil.GetMacUserShell() | ||
| } | ||
|
|
||
| shell := os.Getenv("SHELL") | ||
| if shell == "" { | ||
| return "/bin/bash" | ||
| } | ||
| return strings.TrimSpace(shell) | ||
| } | ||
|
|
||
| func GetInfo() wshrpc.RemoteInfo { | ||
| return wshrpc.RemoteInfo{ | ||
| ConnName: rpcContext.Conn, | ||
| ClientArch: runtime.GOARCH, | ||
| ClientOs: runtime.GOOS, | ||
| ClientVersion: wavebase.WaveVersion, | ||
| Shell: os.Getenv("SHELL"), | ||
| Shell: getShell(), | ||
| } | ||
|
|
||
|
Comment on lines
+555
to
562
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Shell path existence verification needed The review comment is valid. The code assumes shell paths exist without verification:
Suggested locations to add verification:
🔗 Analysis chainVerify shell path existence. The shell path returned by Run this script to verify the shell paths: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify that the default shell paths exist
# Test: Check if common shell paths exist
echo "Checking default shell paths..."
for shell in "/bin/bash" "/bin/sh" "/bin/zsh"; do
if [ -f "$shell" ]; then
echo "Found: $shell"
else
echo "Missing: $shell"
fi
done
# Test: Check if GetMacUserShell is properly implemented
echo "Checking for shellutil.GetMacUserShell implementation..."
rg -A 5 "func GetMacUserShell"
Length of output: 911 Script: #!/bin/bash
# Find getShell implementation and its dependencies
ast-grep --pattern 'func getShell()' -l go
rg -A 10 'func getShell\(\)'
# Check for shell path validation
rg -i 'exists|stat|isfile|filepath' pkg/wshutil/
Length of output: 1817 Script: #!/bin/bash
# Check GetMacUserShell implementation
rg -A 15 'func internalMacUserShell' pkg/util/shellutil/
Length of output: 1094 Script: #!/bin/bash
# Check DefaultShellPath constant
rg "DefaultShellPath\s*=" pkg/util/shellutil/
Length of output: 116 |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Handle Potential Errors Gracefully
After modifying the
GetInfofunction call, ensure that any potential errors are handled appropriately, and provide informative error messages to aid in troubleshooting.Consider checking for errors and updating the error handling logic if necessary.