fix: Write agent URL to file for gitssh (#1123)

This was broken because gitssh couldn't find the URL.
Now it can, and SSH is confirmed to work on dogfood! 🥳
This commit is contained in:
Kyle Carberry 2022-04-24 23:06:52 -05:00 committed by GitHub
parent 68f67c54b6
commit 8ff0c8b02a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -120,6 +120,10 @@ func workspaceAgent() *cobra.Command {
if err != nil {
return xerrors.Errorf("writing agent session token to config: %w", err)
}
err = cfg.URL().Write(client.URL.String())
if err != nil {
return xerrors.Errorf("writing agent url to config: %w", err)
}
closer := agent.New(client.ListenWorkspaceAgent, logger)
<-cmd.Context().Done()

View File

@ -1,9 +1,11 @@
package cli
import (
"net/url"
"os"
"os/exec"
"github.com/coder/coder/codersdk"
"github.com/spf13/cobra"
"golang.org/x/xerrors"
)
@ -14,15 +16,20 @@ func gitssh() *cobra.Command {
Hidden: true,
Short: `Wraps the "ssh" command and uses the coder gitssh key for authentication`,
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
if err != nil {
return xerrors.Errorf("create codersdk client: %w", err)
}
cfg := createConfig(cmd)
rawURL, err := cfg.URL().Read()
if err != nil {
return xerrors.Errorf("read agent url from config: %w", err)
}
parsedURL, err := url.Parse(rawURL)
if err != nil {
return xerrors.Errorf("parse agent url from config: %w", err)
}
session, err := cfg.AgentSession().Read()
if err != nil {
return xerrors.Errorf("read agent session from config: %w", err)
}
client := codersdk.New(parsedURL)
client.SessionToken = session
key, err := client.AgentGitSSHKey(cmd.Context())