Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 2adda6b

Browse files
committed
fix(cdr): fix ssh and sync cmds
1 parent c0c11b8 commit 2adda6b

File tree

7 files changed

+38
-7
lines changed

7 files changed

+38
-7
lines changed

coder-sdk/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,6 @@ func (c *DefaultClient) Token() string {
123123
}
124124

125125
// BaseURL returns the BaseURL configured for this Client.
126-
func (c *DefaultClient) BaseURL() url.URL {
127-
return *c.baseURL
126+
func (c *DefaultClient) BaseURL() *url.URL {
127+
return c.baseURL
128128
}

coder-sdk/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ type Client interface {
227227
Token() string
228228

229229
// BaseURL returns the BaseURL configured for this Client.
230-
BaseURL() url.URL
230+
BaseURL() *url.URL
231231

232232
// CordonWorkspaceProvider prevents the provider from having any more workspaces placed on it.
233233
CordonWorkspaceProvider(ctx context.Context, id, reason string) error

coder-sdk/workspace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func (c *DefaultClient) EditWorkspace(ctx context.Context, workspaceID string, r
229229
// DialWsep dials a workspace's command execution interface
230230
// See https://github.com/cdr/wsep for details.
231231
func (c *DefaultClient) DialWsep(ctx context.Context, baseURL *url.URL, workspaceID string) (*websocket.Conn, error) {
232-
return c.dialWebsocket(ctx, "/proxy/workspaces/"+workspaceID+"/wsep", withBaseURL(baseURL))
232+
return c.dialWebsocket(ctx, "/api/v0/workspaces/"+workspaceID+"/proxy/wsep", withBaseURL(baseURL))
233233
}
234234

235235
// DialExecutor gives a remote execution interface for performing commands
@@ -244,7 +244,7 @@ func (c *DefaultClient) DialExecutor(ctx context.Context, baseURL *url.URL, work
244244

245245
// DialIDEStatus opens a websocket connection for cpu load metrics on the workspace.
246246
func (c *DefaultClient) DialIDEStatus(ctx context.Context, baseURL *url.URL, workspaceID string) (*websocket.Conn, error) {
247-
return c.dialWebsocket(ctx, "/proxy/workspaces/"+workspaceID+"/ide/api/status", withBaseURL(baseURL))
247+
return c.dialWebsocket(ctx, "/api/v0/workspaces/"+workspaceID+"/proxy/ide/api/status", withBaseURL(baseURL))
248248
}
249249

250250
// DialWorkspaceBuildLog opens a websocket connection for the workspace build log messages.

internal/cmd/configssh.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ func makeSSHConfig(binPath, host, userName, workspaceName, privateKeyFilepath st
287287
`, workspaceName, host, userName, workspaceName, privateKeyFilepath)
288288
}
289289

290+
func proxyCommand(binPath, workspaceName string, quoted bool) string {
291+
if quoted {
292+
binPath = fmt.Sprintf("%q", binPath)
293+
}
294+
return fmt.Sprintf(`%s tunnel %s 12213 stdio`, binPath, workspaceName)
295+
}
296+
290297
func writeStr(filename, data string) error {
291298
return ioutil.WriteFile(filename, []byte(data), 0777)
292299
}

internal/cmd/ssh.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ func shell(cmd *cobra.Command, args []string) error {
6060
if err != nil {
6161
return err
6262
}
63+
64+
if !wp.SSHEnabled {
65+
return clog.Error("SSH is disabled on this Workspace")
66+
}
67+
6368
u, err := url.Parse(wp.EnvproxyAccessURL)
6469
if err != nil {
6570
return err
@@ -75,10 +80,24 @@ func shell(cmd *cobra.Command, args []string) error {
7580
if err != nil {
7681
return err
7782
}
83+
84+
binPath, err := binPath()
85+
if err != nil {
86+
return xerrors.Errorf("Failed to get executable path: %w", err)
87+
}
88+
7889
ssh := exec.CommandContext(ctx,
7990
"ssh", "-i"+privateKeyFilepath,
8091
fmt.Sprintf("%s-%s@%s", me.Username, workspace.Name, u.Hostname()),
8192
)
93+
94+
if wp.EnableNetV2 {
95+
ssh = exec.CommandContext(ctx,
96+
"ssh", "-i"+privateKeyFilepath,
97+
"-o"+fmt.Sprintf("ProxyCommand=%s", proxyCommand(binPath, workspace.Name, false)),
98+
workspace.Name,
99+
)
100+
}
82101
if len(args) > 1 {
83102
ssh.Args = append(ssh.Args, args[1:]...)
84103
}

internal/cmd/tunnel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ coder tunnel my-dev 3000 3000
7777

7878
c := &tunnneler{
7979
log: log,
80-
brokerAddr: &baseURL,
80+
brokerAddr: baseURL,
8181
token: sdk.Token(),
8282
workspaceID: workspaceID,
8383
stdio: args[2] == "stdio",

internal/coderutil/workspace.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ func DialWorkspaceWsep(ctx context.Context, client coder.Client, workspace *code
2020
if err != nil {
2121
return nil, xerrors.Errorf("get workspace workspace provider: %w", err)
2222
}
23-
accessURL, err := url.Parse(workspaceProvider.EnvproxyAccessURL)
23+
uri := workspaceProvider.EnvproxyAccessURL
24+
if workspaceProvider.EnableNetV2 {
25+
uri = client.BaseURL().String()
26+
}
27+
28+
accessURL, err := url.Parse(uri)
2429
if err != nil {
2530
return nil, xerrors.Errorf("invalid workspace provider envproxy access url: %w", err)
2631
}

0 commit comments

Comments
 (0)