Skip to content

Commit

Permalink
chore: test ssh config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbreuninger committed Dec 8, 2023
1 parent 6e903b0 commit 3787ae7
Show file tree
Hide file tree
Showing 92 changed files with 65 additions and 8,985 deletions.
8 changes: 1 addition & 7 deletions cmd/agent/workspace/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/loft-sh/devpod/pkg/binaries"
"github.com/loft-sh/devpod/pkg/client/clientimplementation"
"github.com/loft-sh/devpod/pkg/command"
"github.com/loft-sh/devpod/pkg/config"
"github.com/loft-sh/devpod/pkg/credentials"
"github.com/loft-sh/devpod/pkg/daemon"
"github.com/loft-sh/devpod/pkg/devcontainer"
Expand Down Expand Up @@ -78,14 +77,9 @@ func (cmd *UpCmd) Run(ctx context.Context) error {
cancelCtx, cancel := context.WithCancel(ctx)
defer cancel()

devPodConfig, err := config.LoadConfig(workspaceInfo.Workspace.Context, "")
if err != nil {
return err
}

tunnelClient, logger, credentialsDir, err := initWorkspace(cancelCtx, cancel, workspaceInfo, cmd.Debug, !workspaceInfo.CLIOptions.Proxy && !workspaceInfo.CLIOptions.DisableDaemon)
if err != nil {
err1 := clientimplementation.DeleteWorkspaceFolder(devPodConfig, workspaceInfo.Workspace.Context, workspaceInfo.Workspace.ID, workspaceInfo.Workspace.SSHConfigPath, logger)
err1 := clientimplementation.DeleteWorkspaceFolder(workspaceInfo.Workspace.Context, workspaceInfo.Workspace.ID, workspaceInfo.Workspace.SSHConfigPath, logger)
if err1 != nil {
return errors.Wrap(err, err1.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (cmd *DeleteCmd) Run(ctx context.Context, devPodConfig *config.Config, args
log.Default.Errorf("Error retrieving workspace: %v", err)

// delete workspace folder
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig, devPodConfig.DefaultContext, workspaceID, "", log.Default)
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig.DefaultContext, workspaceID, "", log.Default)
if err != nil {
return err
}
Expand All @@ -88,7 +88,7 @@ func (cmd *DeleteCmd) Run(ctx context.Context, devPodConfig *config.Config, args
workspaceConfig := client.WorkspaceConfig()
if !cmd.Force && workspaceConfig.Imported {
// delete workspace folder
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig, devPodConfig.DefaultContext, client.Workspace(), workspaceConfig.SSHConfigPath, log.Default)
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig.DefaultContext, client.Workspace(), workspaceConfig.SSHConfigPath, log.Default)
if err != nil {
return err
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (cmd *DeleteCmd) deleteSingleMachine(ctx context.Context, client client2.Ba
}

// delete workspace folder
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig, client.Context(), client.Workspace(), client.WorkspaceConfig().SSHConfigPath, log.Default)
err = clientimplementation.DeleteWorkspaceFolder(client.Context(), client.Workspace(), client.WorkspaceConfig().SSHConfigPath, log.Default)
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (cmd *SSHCmd) Run(ctx context.Context, devPodConfig *config.Config, client
// get user
if cmd.User == "" {
var err error
cmd.User, err = devssh.GetUser(devPodConfig, client.WorkspaceConfig().ID, client.WorkspaceConfig().SSHConfigPath)
cmd.User, err = devssh.GetUser(client.WorkspaceConfig().ID, client.WorkspaceConfig().SSHConfigPath)
if err != nil {
return err
}
Expand Down
22 changes: 12 additions & 10 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/loft-sh/devpod/pkg/port"
provider2 "github.com/loft-sh/devpod/pkg/provider"
devssh "github.com/loft-sh/devpod/pkg/ssh"

Check failure on line 31 in cmd/up.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/loft-sh/devpod/pkg/ssh" is being imported more than once (stylecheck)
pkgssh "github.com/loft-sh/devpod/pkg/ssh"

Check failure on line 32 in cmd/up.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/loft-sh/devpod/pkg/ssh" (stylecheck)
"github.com/loft-sh/devpod/pkg/tunnel"
workspace2 "github.com/loft-sh/devpod/pkg/workspace"
"github.com/loft-sh/log"
Expand Down Expand Up @@ -671,9 +672,15 @@ func startBrowserTunnel(
return nil
}

func configureSSH(c *config.Config, client client2.BaseWorkspaceClient, configPath, user string, gpgagent bool) error {
err := devssh.ConfigureSSHConfig(c,
configPath,
func configureSSH(c *config.Config, client client2.BaseWorkspaceClient, sshConfigPath, user string, gpgagent bool) error {
path, err := pkgssh.ResolveSSHConfigPath(sshConfigPath)
if err != nil {
return errors.Wrap(err, "Invalid ssh config path")
}
sshConfigPath = path

err = devssh.ConfigureSSHConfig(
sshConfigPath,
client.Context(),
client.Workspace(),
user,
Expand Down Expand Up @@ -780,7 +787,7 @@ func setupDotfiles(
agentArguments = append(agentArguments, dotfilesScript)
}

remoteUser, err := devssh.GetUser(devPodConfig, client.WorkspaceConfig().ID, client.WorkspaceConfig().SSHConfigPath)
remoteUser, err := devssh.GetUser(client.WorkspaceConfig().ID, client.WorkspaceConfig().SSHConfigPath)
if err != nil {
remoteUser = "root"
}
Expand Down Expand Up @@ -832,12 +839,7 @@ func performGpgForwarding(
return err
}

devPodConfig, err := config.LoadConfig(client.WorkspaceConfig().Context, "")
if err != nil {
return err
}

remoteUser, err := devssh.GetUser(devPodConfig, client.WorkspaceConfig().ID, client.WorkspaceConfig().SSHConfigPath)
remoteUser, err := devssh.GetUser(client.WorkspaceConfig().ID, client.WorkspaceConfig().SSHConfigPath)
if err != nil {
remoteUser = "root"
}
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ require (
github.com/containerd/containerd v1.6.20 // indirect
github.com/containerd/fifo v1.1.0 // indirect
github.com/containerd/ttrpc v1.2.2 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/moby/term v0.5.0 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/opencontainers/runc v1.1.7 // indirect
github.com/opencontainers/selinux v1.11.0 // indirect
Expand All @@ -68,6 +71,7 @@ require (
go.opentelemetry.io/otel/trace v1.4.1 // indirect
go.opentelemetry.io/proto/otlp v0.12.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)

require (
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
Expand Down Expand Up @@ -648,6 +649,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
Expand All @@ -661,6 +664,8 @@ github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk=
github.com/onsi/ginkgo/v2 v2.9.1/go.mod h1:FEcmzVcCHl+4o9bQZVab+4dC9+j+91t2FHSzmGAPfuo=
github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
Expand All @@ -669,6 +674,7 @@ github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc=
github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E=
github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ=
Expand Down Expand Up @@ -990,6 +996,7 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
Expand Down Expand Up @@ -1110,6 +1117,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201202213521-69691e467435/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -1220,6 +1228,7 @@ golang.org/x/tools v0.0.0-20200916195026-c9a70fc28ce3/go.mod h1:z6u4i615ZeAfBE4X
golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
Expand Down Expand Up @@ -1407,6 +1416,7 @@ gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76
gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/square/go-jose.v2 v2.5.1 h1:7odma5RETjNHWJnR32wx8t+Io4djHE1PqxCFx3iiZ2w=
gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/clientimplementation/proxy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (s *proxyClient) Delete(ctx context.Context, opt client.DeleteOptions) erro
s.log.Errorf("Error deleting workspace: %v", err)
}

return DeleteWorkspaceFolder(s.devPodConfig, s.workspace.Context, s.workspace.ID, s.workspace.SSHConfigPath, s.log)
return DeleteWorkspaceFolder(s.workspace.Context, s.workspace.ID, s.workspace.SSHConfigPath, s.log)
}

func (s *proxyClient) Stop(ctx context.Context, opt client.StopOptions) error {
Expand Down
12 changes: 9 additions & 3 deletions pkg/client/clientimplementation/workspace_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (s *workspaceClient) Delete(ctx context.Context, opt client.DeleteOptions)
}
}

return DeleteWorkspaceFolder(s.devPodConfig, s.workspace.Context, s.workspace.ID, s.workspace.SSHConfigPath, s.log)
return DeleteWorkspaceFolder(s.workspace.Context, s.workspace.ID, s.workspace.SSHConfigPath, s.log)
}

func (s *workspaceClient) isMachineRunning(ctx context.Context) (bool, error) {
Expand Down Expand Up @@ -612,8 +612,14 @@ func DeleteMachineFolder(context, machineID string) error {
return nil
}

func DeleteWorkspaceFolder(c *config.Config, context string, workspaceID string, sshConfigPath string, log log.Logger) error {
err := ssh.RemoveFromConfig(c, workspaceID, sshConfigPath, log)
func DeleteWorkspaceFolder(context string, workspaceID string, sshConfigPath string, log log.Logger) error {
path, err := ssh.ResolveSSHConfigPath(sshConfigPath)
if err != nil {
return err
}
sshConfigPath = path

err = ssh.RemoveFromConfig(workspaceID, sshConfigPath, log)
if err != nil {
log.Errorf("Remove workspace '%s' from ssh config: %v", workspaceID, err)
}
Expand Down
68 changes: 15 additions & 53 deletions pkg/ssh/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"sync"

"github.com/loft-sh/devpod/pkg/config"
"github.com/loft-sh/log"
"github.com/loft-sh/log/scanner"
"github.com/mitchellh/go-homedir"
Expand All @@ -22,25 +21,13 @@ var (
MarkerEndPrefix = "# DevPod End "
)

func ConfigureSSHConfig(c *config.Config, configPath, context, workspace, user string, gpgagent bool, log log.Logger) error {
return configureSSHConfigSameFile(c, configPath, context, workspace, user, "", gpgagent, log)
func ConfigureSSHConfig(sshConfigPath, context, workspace, user string, gpgagent bool, log log.Logger) error {
return configureSSHConfigSameFile(sshConfigPath, context, workspace, user, "", gpgagent, log)
}

func configureSSHConfigSameFile(c *config.Config, sshConfigPath, context, workspace, user, command string, gpgagent bool, log log.Logger) error {
func configureSSHConfigSameFile(sshConfigPath, context, workspace, user, command string, gpgagent bool, log log.Logger) error {
configLock.Lock()
defer configLock.Unlock()
var err error
if sshConfigPath == "" {
sshConfigPath, err = GetDefaultSSHConfigPath(c)
if err != nil {
return err
}
} else {
sshConfigPath, err = ResolveSSHConfigPath(sshConfigPath)
if err != nil {
return errors.Wrap(err, "Invalid ssh config path")
}
}

newFile, err := addHost(sshConfigPath, workspace+"."+"devpod", user, context, workspace, command, gpgagent)
if err != nil {
Expand Down Expand Up @@ -90,19 +77,12 @@ func addHost(path, host, user, context, workspace, command string, gpgagent bool
return strings.Join(newLines, "\n"), nil
}

func GetUser(c *config.Config, workspaceID string, sshConfigPath string) (string, error) {
var err error
if sshConfigPath == "" {
sshConfigPath, err = GetDefaultSSHConfigPath(c)
if err != nil {
return "", err
}
} else {
sshConfigPath, err = ResolveSSHConfigPath(sshConfigPath)
if err != nil {
return "", errors.Wrap(err, "Invalid ssh config path")
}
func GetUser(workspaceID string, sshConfigPath string) (string, error) {
path, err := ResolveSSHConfigPath(sshConfigPath)
if err != nil {
return "", errors.Wrap(err, "Invalid ssh config path")
}
sshConfigPath = path

user := "root"
_, err = transformHostSection(sshConfigPath, workspaceID+"."+"devpod", func(line string) string {
Expand All @@ -120,21 +100,9 @@ func GetUser(c *config.Config, workspaceID string, sshConfigPath string) (string
return user, nil
}

func RemoveFromConfig(c *config.Config, workspaceID string, sshConfigPath string, log log.Logger) error {
func RemoveFromConfig(workspaceID string, sshConfigPath string, log log.Logger) error {
configLock.Lock()
defer configLock.Unlock()
var err error
if sshConfigPath == "" {
sshConfigPath, err = GetDefaultSSHConfigPath(c)
if err != nil {
return err
}
} else {
sshConfigPath, err = ResolveSSHConfigPath(sshConfigPath)
if err != nil {
return errors.Wrap(err, "Invalid ssh config path")
}
}

newFile, err := removeFromConfig(sshConfigPath, workspaceID+"."+"devpod")
if err != nil {
Expand Down Expand Up @@ -163,22 +131,16 @@ func ResolveSSHConfigPath(sshConfigPath string) (string, error) {
if err != nil {
return "", errors.Wrap(err, "get home dir")
}

if sshConfigPath == "" {
return filepath.Join(homeDir, ".ssh", "config"), nil
}

if strings.HasPrefix(sshConfigPath, "~/") {
sshConfigPath = strings.Replace(sshConfigPath, "~", homeDir, 1)
}
return filepath.Abs(sshConfigPath)
}

func GetDefaultSSHConfigPath(c *config.Config) (string, error) {
homeDir, err := homedir.Dir()
if err != nil {
return "", errors.Wrap(err, "get home dir")
}
if c.ContextOption(config.ContextOptionSSHConfigPath) == "" {
return filepath.Join(homeDir, ".ssh", "config"), nil
} else {
return ResolveSSHConfigPath(c.ContextOption(config.ContextOptionSSHConfigPath))
}
return filepath.Abs(sshConfigPath)
}

func removeFromConfig(path, host string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func resolveWorkspace(
// create workspace
provider, workspace, machine, err := createWorkspace(ctx, devPodConfig, workspaceID, name, desiredMachine, providerUserOptions, sshConfigPath, source, isLocalPath, log)
if err != nil {
_ = clientimplementation.DeleteWorkspaceFolder(devPodConfig, devPodConfig.DefaultContext, workspaceID, sshConfigPath, log)
_ = clientimplementation.DeleteWorkspaceFolder(devPodConfig.DefaultContext, workspaceID, sshConfigPath, log)
return nil, nil, nil, err
}

Expand Down
18 changes: 0 additions & 18 deletions vendor/github.com/gen2brain/beeep/.appveyor.yml

This file was deleted.

10 changes: 0 additions & 10 deletions vendor/github.com/gen2brain/beeep/.travis.yml

This file was deleted.

Loading

0 comments on commit 3787ae7

Please sign in to comment.