- Notifications
You must be signed in to change notification settings - Fork906
fix: handle vscodessh style workspace names in coder ssh#17154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,6 +13,7 @@ import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"regexp" | ||
"slices" | ||
"strconv" | ||
"strings" | ||
@@ -57,6 +58,7 @@ var ( | ||
autostopNotifyCountdown = []time.Duration{30 * time.Minute} | ||
// gracefulShutdownTimeout is the timeout, per item in the stack of things to close | ||
gracefulShutdownTimeout = 2 * time.Second | ||
workspaceNameRe = regexp.MustCompile(`[/.]+|--`) | ||
Member
| ||
) | ||
func (r *RootCmd) ssh() *serpent.Command { | ||
@@ -200,10 +202,9 @@ func (r *RootCmd) ssh() *serpent.Command { | ||
parsedEnv = append(parsedEnv, [2]string{k, v}) | ||
} | ||
workspaceInput := strings.TrimPrefix(inv.Args[0], hostPrefix) | ||
// convert workspace name format into owner/workspace.agent | ||
namedWorkspace := normalizeWorkspaceInput(workspaceInput) | ||
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, !disableAutostart, namedWorkspace) | ||
if err != nil { | ||
return err | ||
@@ -1413,3 +1414,28 @@ func collectNetworkStats(ctx context.Context, agentConn *workspacesdk.AgentConn, | ||
DownloadBytesSec: int64(downloadSecs), | ||
}, nil | ||
} | ||
// Converts workspace name input to owner/workspace.agent format | ||
// Possible valid input formats: | ||
// workspace | ||
// owner/workspace | ||
// owner--workspace | ||
// owner/workspace--agent | ||
// owner/workspace.agent | ||
// owner--workspace--agent | ||
// owner--workspace.agent | ||
func normalizeWorkspaceInput(input string) string { | ||
// Split on "/", "--", and "." | ||
parts := workspaceNameRe.Split(input, -1) | ||
switch len(parts) { | ||
case 1: | ||
return input // "workspace" | ||
case 2: | ||
return fmt.Sprintf("%s/%s", parts[0], parts[1]) // "owner/workspace" | ||
case 3: | ||
return fmt.Sprintf("%s/%s.%s", parts[0], parts[1], parts[2]) // "owner/workspace.agent" | ||
default: | ||
return input // Fallback | ||
} | ||
} |
Uh oh!
There was an error while loading.Please reload this page.