From a41c44898864bd49966cf583e90044c85f5036a2 Mon Sep 17 00:00:00 2001 From: John Dietz Date: Sun, 17 Mar 2024 22:33:48 -0400 Subject: [PATCH] adding known host check for gitlab / github --- cmd/akamai/create.go | 34 ++++++++++++++++++---------------- cmd/aws/create.go | 34 ++++++++++++++++++---------------- cmd/civo/create.go | 34 ++++++++++++++++++---------------- cmd/digitalocean/create.go | 34 ++++++++++++++++++---------------- cmd/google/create.go | 34 ++++++++++++++++++---------------- cmd/vultr/create.go | 34 ++++++++++++++++++---------------- 6 files changed, 108 insertions(+), 96 deletions(-) diff --git a/cmd/akamai/create.go b/cmd/akamai/create.go index 0135ec70a..6201effa7 100644 --- a/cmd/akamai/create.go +++ b/cmd/akamai/create.go @@ -10,6 +10,7 @@ import ( "fmt" "os" + "github.com/rs/zerolog/log" "github.com/kubefirst/kubefirst/internal/catalog" "github.com/kubefirst/kubefirst/internal/cluster" "github.com/kubefirst/kubefirst/internal/gitShim" @@ -18,6 +19,7 @@ import ( "github.com/kubefirst/kubefirst/internal/provision" "github.com/kubefirst/kubefirst/internal/utilities" "github.com/kubefirst/runtime/pkg" + internalssh "github.com/kubefirst/runtime/pkg/ssh" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -106,22 +108,22 @@ func ValidateProvidedFlags(gitProvider string) error { } } - // switch gitProvider { - // case "github": - // key, err := internalssh.GetHostKey("github.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "github.com", key.Type()) - // } - // case "gitlab": - // key, err := internalssh.GetHostKey("gitlab.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) - // } - // } + switch gitProvider { + case "github": + key, err := internalssh.GetHostKey("github.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "github.com", key.Type()) + } + case "gitlab": + key, err := internalssh.GetHostKey("gitlab.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) + } + } progress.CompleteStep("Validate provided flags") diff --git a/cmd/aws/create.go b/cmd/aws/create.go index d34e0875d..2d53f4cd9 100644 --- a/cmd/aws/create.go +++ b/cmd/aws/create.go @@ -20,6 +20,8 @@ import ( "github.com/kubefirst/kubefirst/internal/utilities" "github.com/kubefirst/runtime/pkg" awsinternal "github.com/kubefirst/runtime/pkg/aws" + internalssh "github.com/kubefirst/runtime/pkg/ssh" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -131,22 +133,22 @@ func ValidateProvidedFlags(gitProvider string) error { } } - // switch gitProvider { - // case "github": - // key, err := internalssh.GetHostKey("github.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "github.com", key.Type()) - // } - // case "gitlab": - // key, err := internalssh.GetHostKey("gitlab.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) - // } - // } + switch gitProvider { + case "github": + key, err := internalssh.GetHostKey("github.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "github.com", key.Type()) + } + case "gitlab": + key, err := internalssh.GetHostKey("gitlab.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) + } + } progress.CompleteStep("Validate provided flags") diff --git a/cmd/civo/create.go b/cmd/civo/create.go index 38ab0a6a2..53864b535 100644 --- a/cmd/civo/create.go +++ b/cmd/civo/create.go @@ -18,6 +18,8 @@ import ( "github.com/kubefirst/kubefirst/internal/provision" "github.com/kubefirst/kubefirst/internal/utilities" "github.com/kubefirst/runtime/pkg" + internalssh "github.com/kubefirst/runtime/pkg/ssh" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -106,22 +108,22 @@ func ValidateProvidedFlags(gitProvider string) error { } } - // switch gitProvider { - // case "github": - // key, err := internalssh.GetHostKey("github.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "github.com", key.Type()) - // } - // case "gitlab": - // key, err := internalssh.GetHostKey("gitlab.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) - // } - // } + switch gitProvider { + case "github": + key, err := internalssh.GetHostKey("github.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "github.com", key.Type()) + } + case "gitlab": + key, err := internalssh.GetHostKey("gitlab.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) + } + } progress.CompleteStep("Validate provided flags") diff --git a/cmd/digitalocean/create.go b/cmd/digitalocean/create.go index 5eb03c0be..8d9a1eb79 100644 --- a/cmd/digitalocean/create.go +++ b/cmd/digitalocean/create.go @@ -18,6 +18,8 @@ import ( "github.com/kubefirst/kubefirst/internal/provision" "github.com/kubefirst/kubefirst/internal/utilities" "github.com/kubefirst/runtime/pkg" + internalssh "github.com/kubefirst/runtime/pkg/ssh" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -113,22 +115,22 @@ func ValidateProvidedFlags(gitProvider string) error { } } - // switch gitProvider { - // case "github": - // key, err := internalssh.GetHostKey("github.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "github.com", key.Type()) - // } - // case "gitlab": - // key, err := internalssh.GetHostKey("gitlab.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) - // } - // } + switch gitProvider { + case "github": + key, err := internalssh.GetHostKey("github.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "github.com", key.Type()) + } + case "gitlab": + key, err := internalssh.GetHostKey("gitlab.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) + } + } progress.CompleteStep("Validate provided flags") diff --git a/cmd/google/create.go b/cmd/google/create.go index 22cba021d..ce613c227 100644 --- a/cmd/google/create.go +++ b/cmd/google/create.go @@ -18,6 +18,8 @@ import ( "github.com/kubefirst/kubefirst/internal/provision" "github.com/kubefirst/kubefirst/internal/utilities" "github.com/kubefirst/runtime/pkg" + internalssh "github.com/kubefirst/runtime/pkg/ssh" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -107,22 +109,22 @@ func ValidateProvidedFlags(gitProvider string) error { progress.Error("Unable to read GOOGLE_APPLICATION_CREDENTIALS file") } - // switch gitProvider { - // case "github": - // key, err := internalssh.GetHostKey("github.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "github.com", key.Type()) - // } - // case "gitlab": - // key, err := internalssh.GetHostKey("gitlab.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) - // } - // } + switch gitProvider { + case "github": + key, err := internalssh.GetHostKey("github.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "github.com", key.Type()) + } + case "gitlab": + key, err := internalssh.GetHostKey("gitlab.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) + } + } progress.CompleteStep("Validate provided flags") diff --git a/cmd/vultr/create.go b/cmd/vultr/create.go index 0b8cd873c..0b3a5c2b9 100644 --- a/cmd/vultr/create.go +++ b/cmd/vultr/create.go @@ -18,6 +18,8 @@ import ( "github.com/kubefirst/kubefirst/internal/provision" "github.com/kubefirst/kubefirst/internal/utilities" "github.com/kubefirst/runtime/pkg" + internalssh "github.com/kubefirst/runtime/pkg/ssh" + "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -112,22 +114,22 @@ func ValidateProvidedFlags(gitProvider string) error { } } - // switch gitProvider { - // case "github": - // key, err := internalssh.GetHostKey("github.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "github.com", key.Type()) - // } - // case "gitlab": - // key, err := internalssh.GetHostKey("gitlab.com") - // if err != nil { - // return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") - // } else { - // log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) - // } - // } + switch gitProvider { + case "github": + key, err := internalssh.GetHostKey("github.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan github.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "github.com", key.Type()) + } + case "gitlab": + key, err := internalssh.GetHostKey("gitlab.com") + if err != nil { + return fmt.Errorf("known_hosts file does not exist - please run `ssh-keyscan gitlab.com >> ~/.ssh/known_hosts` to remedy") + } else { + log.Info().Msgf("%s %s\n", "gitlab.com", key.Type()) + } + } progress.CompleteStep("Validate provided flags")