From a9d02a746baa3b3cfa17d7c9cd1f80e030cb4f65 Mon Sep 17 00:00:00 2001 From: Jason Lunz Date: Thu, 16 Dec 2021 17:19:34 -0700 Subject: [PATCH] push fetching codespace details into openSSHSession callers --- pkg/cmd/codespace/ssh.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/codespace/ssh.go b/pkg/cmd/codespace/ssh.go index 5654f3432..33f837bbc 100644 --- a/pkg/cmd/codespace/ssh.go +++ b/pkg/cmd/codespace/ssh.go @@ -90,7 +90,12 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e a.errLogger.Printf("Debug file located at: %s", debugLogger.Name()) } - session, err := openSSHSession(ctx, a, opts.codespace, liveshareLogger) + codespace, err := getOrChooseCodespace(ctx, a.apiClient, opts.codespace) + if err != nil { + return fmt.Errorf("get or choose codespace: %w", err) + } + + session, err := openSSHSession(ctx, a, codespace, liveshareLogger) if err != nil { return fmt.Errorf("error connecting to codespace: %w", err) } @@ -209,7 +214,12 @@ func (a *App) printOpenSSHConfig(ctx context.Context, opts configOptions) error sshUser, ok := sshUsers[cs.Repository.FullName] if !ok { - session, err := openSSHSession(ctx, a, cs.Name, nil) + codespace, err := a.apiClient.GetCodespace(ctx, cs.Name, true) + if err != nil { + return fmt.Errorf("getting full codespace details: %w", err) + } + + session, err := openSSHSession(ctx, a, codespace, nil) if err != nil { fmt.Fprintf(os.Stderr, "error connecting to codespace: %v\n", err) @@ -262,12 +272,7 @@ type codespaceSSHConfig struct { GHExec string // path used for invoking the current `gh` binary } -func openSSHSession(ctx context.Context, a *App, csName string, liveshareLogger *log.Logger) (*liveshare.Session, error) { - codespace, err := getOrChooseCodespace(ctx, a.apiClient, csName) - if err != nil { - return nil, fmt.Errorf("get or choose codespace: %w", err) - } - +func openSSHSession(ctx context.Context, a *App, codespace *api.Codespace, liveshareLogger *log.Logger) (*liveshare.Session, error) { // TODO(josebalius): We can fetch the user in parallel to everything else // we should convert this call and others to happen async user, err := a.apiClient.GetUser(ctx)