ssh_theater: only edit conf if host doesn't resolve
diff --git a/dockerimg/dockerimg.go b/dockerimg/dockerimg.go
index 834a769..0256798 100644
--- a/dockerimg/dockerimg.go
+++ b/dockerimg/dockerimg.go
@@ -283,7 +283,12 @@
var sshServerIdentity, sshUserIdentity []byte
- sshErr := CheckForInclude()
+ cst, err := NewSSHTheater(cntrName, sshHost, sshPort)
+ if err != nil {
+ return appendInternalErr(fmt.Errorf("NewContainerSSHTheather: %w", err))
+ }
+
+ sshErr := CheckSSHReachability(cntrName)
sshAvailable := false
sshErrMsg := ""
if sshErr != nil {
@@ -291,10 +296,6 @@
sshErrMsg = sshErr.Error()
// continue - ssh config is not required for the rest of sketch to function locally.
} else {
- cst, err := NewSSHTheater(cntrName, sshHost, sshPort)
- if err != nil {
- return appendInternalErr(fmt.Errorf("NewContainerSSHTheather: %w", err))
- }
sshAvailable = true
// Note: The vscode: link uses an undocumented request parameter that I really had to dig to find:
// https://github.com/microsoft/vscode/blob/2b9486161abaca59b5132ce3c59544f3cc7000f6/src/vs/code/electron-main/app.ts#L878
diff --git a/dockerimg/ssh_theater.go b/dockerimg/ssh_theater.go
index 6afcfc9..1b060cc 100644
--- a/dockerimg/ssh_theater.go
+++ b/dockerimg/ssh_theater.go
@@ -10,6 +10,7 @@
"fmt"
"io/fs"
"os"
+ "os/exec"
"path/filepath"
"strings"
@@ -125,6 +126,15 @@
return cst, nil
}
+func checkSSHResolve(hostname string) error {
+ cmd := exec.Command("ssh", "-T", hostname)
+ out, err := cmd.CombinedOutput()
+ if strings.HasPrefix(string(out), "ssh: Could not resolve hostname") {
+ return err
+ }
+ return nil
+}
+
func CheckForIncludeWithFS(fs FileSystem, stdinReader bufio.Reader) error {
sketchSSHPathInclude := "Include " + filepath.Join(os.Getenv("HOME"), ".config", "sketch", "ssh_config")
defaultSSHPath := filepath.Join(os.Getenv("HOME"), ".ssh", "config")
@@ -563,7 +573,10 @@
return ssh.NewPublicKey(privateKey)
}
-// CheckForInclude checks if the user's SSH config includes the Sketch SSH config file
-func CheckForInclude() error {
- return CheckForIncludeWithFS(&RealFileSystem{}, *bufio.NewReader(os.Stdin))
+// CheckSSHReachability checks if the user's SSH config includes the Sketch SSH config file
+func CheckSSHReachability(cntrName string) error {
+ if err := checkSSHResolve(cntrName); err != nil {
+ return CheckForIncludeWithFS(&RealFileSystem{}, *bufio.NewReader(os.Stdin))
+ }
+ return nil
}