Skip to content

fix: Write agent URL to file for gitssh #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 10 additions & 3 deletions cli/gitssh.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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())
Expand Down