From 65cfa6d3478e19bd7020f6c1ecd31369d8c0d052 Mon Sep 17 00:00:00 2001
From: Hidde Beydals <hello@hidde.co>
Date: Tue, 9 Jun 2020 12:42:37 +0200
Subject: [PATCH] Move port check to scanHostKey func

---
 cmd/tk/create_source_git.go | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/cmd/tk/create_source_git.go b/cmd/tk/create_source_git.go
index 9f112af9..97f4934f 100644
--- a/cmd/tk/create_source_git.go
+++ b/cmd/tk/create_source_git.go
@@ -140,11 +140,7 @@ func createSourceGitCmdRun(cmd *cobra.Command, args []string) error {
 		}
 
 		logAction("collecting preferred public key from SSH server")
-		host := u.Host
-		if u.Port() == "" {
-			host = host + ":22"
-		}
-		hostKey, err := scanHostKey(ctx, host)
+		hostKey, err := scanHostKey(ctx, u)
 		if err != nil {
 			return err
 		}
@@ -269,7 +265,11 @@ func generateKeyPair(ctx context.Context) (*ssh.KeyPair, error) {
 	return pair, nil
 }
 
-func scanHostKey(ctx context.Context, host string) ([]byte, error) {
+func scanHostKey(ctx context.Context, url *url.URL) ([]byte, error) {
+	host := url.Host
+	if url.Port() == "" {
+		host = host + ":22"
+	}
 	hostKey, err := ssh.ScanHostKey(host, 30*time.Second)
 	if err != nil {
 		return nil, fmt.Errorf("SSH key scan for host '%s' failed: %w", host, err)
-- 
GitLab