Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/agent/workspace/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ func (cmd *UpCmd) Run(ctx context.Context) error {

tunnelClient, logger, credentialsDir, err := initWorkspace(cancelCtx, cancel, workspaceInfo, cmd.Debug, !workspaceInfo.CLIOptions.Platform.Enabled && !workspaceInfo.CLIOptions.DisableDaemon)
if err != nil {
err1 := clientimplementation.DeleteWorkspaceFolder(workspaceInfo.Workspace.Context, workspaceInfo.Workspace.ID, workspaceInfo.Workspace.SSHConfigPath, workspaceInfo.Workspace.SSHConfigIncludePath, logger)
err1 := clientimplementation.DeleteWorkspaceFolder(clientimplementation.DeleteWorkspaceFolderParams{
Context: workspaceInfo.Workspace.Context,
WorkspaceID: workspaceInfo.Workspace.ID,
SSHConfigPath: workspaceInfo.Workspace.SSHConfigPath,
SSHConfigIncludePath: workspaceInfo.Workspace.SSHConfigIncludePath,
}, logger)
if err1 != nil {
return fmt.Errorf("%s %w", err1.Error(), err)
}
Expand Down
32 changes: 17 additions & 15 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,23 @@ func NewBuildCmd(flags *flags.GlobalFlags) *cobra.Command {
baseWorkspaceClient, err := workspace2.Resolve(
ctx,
devPodConfig,
"",
nil,
args,
"",
cmd.Machine,
cmd.ProviderOptions,
false,
cmd.DevContainerImage,
cmd.DevContainerPath,
sshConfigPath,
"",
nil,
cmd.UID,
false,
cmd.Owner,
workspace2.ResolveParams{
IDE: "",
IDEOptions: nil,
Args: args,
DesiredID: "",
DesiredMachine: cmd.Machine,
ProviderUserOptions: cmd.ProviderOptions,
ReconfigureProvider: false,
DevContainerImage: cmd.DevContainerImage,
DevContainerPath: cmd.DevContainerPath,
SSHConfigPath: sshConfigPath,
SSHConfigIncludePath: "",
Source: nil,
UID: cmd.UID,
ChangeLastUsed: false,
Owner: cmd.Owner,
},
log.Default,
)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion cmd/pro/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ func cleanupLocalWorkspaces(ctx context.Context, devPodConfig *config.Config, wo
return
}
// delete workspace folder
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig.DefaultContext, client.Workspace(), client.WorkspaceConfig().SSHConfigPath, client.WorkspaceConfig().SSHConfigIncludePath, log)
err = clientimplementation.DeleteWorkspaceFolder(clientimplementation.DeleteWorkspaceFolderParams{
Context: devPodConfig.DefaultContext,
WorkspaceID: client.Workspace(),
SSHConfigPath: client.WorkspaceConfig().SSHConfigPath,
SSHConfigIncludePath: client.WorkspaceConfig().SSHConfigIncludePath,
}, log)
if err != nil {
log.WithFields(logrus.Fields{
"workspaceId": w.ID,
Expand Down
79 changes: 49 additions & 30 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,14 @@ func (cmd *UpCmd) Run(
setupGPGAgentForwarding := cmd.GPGAgentForwarding || devPodConfig.ContextOption(config.ContextOptionGPGAgentForwarding) == "true"
sshConfigIncludePath := devPodConfig.ContextOption(config.ContextOptionSSHConfigIncludePath)

err = configureSSH(client, cmd.SSHConfigPath, sshConfigIncludePath, user, workdir, setupGPGAgentForwarding, devPodHome)
err = configureSSH(client, configureSSHParams{
sshConfigPath: cmd.SSHConfigPath,
sshConfigIncludePath: sshConfigIncludePath,
user: user,
workdir: workdir,
gpgagent: setupGPGAgentForwarding,
devPodHome: devPodHome,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -1003,13 +1010,23 @@ func startBrowserTunnel(
return nil
}

func configureSSH(client client2.BaseWorkspaceClient, sshConfigPath, sshConfigIncludePath, user, workdir string, gpgagent bool, devPodHome string) error {
path, err := devssh.ResolveSSHConfigPath(sshConfigPath)
type configureSSHParams struct {
sshConfigPath string
sshConfigIncludePath string
user string
workdir string
gpgagent bool
devPodHome string
}

func configureSSH(client client2.BaseWorkspaceClient, params configureSSHParams) error {
path, err := devssh.ResolveSSHConfigPath(params.sshConfigPath)
if err != nil {
return fmt.Errorf("invalid ssh config path %w", err)
}
sshConfigPath = path
sshConfigPath := path

sshConfigIncludePath := params.sshConfigIncludePath
if sshConfigIncludePath != "" {
includePath, err := devssh.ResolveSSHConfigPath(sshConfigIncludePath)
if err != nil {
Expand All @@ -1018,17 +1035,17 @@ func configureSSH(client client2.BaseWorkspaceClient, sshConfigPath, sshConfigIn
sshConfigIncludePath = includePath
}

err = devssh.ConfigureSSHConfig(
sshConfigPath,
sshConfigIncludePath,
client.Context(),
client.Workspace(),
user,
workdir,
gpgagent,
devPodHome,
log.Default,
)
err = devssh.ConfigureSSHConfig(devssh.SSHConfigParams{
SSHConfigPath: sshConfigPath,
SSHConfigIncludePath: sshConfigIncludePath,
Context: client.Context(),
Workspace: client.Workspace(),
User: params.user,
Workdir: params.workdir,
GPGAgent: params.gpgagent,
DevPodHome: params.devPodHome,
Log: log.Default,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -1450,21 +1467,23 @@ func (cmd *UpCmd) prepareClient(ctx context.Context, devPodConfig *config.Config
client, err := workspace2.Resolve(
ctx,
devPodConfig,
cmd.IDE,
cmd.IDEOptions,
args,
cmd.ID,
cmd.Machine,
cmd.ProviderOptions,
cmd.Reconfigure,
cmd.DevContainerImage,
cmd.DevContainerPath,
cmd.SSHConfigPath,
sshConfigIncludePath,
source,
cmd.UID,
true,
cmd.Owner,
workspace2.ResolveParams{
IDE: cmd.IDE,
IDEOptions: cmd.IDEOptions,
Args: args,
DesiredID: cmd.ID,
DesiredMachine: cmd.Machine,
ProviderUserOptions: cmd.ProviderOptions,
ReconfigureProvider: cmd.Reconfigure,
DevContainerImage: cmd.DevContainerImage,
DevContainerPath: cmd.DevContainerPath,
SSHConfigPath: cmd.SSHConfigPath,
SSHConfigIncludePath: sshConfigIncludePath,
Source: source,
UID: cmd.UID,
ChangeLastUsed: true,
Owner: cmd.Owner,
},
logger,
)
if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions pkg/client/clientimplementation/daemonclient/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ func (c *client) Delete(ctx context.Context, opt clientpkg.DeleteOptions) error
return err
} else if workspace == nil {
// delete the workspace folder
err = clientimplementation.DeleteWorkspaceFolder(c.workspace.Context, c.workspace.ID, c.workspace.SSHConfigPath, c.workspace.SSHConfigIncludePath, c.log)
err = clientimplementation.DeleteWorkspaceFolder(clientimplementation.DeleteWorkspaceFolderParams{
Context: c.workspace.Context,
WorkspaceID: c.workspace.ID,
SSHConfigPath: c.workspace.SSHConfigPath,
SSHConfigIncludePath: c.workspace.SSHConfigIncludePath,
}, c.log)
if err != nil {
return err
}
Expand Down Expand Up @@ -67,7 +72,12 @@ func (c *client) Delete(ctx context.Context, opt clientpkg.DeleteOptions) error
}

// delete the workspace folder
err = clientimplementation.DeleteWorkspaceFolder(c.workspace.Context, c.workspace.ID, c.workspace.SSHConfigPath, c.workspace.SSHConfigIncludePath, c.log)
err = clientimplementation.DeleteWorkspaceFolder(clientimplementation.DeleteWorkspaceFolderParams{
Context: c.workspace.Context,
WorkspaceID: c.workspace.ID,
SSHConfigPath: c.workspace.SSHConfigPath,
SSHConfigIncludePath: c.workspace.SSHConfigIncludePath,
}, c.log)
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/client/clientimplementation/proxy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ func (s *proxyClient) Delete(ctx context.Context, opt client.DeleteOptions) erro
s.log.Errorf("Error deleting workspace: %v", err)
}

return DeleteWorkspaceFolder(s.workspace.Context, s.workspace.ID, s.workspace.SSHConfigPath, s.workspace.SSHConfigIncludePath, s.log)
return DeleteWorkspaceFolder(DeleteWorkspaceFolderParams{
Context: s.workspace.Context,
WorkspaceID: s.workspace.ID,
SSHConfigPath: s.workspace.SSHConfigPath,
SSHConfigIncludePath: s.workspace.SSHConfigIncludePath,
}, s.log)
}

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

return DeleteWorkspaceFolder(s.workspace.Context, s.workspace.ID, s.workspace.SSHConfigPath, s.workspace.SSHConfigIncludePath, s.log)
return DeleteWorkspaceFolder(DeleteWorkspaceFolderParams{
Context: s.workspace.Context,
WorkspaceID: s.workspace.ID,
SSHConfigPath: s.workspace.SSHConfigPath,
SSHConfigIncludePath: s.workspace.SSHConfigIncludePath,
}, s.log)
}

func (s *workspaceClient) isMachineRunning(ctx context.Context) (bool, error) {
Expand Down Expand Up @@ -643,13 +648,21 @@ func DeleteMachineFolder(context, machineID string) error {
return nil
}

func DeleteWorkspaceFolder(context string, workspaceID string, sshConfigPath string, sshConfigIncludePath string, log log.Logger) error {
path, err := ssh.ResolveSSHConfigPath(sshConfigPath)
type DeleteWorkspaceFolderParams struct {
Context string
WorkspaceID string
SSHConfigPath string
SSHConfigIncludePath string
}

func DeleteWorkspaceFolder(params DeleteWorkspaceFolderParams, log log.Logger) error {
path, err := ssh.ResolveSSHConfigPath(params.SSHConfigPath)
if err != nil {
return err
}
sshConfigPath = path
sshConfigPath := path

sshConfigIncludePath := params.SSHConfigIncludePath
if sshConfigIncludePath != "" {
includePath, err := ssh.ResolveSSHConfigPath(sshConfigIncludePath)
if err != nil {
Expand All @@ -658,12 +671,12 @@ func DeleteWorkspaceFolder(context string, workspaceID string, sshConfigPath str
sshConfigIncludePath = includePath
}

err = ssh.RemoveFromConfig(workspaceID, sshConfigPath, sshConfigIncludePath, log)
err = ssh.RemoveFromConfig(params.WorkspaceID, sshConfigPath, sshConfigIncludePath, log)
if err != nil {
log.Errorf("Remove workspace '%s' from ssh config: %v", workspaceID, err)
log.Errorf("Remove workspace '%s' from ssh config: %v", params.WorkspaceID, err)
}

workspaceFolder, err := provider.GetWorkspaceDir(context, workspaceID)
workspaceFolder, err := provider.GetWorkspaceDir(params.Context, params.WorkspaceID)
if err != nil {
return err
}
Expand Down
25 changes: 17 additions & 8 deletions pkg/ssh/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,34 @@ var (
MarkerEndPrefix = "# DevPod End "
)

func ConfigureSSHConfig(sshConfigPath, sshConfigIncludePath, context, workspace, user, workdir string, gpgagent bool, devPodHome string, log log.Logger) error {
return configureSSHConfigSameFile(sshConfigPath, sshConfigIncludePath, context, workspace, user, workdir, "", gpgagent, devPodHome, log)
type SSHConfigParams struct {
SSHConfigPath string
SSHConfigIncludePath string
Context string
Workspace string
User string
Workdir string
Command string
GPGAgent bool
DevPodHome string
Log log.Logger
}

func configureSSHConfigSameFile(sshConfigPath, sshConfigIncludePath, context, workspace, user, workdir, command string, gpgagent bool, devPodHome string, log log.Logger) error {
func ConfigureSSHConfig(params SSHConfigParams) error {
configLock.Lock()
defer configLock.Unlock()

targetPath := sshConfigPath
if sshConfigIncludePath != "" {
targetPath = sshConfigIncludePath
targetPath := params.SSHConfigPath
if params.SSHConfigIncludePath != "" {
targetPath = params.SSHConfigIncludePath
}

newFile, err := addHost(targetPath, workspace+"."+"devpod", user, context, workspace, workdir, command, gpgagent, devPodHome)
newFile, err := addHost(targetPath, params.Workspace+"."+"devpod", params.User, params.Context, params.Workspace, params.Workdir, params.Command, params.GPGAgent, params.DevPodHome)
if err != nil {
return fmt.Errorf("parse ssh config %w", err)
}

return writeSSHConfig(targetPath, newFile, log)
return writeSSHConfig(targetPath, newFile, params.Log)
}

type DevPodSSHEntry struct {
Expand Down
21 changes: 18 additions & 3 deletions pkg/workspace/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ func Delete(ctx context.Context, devPodConfig *config.Config, args []string, ign
log.Errorf("Error retrieving workspace: %v", err)

// delete workspace folder
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig.DefaultContext, workspaceID, "", "", log)
err = clientimplementation.DeleteWorkspaceFolder(clientimplementation.DeleteWorkspaceFolderParams{
Context: devPodConfig.DefaultContext,
WorkspaceID: workspaceID,
SSHConfigPath: "",
SSHConfigIncludePath: "",
}, log)
if err != nil {
return "", err
}
Expand All @@ -52,7 +57,12 @@ func Delete(ctx context.Context, devPodConfig *config.Config, args []string, ign
workspaceConfig := client.WorkspaceConfig()
if !force && workspaceConfig.Imported {
// delete workspace folder
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig.DefaultContext, client.Workspace(), workspaceConfig.SSHConfigPath, workspaceConfig.SSHConfigIncludePath, log)
err = clientimplementation.DeleteWorkspaceFolder(clientimplementation.DeleteWorkspaceFolderParams{
Context: devPodConfig.DefaultContext,
WorkspaceID: client.Workspace(),
SSHConfigPath: workspaceConfig.SSHConfigPath,
SSHConfigIncludePath: workspaceConfig.SSHConfigIncludePath,
}, log)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -138,7 +148,12 @@ func deleteSingleMachine(ctx context.Context, client client2.BaseWorkspaceClient
}

// delete workspace folder
err = clientimplementation.DeleteWorkspaceFolder(client.Context(), client.Workspace(), client.WorkspaceConfig().SSHConfigPath, client.WorkspaceConfig().SSHConfigIncludePath, log)
err = clientimplementation.DeleteWorkspaceFolder(clientimplementation.DeleteWorkspaceFolderParams{
Context: client.Context(),
WorkspaceID: client.Workspace(),
SSHConfigPath: client.WorkspaceConfig().SSHConfigPath,
SSHConfigIncludePath: client.WorkspaceConfig().SSHConfigIncludePath,
}, log)
if err != nil {
return false, err
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/workspace/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ func List(ctx context.Context, devPodConfig *config.Config, skipPro bool, owner
for _, localWorkspace := range localWorkspaces {
if localWorkspace.IsPro() {
if shouldDeleteLocalWorkspace(ctx, localWorkspace, proWorkspaceResults) {
err = clientimplementation.DeleteWorkspaceFolder(devPodConfig.DefaultContext, localWorkspace.ID, localWorkspace.SSHConfigPath, localWorkspace.SSHConfigIncludePath, log)
err = clientimplementation.DeleteWorkspaceFolder(clientimplementation.DeleteWorkspaceFolderParams{
Context: devPodConfig.DefaultContext,
WorkspaceID: localWorkspace.ID,
SSHConfigPath: localWorkspace.SSHConfigPath,
SSHConfigIncludePath: localWorkspace.SSHConfigIncludePath,
}, log)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
if err != nil {
log.Debugf("failed to delete local workspace %s: %v", localWorkspace.ID, err)
}
Expand Down
Loading
Loading