Skip to content

Commit

Permalink
Optimize the logic of adding entry in wsl (#1414)
Browse files Browse the repository at this point in the history
Signed-off-by: hwdef <hwdefcom@outlook.com>

Signed-off-by: hwdef <hwdefcom@outlook.com>
  • Loading branch information
hwdef committed Jan 13, 2023
1 parent e1bbd56 commit 64b5a0a
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions pkg/ssh/config/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,13 @@ func AddEntry(eo EntryOptions) error {
if err != nil {
return err
}

// It helps user to directly use remote ssh plugin of VSCode on the host system.
// VSCode will only check the host ssh files.
if osutil.IsWsl() {
logrus.Debug("Try adding entry to WSL's ssh-agent")
winSshConfig, err := osutil.GetWslHostSshConfig()
if err != nil {
return err
}
winKeyPath, err := osutil.CopyToWinEnvdHome(eo.PrivateKeyPath, 0600)
err := addEntryToWSLHost(eo)
if err != nil {
return err
}
// Add the entry to the WSL host SSH config
logrus.Debugf("Adding entry to WSL's ssh-agent: %s", winSshConfig)
eo.PrivateKeyPath = winKeyPath
err = add(winSshConfig, eo)
if err != nil {
return err
logrus.Warnf("Failed to add entry to WSL host %s\n", err.Error())
}
}
return nil
Expand Down Expand Up @@ -115,3 +106,23 @@ func RemoveEntry(name string) error {
}
return nil
}

func addEntryToWSLHost(eo EntryOptions) error {
logrus.Debug("Try adding entry to WSL's ssh-agent")
winSshConfig, err := osutil.GetWslHostSshConfig()
if err != nil {
return err
}
winKeyPath, err := osutil.CopyToWinEnvdHome(eo.PrivateKeyPath, 0600)
if err != nil {
return err
}
// Add the entry to the WSL host SSH config
logrus.Debugf("Adding entry to WSL's ssh-agent: %s", winSshConfig)
eo.PrivateKeyPath = winKeyPath
err = add(winSshConfig, eo)
if err != nil {
return err
}
return nil
}

0 comments on commit 64b5a0a

Please sign in to comment.