Skip to content

Commit da02375

Browse files
fix: handle workspace.agent and agent.workspace.owner in coder ssh (#18093)
Closes #18088. The linked issue is misleading -- `coder config-ssh` continues to support the `coder.` prefix. The reason the command `ssh coder.workspace.agent` fails is because `coder ssh workspace.agent` wasn't supported. This PR fixes that. We know we used to support `workspace.agent`, as this is what we recommend in the Web UI: ![image](https://github.com/user-attachments/assets/702bbbc7-c586-4947-98a6-4508a481280b) This PR also adds support for `coder ssh agent.workspace.owner`, such that after running `coder config-ssh`, a command like ``` ssh agent.workspace.owner.coder ``` works, even without Coder Connect running. This is done for parity with an existing workflow that uses `ssh workspace.coder`, which either uses Coder Connect if available, or the CLI.
1 parent 5cfcb73 commit da02375

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cli/ssh.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,12 +1594,14 @@ func writeCoderConnectNetInfo(ctx context.Context, networkInfoDir string) error
15941594
// Converts workspace name input to owner/workspace.agent format
15951595
// Possible valid input formats:
15961596
// workspace
1597+
// workspace.agent
15971598
// owner/workspace
15981599
// owner--workspace
15991600
// owner/workspace--agent
16001601
// owner/workspace.agent
16011602
// owner--workspace--agent
16021603
// owner--workspace.agent
1604+
// agent.workspace.owner - for parity with Coder Connect
16031605
func normalizeWorkspaceInput(input string) string {
16041606
// Split on "/", "--", and "."
16051607
parts := workspaceNameRe.Split(input, -1)
@@ -1608,8 +1610,15 @@ func normalizeWorkspaceInput(input string) string {
16081610
case 1:
16091611
return input // "workspace"
16101612
case 2:
1613+
if strings.Contains(input, ".") {
1614+
return fmt.Sprintf("%s.%s", parts[0], parts[1]) // "workspace.agent"
1615+
}
16111616
return fmt.Sprintf("%s/%s", parts[0], parts[1]) // "owner/workspace"
16121617
case 3:
1618+
// If the only separator is a dot, it's the Coder Connect format
1619+
if !strings.Contains(input, "/") && !strings.Contains(input, "--") {
1620+
return fmt.Sprintf("%s/%s.%s", parts[2], parts[1], parts[0]) // "owner/workspace.agent"
1621+
}
16131622
return fmt.Sprintf("%s/%s.%s", parts[0], parts[1], parts[2]) // "owner/workspace.agent"
16141623
default:
16151624
return input // Fallback

cli/ssh_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,14 @@ func TestSSH(t *testing.T) {
107107

108108
cases := []string{
109109
"myworkspace",
110+
"myworkspace.dev",
110111
"myuser/myworkspace",
111112
"myuser--myworkspace",
112113
"myuser/myworkspace--dev",
113114
"myuser/myworkspace.dev",
114115
"myuser--myworkspace--dev",
115116
"myuser--myworkspace.dev",
117+
"dev.myworkspace.myuser",
116118
}
117119

118120
for _, tc := range cases {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy