Skip to content

Commit 8ff0c8b

Browse files
authored
fix: Write agent URL to file for gitssh (coder#1123)
This was broken because gitssh couldn't find the URL. Now it can, and SSH is confirmed to work on dogfood! 🥳
1 parent 68f67c5 commit 8ff0c8b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

cli/agent.go

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func workspaceAgent() *cobra.Command {
120120
if err != nil {
121121
return xerrors.Errorf("writing agent session token to config: %w", err)
122122
}
123+
err = cfg.URL().Write(client.URL.String())
124+
if err != nil {
125+
return xerrors.Errorf("writing agent url to config: %w", err)
126+
}
123127

124128
closer := agent.New(client.ListenWorkspaceAgent, logger)
125129
<-cmd.Context().Done()

cli/gitssh.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package cli
22

33
import (
4+
"net/url"
45
"os"
56
"os/exec"
67

8+
"github.com/coder/coder/codersdk"
79
"github.com/spf13/cobra"
810
"golang.org/x/xerrors"
911
)
@@ -14,15 +16,20 @@ func gitssh() *cobra.Command {
1416
Hidden: true,
1517
Short: `Wraps the "ssh" command and uses the coder gitssh key for authentication`,
1618
RunE: func(cmd *cobra.Command, args []string) error {
17-
client, err := createClient(cmd)
19+
cfg := createConfig(cmd)
20+
rawURL, err := cfg.URL().Read()
1821
if err != nil {
19-
return xerrors.Errorf("create codersdk client: %w", err)
22+
return xerrors.Errorf("read agent url from config: %w", err)
23+
}
24+
parsedURL, err := url.Parse(rawURL)
25+
if err != nil {
26+
return xerrors.Errorf("parse agent url from config: %w", err)
2027
}
21-
cfg := createConfig(cmd)
2228
session, err := cfg.AgentSession().Read()
2329
if err != nil {
2430
return xerrors.Errorf("read agent session from config: %w", err)
2531
}
32+
client := codersdk.New(parsedURL)
2633
client.SessionToken = session
2734

2835
key, err := client.AgentGitSSHKey(cmd.Context())

0 commit comments

Comments
 (0)