From bb6db4b309a582ab881d6b2a83fcd7fd0fe07a32 Mon Sep 17 00:00:00 2001 From: Caleb Brose <5447118+cmbrose@users.noreply.github.com> Date: Tue, 20 Sep 2022 22:00:27 +0000 Subject: [PATCH] PR suggestions --- pkg/cmd/codespace/ssh.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pkg/cmd/codespace/ssh.go b/pkg/cmd/codespace/ssh.go index f2d7f8673..4b8d9bfc9 100644 --- a/pkg/cmd/codespace/ssh.go +++ b/pkg/cmd/codespace/ssh.go @@ -277,23 +277,20 @@ func selectSSHKeys( return autoKeyPair, true, nil } - configKeyPair, err := firstConfiguredKeyPair(ctx, customConfigPath, opts.profile) - if err != nil && !errors.Is(err, errKeyFileNotFound) { - return nil, false, fmt.Errorf("checking configured keys: %w", err) - } - - // Even if there was no error, there may simply be no configured keys, so still check for nil here - if configKeyPair != nil { - return configKeyPair, true, nil - } - - // Finally, fall back to generating new automatic keys - autoKeyPair, err := generateAutomaticSSHKeys(sshContext) + keyPair, err := firstConfiguredKeyPair(ctx, customConfigPath, opts.profile) if err != nil { - return nil, false, fmt.Errorf("generating automatic keypair: %w", err) + if !errors.Is(err, errKeyFileNotFound) { + return nil, false, fmt.Errorf("checking configured keys: %w", err) + } + + // no valid key in ssh config, generate one + keyPair, err = generateAutomaticSSHKeys(sshContext) + if err != nil { + return nil, false, fmt.Errorf("generating automatic keypair: %w", err) + } } - return autoKeyPair, true, nil + return keyPair, true, nil } // automaticSSHKeyPair returns the paths to the automatic key pair files, if they both exist