diff --git a/cli/agent.go b/cli/agent.go index d17aa60e82491..cb1a456105752 100644 --- a/cli/agent.go +++ b/cli/agent.go @@ -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() diff --git a/cli/gitssh.go b/cli/gitssh.go index 6945c652dd8e6..e92b201023b02 100644 --- a/cli/gitssh.go +++ b/cli/gitssh.go @@ -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) + cfg := createConfig(cmd) + rawURL, err := cfg.URL().Read() if err != nil { - return xerrors.Errorf("create codersdk client: %w", err) + 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) } - cfg := createConfig(cmd) 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())