This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Warn if coder-cli is not in PATH on Windows #357
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2b838a9
Enforce coder-cli in PATH on Windows
deansheather 74b7fa4
Warn if coder-cli not in PATH on Windows
deansheather 4a7aca7
Use safeexec to get windows path
deansheather 3746bf5
Delete GOARCH=386 from windows build
deansheather 5da2fc0
Add comment to unset GOARCH
deansheather File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,13 @@ import ( | |
"sort" | ||
"strings" | ||
|
||
"cdr.dev/coder-cli/pkg/clog" | ||
|
||
"github.com/cli/safeexec" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/xerrors" | ||
|
||
"cdr.dev/coder-cli/coder-sdk" | ||
"cdr.dev/coder-cli/internal/coderutil" | ||
"cdr.dev/coder-cli/pkg/clog" | ||
) | ||
|
||
const sshStartToken = "# ------------START-CODER-ENTERPRISE-----------" | ||
|
@@ -114,7 +114,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st | |
return xerrors.New("SSH is disabled or not available for any workspaces in your Coder deployment.") | ||
} | ||
|
||
binPath, err := os.Executable() | ||
binPath, err := binPath() | ||
if err != nil { | ||
return xerrors.Errorf("Failed to get executable path: %w", err) | ||
} | ||
|
@@ -147,6 +147,53 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st | |
} | ||
} | ||
|
||
// binPath returns the path to the coder binary suitable for use in ssh | ||
// ProxyCommand. | ||
func binPath() (string, error) { | ||
exePath, err := os.Executable() | ||
if err != nil { | ||
return "", xerrors.Errorf("get executable path: %w", err) | ||
} | ||
|
||
// On Windows, the coder-cli executable must be in $PATH for both Msys2/Git | ||
// Bash and OpenSSH for Windows (used by Powershell and VS Code) to function | ||
// correctly. Check if the current executable is in $PATH, and warn the user | ||
// if it isn't. | ||
if runtime.GOOS == "windows" { | ||
binName := filepath.Base(exePath) | ||
|
||
// We use safeexec instead of os/exec because os/exec returns paths in | ||
// the current working directory, which we will run into very often when | ||
// looking for our own path. | ||
pathPath, err := safeexec.LookPath(binName) | ||
deansheather marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
clog.LogWarn( | ||
"The current executable is not in $PATH.", | ||
"This may lead to problems connecting to your workspace via SSH.", | ||
fmt.Sprintf("Please move %q to a location in your $PATH (such as System32) and run `%s config-ssh` again.", binName, binName), | ||
) | ||
// Return the exePath so SSH at least works outside of Msys2. | ||
return exePath, nil | ||
} | ||
|
||
// Warn the user if the current executable is not the same as the one in | ||
// $PATH. | ||
if filepath.Clean(pathPath) != filepath.Clean(exePath) { | ||
clog.LogWarn( | ||
"The current executable path does not match the executable path found in $PATH.", | ||
"This may lead to problems connecting to your workspace via SSH.", | ||
fmt.Sprintf("\t Current executable path: %q", exePath), | ||
fmt.Sprintf("\tExecutable path in $PATH: %q", pathPath), | ||
) | ||
} | ||
|
||
return binName, nil | ||
} | ||
|
||
// On platforms other than Windows we can use the full path to the binary. | ||
return exePath, nil | ||
} | ||
|
||
// removeOldConfig removes the old ssh configuration from the user's sshconfig. | ||
// Returns true if the config was modified. | ||
func removeOldConfig(config string) (string, bool) { | ||
|
@@ -212,7 +259,7 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st | |
host := fmt.Sprintf( | ||
`Host coder.%s | ||
HostName coder.%s | ||
ProxyCommand %s tunnel %s 12213 stdio | ||
ProxyCommand "%s" tunnel %s 12213 stdio | ||
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. Do the quotes work on Linux too? I thought I tried it before... 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. Works on windows, mac and linux from my testing. |
||
StrictHostKeyChecking no | ||
ConnectTimeout=0 | ||
IdentitiesOnly yes | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.