From 29522b51d22bc48baf61cb51161303b48b52b508 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 14 Feb 2022 15:29:48 +0200 Subject: [PATCH 01/32] New lakectl command 'doctor' to run a basic diagnosis of lakeFS configuration. --- cmd/lakectl/cmd/common_helpers.go | 43 ++++++++ cmd/lakectl/cmd/doctor.go | 104 ++++++++++++++++++ docs/reference/commands.md | 10 ++ nessie/doctor_test.go | 27 +++++ ...ctor_invalid_char_secret_access_key.golden | 3 + ...kectl_doctor_long_secret_access_key.golden | 3 + nessie/golden/lakectl_doctor_ok.golden | 1 + ...ectl_doctor_short_secret_access_key.golden | 3 + ...tor_with_invalid_char_access_key_id.golden | 3 + ...ctor_with_long_length_access_key_id.golden | 3 + ...octor_with_lower_case_access_key_id.golden | 3 + ...tor_with_short_length_access_key_id.golden | 3 + ...tor_with_wrong_prefix_access_key_id.golden | 3 + ...ctor_with_wrong_sufix_access_key_id.golden | 2 + .../lakectl_doctor_wrong_access_key_id.golden | 2 + .../lakectl_doctor_wrong_endpoint.golden | 2 + ...ectl_doctor_wrong_secret_access_key.golden | 2 + ...tl_doctor_wrong_uri_format_endpoint.golden | 2 + nessie/lakectl_util.go | 11 +- 19 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 cmd/lakectl/cmd/doctor.go create mode 100644 nessie/doctor_test.go create mode 100644 nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden create mode 100644 nessie/golden/lakectl_doctor_long_secret_access_key.golden create mode 100644 nessie/golden/lakectl_doctor_ok.golden create mode 100644 nessie/golden/lakectl_doctor_short_secret_access_key.golden create mode 100644 nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden create mode 100644 nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden create mode 100644 nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden create mode 100644 nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden create mode 100644 nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden create mode 100644 nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden create mode 100644 nessie/golden/lakectl_doctor_wrong_access_key_id.golden create mode 100644 nessie/golden/lakectl_doctor_wrong_endpoint.golden create mode 100644 nessie/golden/lakectl_doctor_wrong_secret_access_key.golden create mode 100644 nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 20aeb4f11f7..2154b6d945f 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -2,15 +2,18 @@ package cmd import ( "bytes" + "encoding/base64" "encoding/json" "errors" "fmt" "io" "net/http" + "net/url" "os" "strings" "text/template" "time" + "unicode" "github.com/treeverse/lakefs/pkg/uri" @@ -267,3 +270,43 @@ func MustParsePathURI(name, s string) *uri.URI { } return u } + +func IsValidAccessKeyID(accessKeyID string) bool { + return (len(accessKeyID) == 20 && (strings.HasPrefix(accessKeyID, "ASIA") || strings.HasPrefix(accessKeyID, "AKIA")) && (string(accessKeyID[4]) == "I" || string(accessKeyID[4]) == "J") && (strings.HasSuffix(accessKeyID, "A") || strings.HasSuffix(accessKeyID, "Q")) && IsContainOnlyUpperLettersOrNumber(accessKeyID)) +} + +func IsValidSecretAccessKey(secretAcceessKey string) bool { + return (IsBase64(secretAcceessKey) && len(secretAcceessKey) == 40) +} + +func IsBase64(s string) bool { + _, err := base64.StdEncoding.DecodeString(s) + return err == nil +} + +func IsContainOnlyUpperLettersOrNumber(s string) bool { + for _, r := range s { + if !unicode.IsNumber(r) && !unicode.IsUpper(r) { + return false + } + } + return true +} + +func IsValidUrI(URI string) bool { + _, err := url.ParseRequestURI(URI) + if err != nil { + return false + } + + u, err := url.Parse(URI) + if err != nil || u.Scheme == "" || u.Host == "" { + return false + } + + return true +} + +func IsValidEndpointUrI(URI string) bool { + return (IsValidUrI(URI) && strings.HasSuffix(URI, api.BaseURL)) +} diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go new file mode 100644 index 00000000000..103e9de619a --- /dev/null +++ b/cmd/lakectl/cmd/doctor.go @@ -0,0 +1,104 @@ +package cmd + +import ( + "errors" + "fmt" + "strings" + + "github.com/deepmap/oapi-codegen/pkg/securityprovider" + "github.com/mitchellh/go-homedir" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "github.com/treeverse/lakefs/cmd/lakectl/cmd/config" + "github.com/treeverse/lakefs/pkg/api" +) + +// doctorCmd represents the doctor command +var doctorCmd = &cobra.Command{ + Use: "doctor", + Short: "Run a basic diagnosis of the LakeFS configuration", + Run: func(cmd *cobra.Command, args []string) { + // Find home directory. + home, err := homedir.Dir() + if err != nil { + DieErr(err) + } + + // Search config in home directory with name ".lakefs" (without extension). + viper.AddConfigPath(home) + viper.SetConfigType("yaml") + viper.SetConfigName(".lakectl") + viper.SetEnvPrefix("LAKECTL") + viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // support nested config + viper.AutomaticEnv() // read in environment variables that match + + cfg := config.ReadConfig() + cfgError := cfg.Err() + if cfgError != nil { + if errors.As(cfgError, &viper.ConfigFileNotFoundError{}) { + // specific message in case the file isn't found + DieFmt("Config file not found, please run \"lakectl config\" to create one\n%s\n", cfg.Err()) + } + // other errors while reading the config file + DieFmt("Error reading configuration file: %v", cfgError) + } + + if err := viper.UnmarshalExact(&cfg.Values); err != nil { + DieFmt("Error unmarshal configuration: %v", err) + } + + accessKeyID := cfg.Values.Credentials.AccessKeyID + if !IsValidAccessKeyID(accessKeyID) { + fmt.Println("access_key_id value looks suspicious...") + } + + secretAccessKey := cfg.Values.Credentials.SecretAccessKey + if !IsValidSecretAccessKey(secretAccessKey) { + fmt.Println("secret_access_key value looks suspicious...") + } + + basicAuthProvider, err := securityprovider.NewSecurityProviderBasicAuth(accessKeyID, secretAccessKey) + if err != nil { + DieErr(err) + } + + serverEndpoint := cfg.Values.Server.EndpointURL + if !IsValidEndpointUrI(serverEndpoint) { + DieFmt("Wrong URI format for server.endpoint_url: %v", serverEndpoint) + } + + client, err := api.NewClientWithResponses( + serverEndpoint, + api.WithRequestEditorFn(basicAuthProvider.Intercept), + ) + if err != nil { + DieFmt("Could not initialize API client: %v", err.Error()) + } + + loginReq := api.LoginJSONRequestBody{ + AccessKeyId: accessKeyID, + SecretAccessKey: secretAccessKey, + } + + login, err := client.LoginWithResponse(cmd.Context(), loginReq) + if err != nil { + DieFmt("Login: %v", err.Error()) + } + if login.JSON200 == nil { + DieFmt("Failed to login: %v", login.Status()) + } + + rsp, _ := client.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{}) + rsp.StatusCode() + if rsp.JSON200 != nil { + fmt.Println("LakeFS doctor could not find any configuration issues") + } else { + fmt.Print("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong \n\n") + } + }, +} + +//nolint:gochecknoinits +func init() { + rootCmd.AddCommand(doctorCmd) +} diff --git a/docs/reference/commands.md b/docs/reference/commands.md index de5441906fd..cca6e2480e5 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -1733,7 +1733,17 @@ lakectl docs [outfile] [flags] -h, --help help for docs ``` +### lakectl doctor +This command does a basic diagnosis of lakeFS configuration. + + +#### Options +{:.no_toc} + +``` + -h, --help help for docs +``` ### lakectl fs diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go new file mode 100644 index 00000000000..9a10e40c3c1 --- /dev/null +++ b/nessie/doctor_test.go @@ -0,0 +1,27 @@ +package nessie + +import ( + "testing" + + "github.com/spf13/viper" +) + +func TestDoctor(t *testing.T) { + accessKeyID := viper.GetString("access_key_id") + secretAccessKey := viper.GetString("secret_access_key") + endPointURL := viper.GetString("endpoint_url") + "/api/v1" + RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_ok", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIhCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_lower_case_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIBJOIHCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_prefix_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIHCOZ5JBYHCSDA", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_sufix_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOICO!Z5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_invalid_char_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOICOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_short_length_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIHHCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_long_length_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", endPointURL)+" doctor", false, "lakectl_doctor_wrong_secret_access_key", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ", endPointURL)+" doctor", false, "lakectl_doctor_short_secret_access_key", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJzz", endPointURL)+" doctor", false, "lakectl_doctor_long_secret_access_key", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ!", endPointURL)+" doctor", false, "lakectl_doctor_invalid_char_secret_access_key", emptyVars) +} diff --git a/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden b/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden new file mode 100644 index 00000000000..248f14df7b6 --- /dev/null +++ b/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden @@ -0,0 +1,3 @@ +secret_access_key value looks suspicious... +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_long_secret_access_key.golden b/nessie/golden/lakectl_doctor_long_secret_access_key.golden new file mode 100644 index 00000000000..248f14df7b6 --- /dev/null +++ b/nessie/golden/lakectl_doctor_long_secret_access_key.golden @@ -0,0 +1,3 @@ +secret_access_key value looks suspicious... +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_ok.golden b/nessie/golden/lakectl_doctor_ok.golden new file mode 100644 index 00000000000..e4673676cc1 --- /dev/null +++ b/nessie/golden/lakectl_doctor_ok.golden @@ -0,0 +1 @@ +LakeFS doctor could not find any configuration issues diff --git a/nessie/golden/lakectl_doctor_short_secret_access_key.golden b/nessie/golden/lakectl_doctor_short_secret_access_key.golden new file mode 100644 index 00000000000..248f14df7b6 --- /dev/null +++ b/nessie/golden/lakectl_doctor_short_secret_access_key.golden @@ -0,0 +1,3 @@ +secret_access_key value looks suspicious... +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden b/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden new file mode 100644 index 00000000000..1ce211975e9 --- /dev/null +++ b/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden @@ -0,0 +1,3 @@ +access_key_id value looks suspicious... +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden b/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden new file mode 100644 index 00000000000..1ce211975e9 --- /dev/null +++ b/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden @@ -0,0 +1,3 @@ +access_key_id value looks suspicious... +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden b/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden new file mode 100644 index 00000000000..1ce211975e9 --- /dev/null +++ b/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden @@ -0,0 +1,3 @@ +access_key_id value looks suspicious... +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden b/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden new file mode 100644 index 00000000000..1ce211975e9 --- /dev/null +++ b/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden @@ -0,0 +1,3 @@ +access_key_id value looks suspicious... +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden b/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden new file mode 100644 index 00000000000..1ce211975e9 --- /dev/null +++ b/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden @@ -0,0 +1,3 @@ +access_key_id value looks suspicious... +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden b/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden new file mode 100644 index 00000000000..4bec5246efe --- /dev/null +++ b/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden @@ -0,0 +1,2 @@ +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden new file mode 100644 index 00000000000..4bec5246efe --- /dev/null +++ b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden @@ -0,0 +1,2 @@ +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden new file mode 100644 index 00000000000..399033fe77e --- /dev/null +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -0,0 +1,2 @@ +Wrong URI format for server.endpoint_url: http://localhost:8000/api/v11 +Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden b/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden new file mode 100644 index 00000000000..4bec5246efe --- /dev/null +++ b/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden @@ -0,0 +1,2 @@ +Login: json: cannot unmarshal string into Go value of type api.Error +Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden new file mode 100644 index 00000000000..08f8f3b2749 --- /dev/null +++ b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden @@ -0,0 +1,2 @@ +Wrong URI format for server.endpoint_url: wrong_uri +Error executing command. diff --git a/nessie/lakectl_util.go b/nessie/lakectl_util.go index 168123863dc..ee8d572c88c 100644 --- a/nessie/lakectl_util.go +++ b/nessie/lakectl_util.go @@ -26,7 +26,16 @@ func Lakectl() string { lakectlCmdline := "LAKECTL_CREDENTIALS_ACCESS_KEY_ID=" + viper.GetString("access_key_id") + " LAKECTL_CREDENTIALS_SECRET_ACCESS_KEY=" + viper.GetString("secret_access_key") + - " LAKECTL_SERVER_ENDPOINT_URL=" + viper.GetString("endpoint_url") + + " LAKECTL_SERVER_ENDPOINT_URL=" + viper.GetString("endpoint_url") + + " " + lakectlLocation() + + return lakectlCmdline +} +func LakectlWithParams(accessKeyID, secretAcceessKey, endPointURL string) string { + lakectlCmdline := + "LAKECTL_CREDENTIALS_ACCESS_KEY_ID=" + accessKeyID + + " LAKECTL_CREDENTIALS_SECRET_ACCESS_KEY=" + secretAcceessKey + + " LAKECTL_SERVER_ENDPOINT_URL=" + endPointURL + " " + lakectlLocation() return lakectlCmdline From 2528ff0d1295d4c54f754b3374a82de4e19c4596 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 14 Feb 2022 15:48:50 +0200 Subject: [PATCH 02/32] Fixed command outputs --- cmd/lakectl/cmd/doctor.go | 2 ++ docs/reference/commands.md | 11 +++++++++-- nessie/doctor_test.go | 2 +- ...kectl_doctor_invalid_char_secret_access_key.golden | 3 +++ .../lakectl_doctor_long_secret_access_key.golden | 3 +++ .../lakectl_doctor_short_secret_access_key.golden | 3 +++ ...ectl_doctor_with_invalid_char_access_key_id.golden | 3 +++ ...kectl_doctor_with_long_length_access_key_id.golden | 3 +++ ...akectl_doctor_with_lower_case_access_key_id.golden | 3 +++ ...ectl_doctor_with_short_length_access_key_id.golden | 3 +++ ...ectl_doctor_with_wrong_prefix_access_key_id.golden | 3 +++ ...kectl_doctor_with_wrong_sufix_access_key_id.golden | 4 ++++ .../golden/lakectl_doctor_wrong_access_key_id.golden | 3 +++ .../lakectl_doctor_wrong_secret_access_key.golden | 3 +++ 14 files changed, 46 insertions(+), 3 deletions(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 103e9de619a..4707b294232 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -82,9 +82,11 @@ var doctorCmd = &cobra.Command{ login, err := client.LoginWithResponse(cmd.Context(), loginReq) if err != nil { + fmt.Print("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong \n\n") DieFmt("Login: %v", err.Error()) } if login.JSON200 == nil { + fmt.Print("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong \n\n") DieFmt("Failed to login: %v", login.Status()) } diff --git a/docs/reference/commands.md b/docs/reference/commands.md index cca6e2480e5..ff7bc15aa70 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -1733,18 +1733,25 @@ lakectl docs [outfile] [flags] -h, --help help for docs ``` + + ### lakectl doctor -This command does a basic diagnosis of lakeFS configuration. +Run a basic diagnosis of the LakeFS configuration +``` +lakectl doctor [flags] +``` #### Options {:.no_toc} ``` - -h, --help help for docs + -h, --help help for doctor ``` + + ### lakectl fs View and manipulate objects diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index 9a10e40c3c1..3b3f5e2c90e 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -16,7 +16,7 @@ func TestDoctor(t *testing.T) { RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_access_key_id", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIhCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_lower_case_access_key_id", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIBJOIHCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_prefix_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIHCOZ5JBYHCSDA", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_sufix_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIHCOZ5JBYHCSDB", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_sufix_access_key_id", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOICO!Z5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_invalid_char_access_key_id", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOICOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_short_length_access_key_id", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIHHCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_long_length_access_key_id", emptyVars) diff --git a/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden b/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden index 248f14df7b6..90363cbd6b1 100644 --- a/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden @@ -1,3 +1,6 @@ secret_access_key value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_long_secret_access_key.golden b/nessie/golden/lakectl_doctor_long_secret_access_key.golden index 248f14df7b6..90363cbd6b1 100644 --- a/nessie/golden/lakectl_doctor_long_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_long_secret_access_key.golden @@ -1,3 +1,6 @@ secret_access_key value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_short_secret_access_key.golden b/nessie/golden/lakectl_doctor_short_secret_access_key.golden index 248f14df7b6..90363cbd6b1 100644 --- a/nessie/golden/lakectl_doctor_short_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_short_secret_access_key.golden @@ -1,3 +1,6 @@ secret_access_key value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden b/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden index 1ce211975e9..8572a9b8e08 100644 --- a/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden @@ -1,3 +1,6 @@ access_key_id value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden b/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden index 1ce211975e9..8572a9b8e08 100644 --- a/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden @@ -1,3 +1,6 @@ access_key_id value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden b/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden index 1ce211975e9..8572a9b8e08 100644 --- a/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden @@ -1,3 +1,6 @@ access_key_id value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden b/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden index 1ce211975e9..8572a9b8e08 100644 --- a/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden @@ -1,3 +1,6 @@ access_key_id value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden b/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden index 1ce211975e9..8572a9b8e08 100644 --- a/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden @@ -1,3 +1,6 @@ access_key_id value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden b/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden index 4bec5246efe..8572a9b8e08 100644 --- a/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden @@ -1,2 +1,6 @@ +access_key_id value looks suspicious... +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden index 4bec5246efe..39029dc8771 100644 --- a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden @@ -1,2 +1,5 @@ +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden b/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden index 4bec5246efe..39029dc8771 100644 --- a/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden @@ -1,2 +1,5 @@ +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong + Login: json: cannot unmarshal string into Go value of type api.Error Error executing command. From 3e69a10290636c781c3a055b8d6c0d31ff456558 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 14 Feb 2022 15:54:45 +0200 Subject: [PATCH 03/32] Fixed command outputs --- cmd/lakectl/cmd/doctor.go | 9 ++------- .../lakectl_doctor_invalid_char_secret_access_key.golden | 2 +- .../golden/lakectl_doctor_long_secret_access_key.golden | 2 +- .../golden/lakectl_doctor_short_secret_access_key.golden | 2 +- ...lakectl_doctor_with_invalid_char_access_key_id.golden | 2 +- .../lakectl_doctor_with_long_length_access_key_id.golden | 2 +- .../lakectl_doctor_with_lower_case_access_key_id.golden | 2 +- ...lakectl_doctor_with_short_length_access_key_id.golden | 2 +- ...lakectl_doctor_with_wrong_prefix_access_key_id.golden | 2 +- .../lakectl_doctor_with_wrong_sufix_access_key_id.golden | 2 +- nessie/golden/lakectl_doctor_wrong_access_key_id.golden | 2 +- .../golden/lakectl_doctor_wrong_secret_access_key.golden | 2 +- 12 files changed, 13 insertions(+), 18 deletions(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 4707b294232..085ff773e54 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -81,13 +81,8 @@ var doctorCmd = &cobra.Command{ } login, err := client.LoginWithResponse(cmd.Context(), loginReq) - if err != nil { - fmt.Print("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong \n\n") - DieFmt("Login: %v", err.Error()) - } - if login.JSON200 == nil { - fmt.Print("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong \n\n") - DieFmt("Failed to login: %v", login.Status()) + if err != nil || login.JSON200 == nil { + DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong \n\n") } rsp, _ := client.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{}) diff --git a/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden b/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden index 90363cbd6b1..b9406b8c1da 100644 --- a/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden @@ -2,5 +2,5 @@ secret_access_key value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_long_secret_access_key.golden b/nessie/golden/lakectl_doctor_long_secret_access_key.golden index 90363cbd6b1..b9406b8c1da 100644 --- a/nessie/golden/lakectl_doctor_long_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_long_secret_access_key.golden @@ -2,5 +2,5 @@ secret_access_key value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_short_secret_access_key.golden b/nessie/golden/lakectl_doctor_short_secret_access_key.golden index 90363cbd6b1..b9406b8c1da 100644 --- a/nessie/golden/lakectl_doctor_short_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_short_secret_access_key.golden @@ -2,5 +2,5 @@ secret_access_key value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden b/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden index 8572a9b8e08..3f2f8a2aa9f 100644 --- a/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden @@ -2,5 +2,5 @@ access_key_id value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden b/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden index 8572a9b8e08..3f2f8a2aa9f 100644 --- a/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden @@ -2,5 +2,5 @@ access_key_id value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden b/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden index 8572a9b8e08..3f2f8a2aa9f 100644 --- a/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden @@ -2,5 +2,5 @@ access_key_id value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden b/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden index 8572a9b8e08..3f2f8a2aa9f 100644 --- a/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden @@ -2,5 +2,5 @@ access_key_id value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden b/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden index 8572a9b8e08..3f2f8a2aa9f 100644 --- a/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden @@ -2,5 +2,5 @@ access_key_id value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden b/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden index 8572a9b8e08..3f2f8a2aa9f 100644 --- a/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden @@ -2,5 +2,5 @@ access_key_id value looks suspicious... It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden index 39029dc8771..1d1198a6995 100644 --- a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden @@ -1,5 +1,5 @@ It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden b/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden index 39029dc8771..1d1198a6995 100644 --- a/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden @@ -1,5 +1,5 @@ It looks like you have a problem with your '.lakectl.yaml' file. It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong -Login: json: cannot unmarshal string into Go value of type api.Error + Error executing command. From 531371cc71a7418e3d8944c1b486f0dbf8b7915d Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 14 Feb 2022 16:21:34 +0200 Subject: [PATCH 04/32] Fixed linter comments --- cmd/lakectl/cmd/common_helpers.go | 2 +- cmd/lakectl/cmd/doctor.go | 2 +- nessie/lakectl_util.go | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 2154b6d945f..71929b9af69 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -307,6 +307,6 @@ func IsValidUrI(URI string) bool { return true } -func IsValidEndpointUrI(URI string) bool { +func IsValidEndpointURI(URI string) bool { return (IsValidUrI(URI) && strings.HasSuffix(URI, api.BaseURL)) } diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 085ff773e54..a6a2235db6f 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -63,7 +63,7 @@ var doctorCmd = &cobra.Command{ } serverEndpoint := cfg.Values.Server.EndpointURL - if !IsValidEndpointUrI(serverEndpoint) { + if !IsValidEndpointURI(serverEndpoint) { DieFmt("Wrong URI format for server.endpoint_url: %v", serverEndpoint) } diff --git a/nessie/lakectl_util.go b/nessie/lakectl_util.go index ee8d572c88c..3ad9fd4d2d8 100644 --- a/nessie/lakectl_util.go +++ b/nessie/lakectl_util.go @@ -31,6 +31,7 @@ func Lakectl() string { return lakectlCmdline } + func LakectlWithParams(accessKeyID, secretAcceessKey, endPointURL string) string { lakectlCmdline := "LAKECTL_CREDENTIALS_ACCESS_KEY_ID=" + accessKeyID + From 9c4e5dec85c1bb9eb7105e19d5414d166c05de4b Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 14 Feb 2022 16:32:25 +0200 Subject: [PATCH 05/32] Fixed linter comments --- cmd/lakectl/cmd/common_helpers.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 71929b9af69..e921560df9c 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -293,13 +293,13 @@ func IsContainOnlyUpperLettersOrNumber(s string) bool { return true } -func IsValidUrI(URI string) bool { - _, err := url.ParseRequestURI(URI) +func IsValidURI(uri string) bool { + _, err := url.ParseRequestURI(uri) if err != nil { return false } - u, err := url.Parse(URI) + u, err := url.Parse(uri) if err != nil || u.Scheme == "" || u.Host == "" { return false } @@ -307,6 +307,6 @@ func IsValidUrI(URI string) bool { return true } -func IsValidEndpointURI(URI string) bool { - return (IsValidUrI(URI) && strings.HasSuffix(URI, api.BaseURL)) +func IsValidEndpointURI(uri string) bool { + return (IsValidURI(uri) && strings.HasSuffix(uri, api.BaseURL)) } From 91b1b8932f6db31675890e92f92376197ca8746d Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 14 Feb 2022 18:01:05 +0200 Subject: [PATCH 06/32] Fixed a bug of ignoring the '--config' flag --- cmd/lakectl/cmd/doctor.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index a6a2235db6f..82042d911c8 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -3,6 +3,7 @@ package cmd import ( "errors" "fmt" + "path/filepath" "strings" "github.com/deepmap/oapi-codegen/pkg/securityprovider" @@ -18,16 +19,16 @@ var doctorCmd = &cobra.Command{ Use: "doctor", Short: "Run a basic diagnosis of the LakeFS configuration", Run: func(cmd *cobra.Command, args []string) { - // Find home directory. - home, err := homedir.Dir() - if err != nil { - DieErr(err) + if viper.ConfigFileUsed() == "" { + // Find home directory. + home, err := homedir.Dir() + if err != nil { + DieErr(err) + } + // Setup default config file + viper.SetConfigFile(filepath.Join(home, ".lakectl.yaml")) } - // Search config in home directory with name ".lakefs" (without extension). - viper.AddConfigPath(home) - viper.SetConfigType("yaml") - viper.SetConfigName(".lakectl") viper.SetEnvPrefix("LAKECTL") viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // support nested config viper.AutomaticEnv() // read in environment variables that match From c2fb59b230b35eaac763b9b36e6054c4d16b533d Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 14 Feb 2022 18:34:09 +0200 Subject: [PATCH 07/32] Added tests for bad config files --- nessie/doctor_test.go | 9 +++++++++ nessie/golden/lakectl_doctor_empty_file.golden | 4 ++++ nessie/golden/lakectl_doctor_not_existed_file.golden | 2 ++ nessie/golden/lakectl_doctor_wrong_format_file.golden | 3 +++ 4 files changed, 18 insertions(+) create mode 100644 nessie/golden/lakectl_doctor_empty_file.golden create mode 100644 nessie/golden/lakectl_doctor_not_existed_file.golden create mode 100644 nessie/golden/lakectl_doctor_wrong_format_file.golden diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index 3b3f5e2c90e..16d98730735 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -1,6 +1,8 @@ package nessie import ( + "io/ioutil" + "os" "testing" "github.com/spf13/viper" @@ -10,7 +12,14 @@ func TestDoctor(t *testing.T) { accessKeyID := viper.GetString("access_key_id") secretAccessKey := viper.GetString("secret_access_key") endPointURL := viper.GetString("endpoint_url") + "/api/v1" + emptyConfigFileName := "empty.yaml" + wrongFormatFileName := "wrong_format.yaml" + os.Create(emptyConfigFileName) + ioutil.WriteFile(wrongFormatFileName, []byte("nothing"), 0644) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_ok", emptyVars) + RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c "+wrongFormatFileName, false, "lakectl_doctor_wrong_format_file", emptyVars) + RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c "+emptyConfigFileName, false, "lakectl_doctor_empty_file", emptyVars) + RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exited.yaml", false, "lakectl_doctor_not_existed_file", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_access_key_id", emptyVars) diff --git a/nessie/golden/lakectl_doctor_empty_file.golden b/nessie/golden/lakectl_doctor_empty_file.golden new file mode 100644 index 00000000000..6baf7f28988 --- /dev/null +++ b/nessie/golden/lakectl_doctor_empty_file.golden @@ -0,0 +1,4 @@ +access_key_id value looks suspicious... +secret_access_key value looks suspicious... +Wrong URI format for server.endpoint_url: http://127.0.0.1:8000 +Error executing command. diff --git a/nessie/golden/lakectl_doctor_not_existed_file.golden b/nessie/golden/lakectl_doctor_not_existed_file.golden new file mode 100644 index 00000000000..325f01b1c03 --- /dev/null +++ b/nessie/golden/lakectl_doctor_not_existed_file.golden @@ -0,0 +1,2 @@ +error reading configuration file: open not_exited.yaml: no such file or directory +Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_format_file.golden b/nessie/golden/lakectl_doctor_wrong_format_file.golden new file mode 100644 index 00000000000..0c82d02c9c6 --- /dev/null +++ b/nessie/golden/lakectl_doctor_wrong_format_file.golden @@ -0,0 +1,3 @@ +error reading configuration file: While parsing config: yaml: unmarshal errors: + line 1: cannot unmarshal !!str `nothing` into map[string]interface {} +Error executing command. From 7e77e9e0046c87e283cf36c6ee427317fddc6cdb Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 14 Feb 2022 19:08:13 +0200 Subject: [PATCH 08/32] Fixed tests to pass on runners --- nessie/doctor_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index 16d98730735..648f4f887bc 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -14,7 +14,9 @@ func TestDoctor(t *testing.T) { endPointURL := viper.GetString("endpoint_url") + "/api/v1" emptyConfigFileName := "empty.yaml" wrongFormatFileName := "wrong_format.yaml" + defaultConfigPath := "/root/.lakectl.yaml" os.Create(emptyConfigFileName) + os.Create(defaultConfigPath) ioutil.WriteFile(wrongFormatFileName, []byte("nothing"), 0644) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_ok", emptyVars) RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c "+wrongFormatFileName, false, "lakectl_doctor_wrong_format_file", emptyVars) From 23d3eed92138bb2e27ae204dbcb5cbd5825e8fce Mon Sep 17 00:00:00 2001 From: Idan Novogroder <43949240+idanovo@users.noreply.github.com> Date: Mon, 14 Feb 2022 23:54:41 +0200 Subject: [PATCH 09/32] changed IsValidAccessKeyID to be more readable Co-authored-by: itai-david <90712874+itai-david@users.noreply.github.com> --- cmd/lakectl/cmd/common_helpers.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index e921560df9c..e6c6a595221 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -272,7 +272,11 @@ func MustParsePathURI(name, s string) *uri.URI { } func IsValidAccessKeyID(accessKeyID string) bool { - return (len(accessKeyID) == 20 && (strings.HasPrefix(accessKeyID, "ASIA") || strings.HasPrefix(accessKeyID, "AKIA")) && (string(accessKeyID[4]) == "I" || string(accessKeyID[4]) == "J") && (strings.HasSuffix(accessKeyID, "A") || strings.HasSuffix(accessKeyID, "Q")) && IsContainOnlyUpperLettersOrNumber(accessKeyID)) + return (len(accessKeyID) == 20 && + (strings.HasPrefix(accessKeyID, "ASIA") || strings.HasPrefix(accessKeyID, "AKIA")) && + (string(accessKeyID[4]) == "I" || string(accessKeyID[4]) == "J") && + (strings.HasSuffix(accessKeyID, "A") || strings.HasSuffix(accessKeyID, "Q")) && + IsContainOnlyUpperLettersOrNumber(accessKeyID)) } func IsValidSecretAccessKey(secretAcceessKey string) bool { From 8cf0aa6625db2a2927b02ec14e9b8a74f9b44512 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 01:45:48 +0200 Subject: [PATCH 10/32] Fixed PR review --- cmd/lakectl/cmd/common_helpers.go | 4 +- cmd/lakectl/cmd/doctor.go | 90 ++++++------------- nessie/doctor_test.go | 21 +---- .../golden/lakectl_doctor_empty_file.golden | 4 - ...kectl_doctor_long_secret_access_key.golden | 6 -- ...ectl_doctor_short_secret_access_key.golden | 6 -- ...ctor_with_long_length_access_key_id.golden | 6 -- ...octor_with_lower_case_access_key_id.golden | 6 -- ...tor_with_short_length_access_key_id.golden | 6 -- ...ctor_with_suspicious_access_key_id.golden} | 5 +- ..._with_suspicious_secret_access_key.golden} | 5 +- ...tor_with_wrong_prefix_access_key_id.golden | 6 -- ...octor_with_wrong_secret_access_key.golden} | 5 +- ...ctor_with_wrong_sufix_access_key_id.golden | 6 -- .../lakectl_doctor_wrong_access_key_id.golden | 5 +- .../lakectl_doctor_wrong_endpoint.golden | 4 +- .../lakectl_doctor_wrong_format_file.golden | 3 - ...tl_doctor_wrong_uri_format_endpoint.golden | 4 +- 18 files changed, 48 insertions(+), 144 deletions(-) delete mode 100644 nessie/golden/lakectl_doctor_empty_file.golden delete mode 100644 nessie/golden/lakectl_doctor_long_secret_access_key.golden delete mode 100644 nessie/golden/lakectl_doctor_short_secret_access_key.golden delete mode 100644 nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden delete mode 100644 nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden delete mode 100644 nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden rename nessie/golden/{lakectl_doctor_with_invalid_char_access_key_id.golden => lakectl_doctor_with_suspicious_access_key_id.golden} (79%) rename nessie/golden/{lakectl_doctor_invalid_char_secret_access_key.golden => lakectl_doctor_with_suspicious_secret_access_key.golden} (79%) delete mode 100644 nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden rename nessie/golden/{lakectl_doctor_wrong_secret_access_key.golden => lakectl_doctor_with_wrong_secret_access_key.golden} (75%) delete mode 100644 nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden delete mode 100644 nessie/golden/lakectl_doctor_wrong_format_file.golden diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index e6c6a595221..3d3fe5d35b0 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -279,8 +279,8 @@ func IsValidAccessKeyID(accessKeyID string) bool { IsContainOnlyUpperLettersOrNumber(accessKeyID)) } -func IsValidSecretAccessKey(secretAcceessKey string) bool { - return (IsBase64(secretAcceessKey) && len(secretAcceessKey) == 40) +func IsValidSecretAccessKey(secretAccessKey string) bool { + return (IsBase64(secretAccessKey) && len(secretAccessKey) == 40) } func IsBase64(s string) bool { diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 82042d911c8..0de09ae5a6f 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -1,16 +1,10 @@ package cmd import ( - "errors" "fmt" - "path/filepath" "strings" - "github.com/deepmap/oapi-codegen/pkg/securityprovider" - "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" - "github.com/spf13/viper" - "github.com/treeverse/lakefs/cmd/lakectl/cmd/config" "github.com/treeverse/lakefs/pkg/api" ) @@ -19,35 +13,6 @@ var doctorCmd = &cobra.Command{ Use: "doctor", Short: "Run a basic diagnosis of the LakeFS configuration", Run: func(cmd *cobra.Command, args []string) { - if viper.ConfigFileUsed() == "" { - // Find home directory. - home, err := homedir.Dir() - if err != nil { - DieErr(err) - } - // Setup default config file - viper.SetConfigFile(filepath.Join(home, ".lakectl.yaml")) - } - - viper.SetEnvPrefix("LAKECTL") - viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // support nested config - viper.AutomaticEnv() // read in environment variables that match - - cfg := config.ReadConfig() - cfgError := cfg.Err() - if cfgError != nil { - if errors.As(cfgError, &viper.ConfigFileNotFoundError{}) { - // specific message in case the file isn't found - DieFmt("Config file not found, please run \"lakectl config\" to create one\n%s\n", cfg.Err()) - } - // other errors while reading the config file - DieFmt("Error reading configuration file: %v", cfgError) - } - - if err := viper.UnmarshalExact(&cfg.Values); err != nil { - DieFmt("Error unmarshal configuration: %v", err) - } - accessKeyID := cfg.Values.Credentials.AccessKeyID if !IsValidAccessKeyID(accessKeyID) { fmt.Println("access_key_id value looks suspicious...") @@ -58,40 +23,41 @@ var doctorCmd = &cobra.Command{ fmt.Println("secret_access_key value looks suspicious...") } - basicAuthProvider, err := securityprovider.NewSecurityProviderBasicAuth(accessKeyID, secretAccessKey) - if err != nil { - DieErr(err) - } - serverEndpoint := cfg.Values.Server.EndpointURL if !IsValidEndpointURI(serverEndpoint) { - DieFmt("Wrong URI format for server.endpoint_url: %v", serverEndpoint) + fmt.Println("Suspicious URI format for server.endpoint_url:", serverEndpoint) } - client, err := api.NewClientWithResponses( - serverEndpoint, - api.WithRequestEditorFn(basicAuthProvider.Intercept), - ) - if err != nil { - DieFmt("Could not initialize API client: %v", err.Error()) - } + client := getClient() - loginReq := api.LoginJSONRequestBody{ - AccessKeyId: accessKeyID, - SecretAccessKey: secretAccessKey, - } + rsp, err := client.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{}) - login, err := client.LoginWithResponse(cmd.Context(), loginReq) - if err != nil || login.JSON200 == nil { - DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong \n\n") + if err != nil { + if strings.Contains(err.Error(), "unsupported protocol scheme") { + DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nProbably your endpoint url is wrong.") + } + fmt.Println(err.Error()) } - - rsp, _ := client.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{}) - rsp.StatusCode() - if rsp.JSON200 != nil { - fmt.Println("LakeFS doctor could not find any configuration issues") - } else { - fmt.Print("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong \n\n") + if rsp != nil { + if rsp.JSON200 != nil { + fmt.Println("LakeFS doctor could not find any configuration issues") + return + } + if rsp.JSON401 != nil { + fmt.Println(rsp.JSON401.Message) + DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong.") + } + if rsp.HTTPResponse != nil { + // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) + if rsp.HTTPResponse.StatusCode == 200 { + DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nProbably your endpoint url is wrong.") + } + if rsp.JSONDefault != nil { + fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file.") + DieFmt(rsp.JSONDefault.Message) + } + } + DieFmt("It looks like you have a problem with your '.lakectl.yaml' file.") } }, } diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index 648f4f887bc..830f1f27014 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -1,7 +1,6 @@ package nessie import ( - "io/ioutil" "os" "testing" @@ -12,27 +11,15 @@ func TestDoctor(t *testing.T) { accessKeyID := viper.GetString("access_key_id") secretAccessKey := viper.GetString("secret_access_key") endPointURL := viper.GetString("endpoint_url") + "/api/v1" - emptyConfigFileName := "empty.yaml" - wrongFormatFileName := "wrong_format.yaml" defaultConfigPath := "/root/.lakectl.yaml" - os.Create(emptyConfigFileName) os.Create(defaultConfigPath) - ioutil.WriteFile(wrongFormatFileName, []byte("nothing"), 0644) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_ok", emptyVars) - RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c "+wrongFormatFileName, false, "lakectl_doctor_wrong_format_file", emptyVars) - RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c "+emptyConfigFileName, false, "lakectl_doctor_empty_file", emptyVars) RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exited.yaml", false, "lakectl_doctor_not_existed_file", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIhCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_lower_case_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIBJOIHCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_prefix_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIHCOZ5JBYHCSDB", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_sufix_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOICO!Z5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_invalid_char_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOICOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_short_length_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOIHHCOZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_long_length_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", endPointURL)+" doctor", false, "lakectl_doctor_wrong_secret_access_key", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ", endPointURL)+" doctor", false, "lakectl_doctor_short_secret_access_key", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJzz", endPointURL)+" doctor", false, "lakectl_doctor_long_secret_access_key", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ!", endPointURL)+" doctor", false, "lakectl_doctor_invalid_char_secret_access_key", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOI!COZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_secret_access_key", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ!", endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_secret_access_key", emptyVars) + } diff --git a/nessie/golden/lakectl_doctor_empty_file.golden b/nessie/golden/lakectl_doctor_empty_file.golden deleted file mode 100644 index 6baf7f28988..00000000000 --- a/nessie/golden/lakectl_doctor_empty_file.golden +++ /dev/null @@ -1,4 +0,0 @@ -access_key_id value looks suspicious... -secret_access_key value looks suspicious... -Wrong URI format for server.endpoint_url: http://127.0.0.1:8000 -Error executing command. diff --git a/nessie/golden/lakectl_doctor_long_secret_access_key.golden b/nessie/golden/lakectl_doctor_long_secret_access_key.golden deleted file mode 100644 index b9406b8c1da..00000000000 --- a/nessie/golden/lakectl_doctor_long_secret_access_key.golden +++ /dev/null @@ -1,6 +0,0 @@ -secret_access_key value looks suspicious... -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - -Error executing command. diff --git a/nessie/golden/lakectl_doctor_short_secret_access_key.golden b/nessie/golden/lakectl_doctor_short_secret_access_key.golden deleted file mode 100644 index b9406b8c1da..00000000000 --- a/nessie/golden/lakectl_doctor_short_secret_access_key.golden +++ /dev/null @@ -1,6 +0,0 @@ -secret_access_key value looks suspicious... -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - -Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden b/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden deleted file mode 100644 index 3f2f8a2aa9f..00000000000 --- a/nessie/golden/lakectl_doctor_with_long_length_access_key_id.golden +++ /dev/null @@ -1,6 +0,0 @@ -access_key_id value looks suspicious... -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - -Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden b/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden deleted file mode 100644 index 3f2f8a2aa9f..00000000000 --- a/nessie/golden/lakectl_doctor_with_lower_case_access_key_id.golden +++ /dev/null @@ -1,6 +0,0 @@ -access_key_id value looks suspicious... -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - -Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden b/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden deleted file mode 100644 index 3f2f8a2aa9f..00000000000 --- a/nessie/golden/lakectl_doctor_with_short_length_access_key_id.golden +++ /dev/null @@ -1,6 +0,0 @@ -access_key_id value looks suspicious... -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - -Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden similarity index 79% rename from nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden rename to nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden index 3f2f8a2aa9f..ddaf9793384 100644 --- a/nessie/golden/lakectl_doctor_with_invalid_char_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden @@ -1,6 +1,5 @@ access_key_id value looks suspicious... +error authenticating request It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong. Error executing command. diff --git a/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden similarity index 79% rename from nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden rename to nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden index b9406b8c1da..2678610bc8a 100644 --- a/nessie/golden/lakectl_doctor_invalid_char_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden @@ -1,6 +1,5 @@ secret_access_key value looks suspicious... +error authenticating request It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong. Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden b/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden deleted file mode 100644 index 3f2f8a2aa9f..00000000000 --- a/nessie/golden/lakectl_doctor_with_wrong_prefix_access_key_id.golden +++ /dev/null @@ -1,6 +0,0 @@ -access_key_id value looks suspicious... -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - -Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden b/nessie/golden/lakectl_doctor_with_wrong_secret_access_key.golden similarity index 75% rename from nessie/golden/lakectl_doctor_wrong_secret_access_key.golden rename to nessie/golden/lakectl_doctor_with_wrong_secret_access_key.golden index 1d1198a6995..de0bb64f3a0 100644 --- a/nessie/golden/lakectl_doctor_wrong_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_with_wrong_secret_access_key.golden @@ -1,5 +1,4 @@ +error authenticating request It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong. Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden b/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden deleted file mode 100644 index 3f2f8a2aa9f..00000000000 --- a/nessie/golden/lakectl_doctor_with_wrong_sufix_access_key_id.golden +++ /dev/null @@ -1,6 +0,0 @@ -access_key_id value looks suspicious... -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - -Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden index 1d1198a6995..de0bb64f3a0 100644 --- a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden @@ -1,5 +1,4 @@ +error authenticating request It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong - - +It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong. Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden index 399033fe77e..a588ec9a1d5 100644 --- a/nessie/golden/lakectl_doctor_wrong_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -1,2 +1,4 @@ -Wrong URI format for server.endpoint_url: http://localhost:8000/api/v11 +Suspicious URI format for server.endpoint_url: http://localhost:8000/api/v11 +It looks like you have a problem with your '.lakectl.yaml' file. +Probably your endpoint url is wrong. Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_format_file.golden b/nessie/golden/lakectl_doctor_wrong_format_file.golden deleted file mode 100644 index 0c82d02c9c6..00000000000 --- a/nessie/golden/lakectl_doctor_wrong_format_file.golden +++ /dev/null @@ -1,3 +0,0 @@ -error reading configuration file: While parsing config: yaml: unmarshal errors: - line 1: cannot unmarshal !!str `nothing` into map[string]interface {} -Error executing command. diff --git a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden index 08f8f3b2749..1b539db4464 100644 --- a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden @@ -1,2 +1,4 @@ -Wrong URI format for server.endpoint_url: wrong_uri +Suspicious URI format for server.endpoint_url: wrong_uri +It looks like you have a problem with your '.lakectl.yaml' file. +Probably your endpoint url is wrong. Error executing command. From 77f172ba0924481a42a5232385d5944b6b36b931 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 01:53:18 +0200 Subject: [PATCH 11/32] Changed IsContainOnlyUpperLettersOrNumber func to work with regex --- cmd/lakectl/cmd/common_helpers.go | 11 ++++------- nessie/lakectl_util.go | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 3d3fe5d35b0..d2e36296863 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -10,10 +10,10 @@ import ( "net/http" "net/url" "os" + "regexp" "strings" "text/template" "time" - "unicode" "github.com/treeverse/lakefs/pkg/uri" @@ -30,6 +30,8 @@ var noColorRequested = false // ErrInvalidValueInList is an error returned when a parameter of type list contains an empty string var ErrInvalidValueInList = errors.New("empty string in list") +var uppersAndDigitsRegexp = regexp.MustCompile(`^[0-9A-Z]+$`) + const ( LakectlInteractive = "LAKECTL_INTERACTIVE" LakectlInteractiveDisable = "no" @@ -289,12 +291,7 @@ func IsBase64(s string) bool { } func IsContainOnlyUpperLettersOrNumber(s string) bool { - for _, r := range s { - if !unicode.IsNumber(r) && !unicode.IsUpper(r) { - return false - } - } - return true + return uppersAndDigitsRegexp.MatchString(s) } func IsValidURI(uri string) bool { diff --git a/nessie/lakectl_util.go b/nessie/lakectl_util.go index 3ad9fd4d2d8..5e93e420524 100644 --- a/nessie/lakectl_util.go +++ b/nessie/lakectl_util.go @@ -32,10 +32,10 @@ func Lakectl() string { return lakectlCmdline } -func LakectlWithParams(accessKeyID, secretAcceessKey, endPointURL string) string { +func LakectlWithParams(accessKeyID, secretAccessKey, endPointURL string) string { lakectlCmdline := "LAKECTL_CREDENTIALS_ACCESS_KEY_ID=" + accessKeyID + - " LAKECTL_CREDENTIALS_SECRET_ACCESS_KEY=" + secretAcceessKey + + " LAKECTL_CREDENTIALS_SECRET_ACCESS_KEY=" + secretAccessKey + " LAKECTL_SERVER_ENDPOINT_URL=" + endPointURL + " " + lakectlLocation() From 6c80ac29083ada9d390ee9a2c349d0a7315aa393 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 02:00:19 +0200 Subject: [PATCH 12/32] Fixed a test to pass on runners --- nessie/golden/lakectl_doctor_wrong_endpoint.golden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden index a588ec9a1d5..450fbd6c3b2 100644 --- a/nessie/golden/lakectl_doctor_wrong_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -1,4 +1,4 @@ -Suspicious URI format for server.endpoint_url: http://localhost:8000/api/v11 +Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11 It looks like you have a problem with your '.lakectl.yaml' file. Probably your endpoint url is wrong. Error executing command. From d19fcf1810d029c948ec94306b03181e16b0b08d Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 02:08:13 +0200 Subject: [PATCH 13/32] Changed IsValidAccessKeyID to work with regex --- cmd/lakectl/cmd/common_helpers.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index d2e36296863..bb0d997d7b3 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -30,7 +30,7 @@ var noColorRequested = false // ErrInvalidValueInList is an error returned when a parameter of type list contains an empty string var ErrInvalidValueInList = errors.New("empty string in list") -var uppersAndDigitsRegexp = regexp.MustCompile(`^[0-9A-Z]+$`) +var accessKeyRegexp = regexp.MustCompile(`^A[K|S]IA[I|J][A-Z0-9]{14}[A|Q]$`) const ( LakectlInteractive = "LAKECTL_INTERACTIVE" @@ -274,11 +274,7 @@ func MustParsePathURI(name, s string) *uri.URI { } func IsValidAccessKeyID(accessKeyID string) bool { - return (len(accessKeyID) == 20 && - (strings.HasPrefix(accessKeyID, "ASIA") || strings.HasPrefix(accessKeyID, "AKIA")) && - (string(accessKeyID[4]) == "I" || string(accessKeyID[4]) == "J") && - (strings.HasSuffix(accessKeyID, "A") || strings.HasSuffix(accessKeyID, "Q")) && - IsContainOnlyUpperLettersOrNumber(accessKeyID)) + return accessKeyRegexp.MatchString(accessKeyID) } func IsValidSecretAccessKey(secretAccessKey string) bool { @@ -290,10 +286,6 @@ func IsBase64(s string) bool { return err == nil } -func IsContainOnlyUpperLettersOrNumber(s string) bool { - return uppersAndDigitsRegexp.MatchString(s) -} - func IsValidURI(uri string) bool { _, err := url.ParseRequestURI(uri) if err != nil { From d93230a8157261beefe5e9ea8e45f2289f0e5eb8 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 09:25:35 +0200 Subject: [PATCH 14/32] Fixed tests and changed 'Lakectl' func to reuse 'LakectlWithParams' code --- cmd/lakectl/cmd/doctor.go | 2 +- nessie/doctor_test.go | 4 ++-- .../lakectl_doctor_wrong_access_key_id.golden | 4 ---- ...den => lakectl_doctor_wrong_credentials.golden} | 0 nessie/golden/lakectl_help.golden | 1 + nessie/lakectl_util.go | 14 ++++---------- 6 files changed, 8 insertions(+), 17 deletions(-) delete mode 100644 nessie/golden/lakectl_doctor_wrong_access_key_id.golden rename nessie/golden/{lakectl_doctor_with_wrong_secret_access_key.golden => lakectl_doctor_wrong_credentials.golden} (100%) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 0de09ae5a6f..0d4eaedabd5 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -45,7 +45,7 @@ var doctorCmd = &cobra.Command{ } if rsp.JSON401 != nil { fmt.Println(rsp.JSON401.Message) - DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the access_key_id' or 'secret_access_key' you supplied are wrong.") + DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong.") } if rsp.HTTPResponse != nil { // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index 830f1f27014..c0d009aae26 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -17,9 +17,9 @@ func TestDoctor(t *testing.T) { RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exited.yaml", false, "lakectl_doctor_not_existed_file", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_access_key_id", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_credentials", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOI!COZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_secret_access_key", emptyVars) + RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_credentials", emptyVars) RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ!", endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_secret_access_key", emptyVars) } diff --git a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden b/nessie/golden/lakectl_doctor_wrong_access_key_id.golden deleted file mode 100644 index de0bb64f3a0..00000000000 --- a/nessie/golden/lakectl_doctor_wrong_access_key_id.golden +++ /dev/null @@ -1,4 +0,0 @@ -error authenticating request -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong. -Error executing command. diff --git a/nessie/golden/lakectl_doctor_with_wrong_secret_access_key.golden b/nessie/golden/lakectl_doctor_wrong_credentials.golden similarity index 100% rename from nessie/golden/lakectl_doctor_with_wrong_secret_access_key.golden rename to nessie/golden/lakectl_doctor_wrong_credentials.golden diff --git a/nessie/golden/lakectl_help.golden b/nessie/golden/lakectl_help.golden index 1221e5d3439..c671531491d 100644 --- a/nessie/golden/lakectl_help.golden +++ b/nessie/golden/lakectl_help.golden @@ -16,6 +16,7 @@ Available Commands: config Create/update local lakeFS configuration dbt Integration with dbt commands diff Show changes between two commits, or the currently uncommitted changes + doctor Run a basic diagnosis of the LakeFS configuration fs View and manipulate objects gc Manage garbage collection configuration help Help about any command diff --git a/nessie/lakectl_util.go b/nessie/lakectl_util.go index 5e93e420524..8cbc56cedc6 100644 --- a/nessie/lakectl_util.go +++ b/nessie/lakectl_util.go @@ -22,16 +22,6 @@ func lakectlLocation() string { return viper.GetString("lakectl_dir") + "/lakectl" } -func Lakectl() string { - lakectlCmdline := - "LAKECTL_CREDENTIALS_ACCESS_KEY_ID=" + viper.GetString("access_key_id") + - " LAKECTL_CREDENTIALS_SECRET_ACCESS_KEY=" + viper.GetString("secret_access_key") + - " LAKECTL_SERVER_ENDPOINT_URL=" + viper.GetString("endpoint_url") + - " " + lakectlLocation() - - return lakectlCmdline -} - func LakectlWithParams(accessKeyID, secretAccessKey, endPointURL string) string { lakectlCmdline := "LAKECTL_CREDENTIALS_ACCESS_KEY_ID=" + accessKeyID + @@ -42,6 +32,10 @@ func LakectlWithParams(accessKeyID, secretAccessKey, endPointURL string) string return lakectlCmdline } +func Lakectl() string { + return LakectlWithParams(viper.GetString("access_key_id"), viper.GetString("secret_access_key") , viper.GetString("endpoint_url")) +} + func runShellCommand(command string, isTerminal bool) ([]byte, error) { fmt.Println("Testing '", command, "'") var cmd *exec.Cmd From 6cc1ce6c27735618b0b8cce1935fe535c9b4a20b Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 10:13:27 +0200 Subject: [PATCH 15/32] Checking config file only if the basic command did not work --- cmd/lakectl/cmd/doctor.go | 67 ++++++++++--------- nessie/doctor_test.go | 12 ++-- ...octor_with_suspicious_access_key_id.golden | 5 +- ...r_with_suspicious_secret_access_key.golden | 5 +- ...kectl_doctor_with_wrong_credentials.golden | 3 + .../lakectl_doctor_wrong_credentials.golden | 3 +- .../lakectl_doctor_wrong_endpoint.golden | 3 +- ...tl_doctor_wrong_uri_format_endpoint.golden | 3 +- 8 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 nessie/golden/lakectl_doctor_with_wrong_credentials.golden diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 0d4eaedabd5..59a6a5c37c1 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -13,6 +13,41 @@ var doctorCmd = &cobra.Command{ Use: "doctor", Short: "Run a basic diagnosis of the LakeFS configuration", Run: func(cmd *cobra.Command, args []string) { + client := getClient() + rsp, err := client.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{}) + + if err != nil { + if strings.Contains(err.Error(), "unsupported protocol scheme") { + fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file. \nProbably your endpoint url is wrong.") + } else { + fmt.Println(err.Error()) + } + } else { + if rsp != nil { + if rsp.JSON200 != nil { + fmt.Println("LakeFS doctor could not find any configuration issues") + return + } + if rsp.JSON401 != nil { + fmt.Println(rsp.JSON401.Message) + fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong.") + } else { + // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) + if rsp.HTTPResponse != nil && rsp.HTTPResponse.StatusCode == 200 { + fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file. \nProbably your endpoint url is wrong.") + } else { + if rsp.JSONDefault != nil { + fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file.") + fmt.Println(rsp.JSONDefault.Message) + } else { + fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file.") + } + } + } + } + + } + accessKeyID := cfg.Values.Credentials.AccessKeyID if !IsValidAccessKeyID(accessKeyID) { fmt.Println("access_key_id value looks suspicious...") @@ -27,38 +62,6 @@ var doctorCmd = &cobra.Command{ if !IsValidEndpointURI(serverEndpoint) { fmt.Println("Suspicious URI format for server.endpoint_url:", serverEndpoint) } - - client := getClient() - - rsp, err := client.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{}) - - if err != nil { - if strings.Contains(err.Error(), "unsupported protocol scheme") { - DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nProbably your endpoint url is wrong.") - } - fmt.Println(err.Error()) - } - if rsp != nil { - if rsp.JSON200 != nil { - fmt.Println("LakeFS doctor could not find any configuration issues") - return - } - if rsp.JSON401 != nil { - fmt.Println(rsp.JSON401.Message) - DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong.") - } - if rsp.HTTPResponse != nil { - // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) - if rsp.HTTPResponse.StatusCode == 200 { - DieFmt("It looks like you have a problem with your '.lakectl.yaml' file. \nProbably your endpoint url is wrong.") - } - if rsp.JSONDefault != nil { - fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file.") - DieFmt(rsp.JSONDefault.Message) - } - } - DieFmt("It looks like you have a problem with your '.lakectl.yaml' file.") - } }, } diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index c0d009aae26..0a39fb74d5e 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -15,11 +15,11 @@ func TestDoctor(t *testing.T) { os.Create(defaultConfigPath) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_ok", emptyVars) RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exited.yaml", false, "lakectl_doctor_not_existed_file", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_credentials", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams("AKIAJOI!COZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_access_key_id", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_credentials", emptyVars) - RunCmdAndVerifyFailureWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ!", endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_secret_access_key", emptyVars) + RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) + RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) + RunCmdAndVerifySuccessWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_credentials", emptyVars) + RunCmdAndVerifySuccessWithFile(t, LakectlWithParams("AKIAJOI!COZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_access_key_id", emptyVars) + RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_credentials", emptyVars) + RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ!", endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_secret_access_key", emptyVars) } diff --git a/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden index ddaf9793384..bf7220ec621 100644 --- a/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden @@ -1,5 +1,4 @@ -access_key_id value looks suspicious... error authenticating request It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong. -Error executing command. +It is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong. +access_key_id value looks suspicious... diff --git a/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden index 2678610bc8a..77e21c46d27 100644 --- a/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden @@ -1,5 +1,4 @@ -secret_access_key value looks suspicious... error authenticating request It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong. -Error executing command. +It is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong. +secret_access_key value looks suspicious... diff --git a/nessie/golden/lakectl_doctor_with_wrong_credentials.golden b/nessie/golden/lakectl_doctor_with_wrong_credentials.golden new file mode 100644 index 00000000000..f3890917a35 --- /dev/null +++ b/nessie/golden/lakectl_doctor_with_wrong_credentials.golden @@ -0,0 +1,3 @@ +error authenticating request +It looks like you have a problem with your '.lakectl.yaml' file. +It is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong. diff --git a/nessie/golden/lakectl_doctor_wrong_credentials.golden b/nessie/golden/lakectl_doctor_wrong_credentials.golden index de0bb64f3a0..f3890917a35 100644 --- a/nessie/golden/lakectl_doctor_wrong_credentials.golden +++ b/nessie/golden/lakectl_doctor_wrong_credentials.golden @@ -1,4 +1,3 @@ error authenticating request It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the access_key_id' or 'secret_access_key' you supplied are wrong. -Error executing command. +It is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong. diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden index 450fbd6c3b2..b1304675b83 100644 --- a/nessie/golden/lakectl_doctor_wrong_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -1,4 +1,3 @@ -Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11 It looks like you have a problem with your '.lakectl.yaml' file. Probably your endpoint url is wrong. -Error executing command. +Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11 diff --git a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden index 1b539db4464..b8946917c8f 100644 --- a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden @@ -1,4 +1,3 @@ -Suspicious URI format for server.endpoint_url: wrong_uri It looks like you have a problem with your '.lakectl.yaml' file. Probably your endpoint url is wrong. -Error executing command. +Suspicious URI format for server.endpoint_url: wrong_uri From de505a95457f6f3fe5c525abb589f19f0121d02d Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 12:32:18 +0200 Subject: [PATCH 16/32] Added unittests and changed IsValidAccessKeyID func to be more specific about acceptble conventions --- cmd/lakectl/cmd/common_helpers.go | 2 +- cmd/lakectl/cmd/common_helpers_test.go | 116 +++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 cmd/lakectl/cmd/common_helpers_test.go diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index bb0d997d7b3..f3ca1ad2c3f 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -30,7 +30,7 @@ var noColorRequested = false // ErrInvalidValueInList is an error returned when a parameter of type list contains an empty string var ErrInvalidValueInList = errors.New("empty string in list") -var accessKeyRegexp = regexp.MustCompile(`^A[K|S]IA[I|J][A-Z0-9]{14}[A|Q]$`) +var accessKeyRegexp = regexp.MustCompile(`^AKIA[I|J][A-Z0-9]{14}Q$`) const ( LakectlInteractive = "LAKECTL_INTERACTIVE" diff --git a/cmd/lakectl/cmd/common_helpers_test.go b/cmd/lakectl/cmd/common_helpers_test.go new file mode 100644 index 00000000000..aa419eb9406 --- /dev/null +++ b/cmd/lakectl/cmd/common_helpers_test.go @@ -0,0 +1,116 @@ +package cmd + +import "testing" + +func TestIsValidAccessKeyID(t *testing.T) { + type args struct { + accessKeyID string + } + tests := []struct { + name string + args args + want bool + }{ + {name: "valid access key id", args: args{accessKeyID: "AKIAJ12ZZZZZZZZZZZZQ"}, want: true}, + {name: "access key id with lower case char", args: args{accessKeyID: "AKIAJ12zZZZZZZZZZZZQ"}, want: false}, + {name: "access key id with invalid char", args: args{accessKeyID: "AKIAJ12!ZZZZZZZZZZZQ"}, want: false}, + {name: "access key id with extra char", args: args{accessKeyID: "AKIAJ123ZZZZZZZZZZZZQ"}, want: false}, + {name: "access key id with missing char", args: args{accessKeyID: "AKIAJ1ZZZZZZZZZZZZQ"}, want: false}, + {name: "access key id with wrong prefix", args: args{accessKeyID: "AKIAM12ZZZZZZZZZZZZQ"}, want: false}, + {name: "access key id with wrong suffiix", args: args{accessKeyID: "AKIAJ12ZZZZZZZZZZZZA"}, want: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsValidAccessKeyID(tt.args.accessKeyID); got != tt.want { + t.Errorf("IsValidAccessKeyID() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestIsValidSecretAccessKey(t *testing.T) { + type args struct { + secretAccessKey string + } + tests := []struct { + name string + args args + want bool + }{ + {name: "valid secret access key", args: args{secretAccessKey: "TQG5JcovOozCGJnIRmIKH7Flq1tLxrUbyi9/WmJy"}, want: true}, + {name: "secret access key id with invalid char", args: args{secretAccessKey: "!QG5JcovOozCGJnIRmIKH7Flq1tLxrUbyi9/WmJy"}, want: false}, + {name: "secret access key id with extra char", args: args{secretAccessKey: "aTQG5JcovOozCGJnIRmIKH7Flq1tLxrUbyi9/WmJy"}, want: false}, + {name: "secret access key id with missing char", args: args{secretAccessKey: "QG5JcovOozCGJnIRmIKH7Flq1tLxrUbyi9/WmJy"}, want: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsValidSecretAccessKey(tt.args.secretAccessKey); got != tt.want { + t.Errorf("IsValidSecretAccessKey() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestIsBase64(t *testing.T) { + type args struct { + s string + } + tests := []struct { + name string + args args + want bool + }{ + {name: "valid base64", args: args{s: "TQG5JcovOozCGJnIRmIKH7Flq1tLxrUbyi9/WmJy"}, want: true}, + {name: "invalid base64", args: args{s: "!QG5JcovOozCGJnIRmIKH7Flq1tLxrUbyi9/WmJy"}, want: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsBase64(tt.args.s); got != tt.want { + t.Errorf("IsBase64() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestIsValidURI(t *testing.T) { + type args struct { + uri string + } + tests := []struct { + name string + args args + want bool + }{ + {name: "valid uri", args: args{uri: "lakefs://main.com/side"}, want: true}, + {name: "invalid uri", args: args{uri: "not_uri"}, want: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsValidURI(tt.args.uri); got != tt.want { + t.Errorf("IsValidURI() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestIsValidEndpointURI(t *testing.T) { + type args struct { + uri string + } + tests := []struct { + name string + args args + want bool + }{ + {name: "valid api uri", args: args{uri: "lakefs://main.com/side/api/v1"}, want: true}, + {name: "invalid api uri", args: args{uri: "lakefs://main.com/side/api/v11"}, want: false}, + {name: "invalid uri", args: args{uri: "not_uri"}, want: false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := IsValidEndpointURI(tt.args.uri); got != tt.want { + t.Errorf("IsValidEndpointURI() = %v, want %v", got, tt.want) + } + }) + } +} From d371c8a4a6678f5adab31645f347aa5ea098d795 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 13:22:14 +0200 Subject: [PATCH 17/32] Fixed linter errors --- nessie/lakectl_util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nessie/lakectl_util.go b/nessie/lakectl_util.go index 8cbc56cedc6..b2a58d28181 100644 --- a/nessie/lakectl_util.go +++ b/nessie/lakectl_util.go @@ -33,7 +33,7 @@ func LakectlWithParams(accessKeyID, secretAccessKey, endPointURL string) string } func Lakectl() string { - return LakectlWithParams(viper.GetString("access_key_id"), viper.GetString("secret_access_key") , viper.GetString("endpoint_url")) + return LakectlWithParams(viper.GetString("access_key_id"), viper.GetString("secret_access_key"), viper.GetString("endpoint_url")) } func runShellCommand(command string, isTerminal bool) ([]byte, error) { From e78fbb01ddc21ef9691d49405ff49d5cb4257910 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 14:41:14 +0200 Subject: [PATCH 18/32] Advising the user to use command on failure --- cmd/lakectl/cmd/common_helpers.go | 4 ++++ cmd/lakectl/cmd/doctor.go | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index f3ca1ad2c3f..4ec057c78fe 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -27,6 +27,8 @@ import ( var isTerminal = true var noColorRequested = false +var tryDoctorText = "You can try to run the 'kubectl doctor' command in order to find if there is a configuration issue in your environment." + // ErrInvalidValueInList is an error returned when a parameter of type list contains an empty string var ErrInvalidValueInList = errors.New("empty string in list") @@ -159,6 +161,7 @@ func Write(tpl string, data interface{}) { func Die(err string, code int) { WriteTo(DeathMessage, struct{ Error string }{err}, os.Stderr) + fmt.Println(tryDoctorText) os.Exit(code) } @@ -187,6 +190,7 @@ func DieErr(err error) { default: WriteTo(DeathMessage, ErrData{Error: err.Error()}, os.Stderr) } + fmt.Println(tryDoctorText) os.Exit(1) } diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 59a6a5c37c1..fefc26af87f 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -29,8 +29,8 @@ var doctorCmd = &cobra.Command{ return } if rsp.JSON401 != nil { - fmt.Println(rsp.JSON401.Message) fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong.") + fmt.Println(rsp.JSON401.Message) } else { // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) if rsp.HTTPResponse != nil && rsp.HTTPResponse.StatusCode == 200 { @@ -44,6 +44,8 @@ var doctorCmd = &cobra.Command{ } } } + } else { + fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file.") } } From c6b4a90973f08d3482022df0b253a9663a9e8201 Mon Sep 17 00:00:00 2001 From: Idan Novogroder <43949240+idanovo@users.noreply.github.com> Date: Tue, 15 Feb 2022 14:43:00 +0200 Subject: [PATCH 19/32] Apply style suggestions from code review Co-authored-by: arielshaqed --- cmd/lakectl/cmd/common_helpers.go | 2 +- cmd/lakectl/cmd/common_helpers_test.go | 2 +- docs/reference/commands.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 4ec057c78fe..963f8894ac6 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -282,7 +282,7 @@ func IsValidAccessKeyID(accessKeyID string) bool { } func IsValidSecretAccessKey(secretAccessKey string) bool { - return (IsBase64(secretAccessKey) && len(secretAccessKey) == 40) + return IsBase64(secretAccessKey) && len(secretAccessKey) == 40 } func IsBase64(s string) bool { diff --git a/cmd/lakectl/cmd/common_helpers_test.go b/cmd/lakectl/cmd/common_helpers_test.go index aa419eb9406..f913100ac2b 100644 --- a/cmd/lakectl/cmd/common_helpers_test.go +++ b/cmd/lakectl/cmd/common_helpers_test.go @@ -81,7 +81,7 @@ func TestIsValidURI(t *testing.T) { args args want bool }{ - {name: "valid uri", args: args{uri: "lakefs://main.com/side"}, want: true}, + {name: "valid uri", args: args{uri: "https://main.com/side"}, want: true}, {name: "invalid uri", args: args{uri: "not_uri"}, want: false}, } for _, tt := range tests { diff --git a/docs/reference/commands.md b/docs/reference/commands.md index ff7bc15aa70..3026f6864eb 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -1737,7 +1737,7 @@ lakectl docs [outfile] [flags] ### lakectl doctor -Run a basic diagnosis of the LakeFS configuration +Run a basic diagnosis of lakectl configuration ``` lakectl doctor [flags] From f6cc60ca1e2b46bac6eaf3d12b541925fd2561da Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Tue, 15 Feb 2022 23:47:00 +0200 Subject: [PATCH 20/32] Added a funnc that returnn what was the error we got while analyzing the list repo command, and add a recommendation to use the doctor command when command is dying --- cmd/lakectl/cmd/common_helpers.go | 11 +- cmd/lakectl/cmd/common_helpers_test.go | 45 +------ cmd/lakectl/cmd/doctor.go | 110 ++++++++++++------ docs/reference/commands.md | 2 +- nessie/doctor_test.go | 2 +- .../lakectl_doctor_not_existed_file.golden | 3 +- ...octor_with_suspicious_access_key_id.golden | 5 +- ...r_with_suspicious_secret_access_key.golden | 3 +- ...kectl_doctor_with_wrong_credentials.golden | 3 +- .../lakectl_doctor_wrong_credentials.golden | 3 +- .../lakectl_doctor_wrong_endpoint.golden | 4 +- ...tl_doctor_wrong_uri_format_endpoint.golden | 2 +- 12 files changed, 87 insertions(+), 106 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index 963f8894ac6..e89c438d193 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -292,16 +292,7 @@ func IsBase64(s string) bool { func IsValidURI(uri string) bool { _, err := url.ParseRequestURI(uri) - if err != nil { - return false - } - - u, err := url.Parse(uri) - if err != nil || u.Scheme == "" || u.Host == "" { - return false - } - - return true + return err == nil } func IsValidEndpointURI(uri string) bool { diff --git a/cmd/lakectl/cmd/common_helpers_test.go b/cmd/lakectl/cmd/common_helpers_test.go index f913100ac2b..69c341f50f7 100644 --- a/cmd/lakectl/cmd/common_helpers_test.go +++ b/cmd/lakectl/cmd/common_helpers_test.go @@ -51,47 +51,6 @@ func TestIsValidSecretAccessKey(t *testing.T) { } } -func TestIsBase64(t *testing.T) { - type args struct { - s string - } - tests := []struct { - name string - args args - want bool - }{ - {name: "valid base64", args: args{s: "TQG5JcovOozCGJnIRmIKH7Flq1tLxrUbyi9/WmJy"}, want: true}, - {name: "invalid base64", args: args{s: "!QG5JcovOozCGJnIRmIKH7Flq1tLxrUbyi9/WmJy"}, want: false}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := IsBase64(tt.args.s); got != tt.want { - t.Errorf("IsBase64() = %v, want %v", got, tt.want) - } - }) - } -} - -func TestIsValidURI(t *testing.T) { - type args struct { - uri string - } - tests := []struct { - name string - args args - want bool - }{ - {name: "valid uri", args: args{uri: "https://main.com/side"}, want: true}, - {name: "invalid uri", args: args{uri: "not_uri"}, want: false}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := IsValidURI(tt.args.uri); got != tt.want { - t.Errorf("IsValidURI() = %v, want %v", got, tt.want) - } - }) - } -} func TestIsValidEndpointURI(t *testing.T) { type args struct { @@ -102,8 +61,8 @@ func TestIsValidEndpointURI(t *testing.T) { args args want bool }{ - {name: "valid api uri", args: args{uri: "lakefs://main.com/side/api/v1"}, want: true}, - {name: "invalid api uri", args: args{uri: "lakefs://main.com/side/api/v11"}, want: false}, + {name: "valid api uri", args: args{uri: "http://main.com/side/api/v1"}, want: true}, + {name: "invalid api uri", args: args{uri: "http://main.com/side/api/v11"}, want: false}, {name: "invalid uri", args: args{uri: "not_uri"}, want: false}, } for _, tt := range tests { diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index fefc26af87f..188146ec923 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -1,10 +1,13 @@ package cmd import ( + "context" + "errors" "fmt" - "strings" + "net/url" "github.com/spf13/cobra" + "github.com/spf13/viper" "github.com/treeverse/lakefs/pkg/api" ) @@ -13,46 +16,26 @@ var doctorCmd = &cobra.Command{ Use: "doctor", Short: "Run a basic diagnosis of the LakeFS configuration", Run: func(cmd *cobra.Command, args []string) { - client := getClient() - rsp, err := client.ListRepositoriesWithResponse(cmd.Context(), &api.ListRepositoriesParams{}) - - if err != nil { - if strings.Contains(err.Error(), "unsupported protocol scheme") { - fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file. \nProbably your endpoint url is wrong.") - } else { - fmt.Println(err.Error()) - } - } else { - if rsp != nil { - if rsp.JSON200 != nil { - fmt.Println("LakeFS doctor could not find any configuration issues") - return - } - if rsp.JSON401 != nil { - fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file. \nIt is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong.") - fmt.Println(rsp.JSON401.Message) - } else { - // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) - if rsp.HTTPResponse != nil && rsp.HTTPResponse.StatusCode == 200 { - fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file. \nProbably your endpoint url is wrong.") - } else { - if rsp.JSONDefault != nil { - fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file.") - fmt.Println(rsp.JSONDefault.Message) - } else { - fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file.") - } - } - } - } else { - fmt.Println("It looks like you have a problem with your '.lakectl.yaml' file.") - } - + err := ListRepositoriesAndAnalyze(cmd.Context()) + if err == nil { + fmt.Println("LakeFS doctor could not find any configuration issues") + return + } + configFileName := viper.GetViper().ConfigFileUsed() + fmt.Println("It looks like you have a problem with your `" + configFileName + "` file.") + switch err.(type) { + case *CredentialError: + fmt.Println("It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong.") + case *WrongURIError: + fmt.Println("Probably your endpoint url is wrong.") + } + errMsg := err.Error() + if errMsg != "" { + fmt.Println(errMsg) } - accessKeyID := cfg.Values.Credentials.AccessKeyID if !IsValidAccessKeyID(accessKeyID) { - fmt.Println("access_key_id value looks suspicious...") + fmt.Println("access_key_id value looks suspicious: accessKeyID") } secretAccessKey := cfg.Values.Credentials.SecretAccessKey @@ -67,6 +50,57 @@ var doctorCmd = &cobra.Command{ }, } +func ListRepositoriesAndAnalyze(ctx context.Context) error { + client := getClient() + resp, err := client.ListRepositoriesWithResponse(ctx, &api.ListRepositoriesParams{}) + + if err != nil { + urlErr := new(url.Error) + if errors.As(err, &urlErr) { + return new(WrongURIError) + } else { + return errors.New(err.Error()) + } + } else { + if resp != nil { + if resp.JSON200 != nil { + return nil + } + if resp.JSON401 != nil { + return CredentialError{resp.JSON401.Message} + } else { + // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) + if resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200 { + return new(WrongURIError) + } else { + if resp.JSONDefault != nil { + return errors.New(resp.JSONDefault.Message) + } else { + return errors.New("") + } + } + } + } + } + return errors.New("") +} + +type CredentialError struct { + Message string +} + +func (e CredentialError) Error() string { + return e.Message +} + +type WrongURIError struct { + Message string +} + +func (e WrongURIError) Error() string { + return e.Message +} + //nolint:gochecknoinits func init() { rootCmd.AddCommand(doctorCmd) diff --git a/docs/reference/commands.md b/docs/reference/commands.md index 3026f6864eb..ff7bc15aa70 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -1737,7 +1737,7 @@ lakectl docs [outfile] [flags] ### lakectl doctor -Run a basic diagnosis of lakectl configuration +Run a basic diagnosis of the LakeFS configuration ``` lakectl doctor [flags] diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index 0a39fb74d5e..46a20fcf17c 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -14,7 +14,7 @@ func TestDoctor(t *testing.T) { defaultConfigPath := "/root/.lakectl.yaml" os.Create(defaultConfigPath) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_ok", emptyVars) - RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exited.yaml", false, "lakectl_doctor_not_existed_file", emptyVars) + RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exits.yaml", false, "lakectl_doctor_not_existed_file", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_credentials", emptyVars) diff --git a/nessie/golden/lakectl_doctor_not_existed_file.golden b/nessie/golden/lakectl_doctor_not_existed_file.golden index 325f01b1c03..b8ef023ffe4 100644 --- a/nessie/golden/lakectl_doctor_not_existed_file.golden +++ b/nessie/golden/lakectl_doctor_not_existed_file.golden @@ -1,2 +1,3 @@ -error reading configuration file: open not_exited.yaml: no such file or directory +error reading configuration file: open not_exits.yaml: no such file or directory Error executing command. +You can try to run the 'kubectl doctor' command in order to find if there is a configuration issue in your environment. diff --git a/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden index bf7220ec621..f59ce9c38ce 100644 --- a/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden @@ -1,4 +1,3 @@ +It looks like you have a problem with your `/root/.lakectl.yaml` file. error authenticating request -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong. -access_key_id value looks suspicious... +access_key_id value looks suspicious: accessKeyID diff --git a/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden index 77e21c46d27..b86d71897a5 100644 --- a/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden @@ -1,4 +1,3 @@ +It looks like you have a problem with your `/root/.lakectl.yaml` file. error authenticating request -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong. secret_access_key value looks suspicious... diff --git a/nessie/golden/lakectl_doctor_with_wrong_credentials.golden b/nessie/golden/lakectl_doctor_with_wrong_credentials.golden index f3890917a35..e80ec10e833 100644 --- a/nessie/golden/lakectl_doctor_with_wrong_credentials.golden +++ b/nessie/golden/lakectl_doctor_with_wrong_credentials.golden @@ -1,3 +1,2 @@ +It looks like you have a problem with your `/root/.lakectl.yaml` file. error authenticating request -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong. diff --git a/nessie/golden/lakectl_doctor_wrong_credentials.golden b/nessie/golden/lakectl_doctor_wrong_credentials.golden index f3890917a35..e80ec10e833 100644 --- a/nessie/golden/lakectl_doctor_wrong_credentials.golden +++ b/nessie/golden/lakectl_doctor_wrong_credentials.golden @@ -1,3 +1,2 @@ +It looks like you have a problem with your `/root/.lakectl.yaml` file. error authenticating request -It looks like you have a problem with your '.lakectl.yaml' file. -It is possible that the 'access_key_id' or 'secret_access_key' you supplied are wrong. diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden index b1304675b83..36c751b088e 100644 --- a/nessie/golden/lakectl_doctor_wrong_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -1,3 +1,3 @@ -It looks like you have a problem with your '.lakectl.yaml' file. +It looks like you have a problem with your `/root/.lakectl.yaml` file. Probably your endpoint url is wrong. -Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11 +Suspicious URI format for server.endpoint_url: http:/lakefs:8000/api/v11 diff --git a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden index b8946917c8f..3a274e7cd3d 100644 --- a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden @@ -1,3 +1,3 @@ -It looks like you have a problem with your '.lakectl.yaml' file. +It looks like you have a problem with your `/root/.lakectl.yaml` file. Probably your endpoint url is wrong. Suspicious URI format for server.endpoint_url: wrong_uri From 8575f73d64ad06e1f3c58854727d81c8262ee9d3 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Wed, 16 Feb 2022 15:26:16 +0200 Subject: [PATCH 21/32] Changed text for the default config error --- cmd/lakectl/cmd/common_helpers.go | 14 --- cmd/lakectl/cmd/common_helpers_test.go | 23 ----- cmd/lakectl/cmd/doctor.go | 99 ++++++++----------- .../lakectl_doctor_not_existed_file.golden | 1 - ...octor_with_suspicious_access_key_id.golden | 6 +- ...r_with_suspicious_secret_access_key.golden | 4 +- ...kectl_doctor_with_wrong_credentials.golden | 4 +- .../lakectl_doctor_wrong_credentials.golden | 4 +- .../lakectl_doctor_wrong_endpoint.golden | 2 +- ...tl_doctor_wrong_uri_format_endpoint.golden | 3 +- 10 files changed, 55 insertions(+), 105 deletions(-) diff --git a/cmd/lakectl/cmd/common_helpers.go b/cmd/lakectl/cmd/common_helpers.go index e89c438d193..f9a7675a78c 100644 --- a/cmd/lakectl/cmd/common_helpers.go +++ b/cmd/lakectl/cmd/common_helpers.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "net/http" - "net/url" "os" "regexp" "strings" @@ -27,8 +26,6 @@ import ( var isTerminal = true var noColorRequested = false -var tryDoctorText = "You can try to run the 'kubectl doctor' command in order to find if there is a configuration issue in your environment." - // ErrInvalidValueInList is an error returned when a parameter of type list contains an empty string var ErrInvalidValueInList = errors.New("empty string in list") @@ -161,7 +158,6 @@ func Write(tpl string, data interface{}) { func Die(err string, code int) { WriteTo(DeathMessage, struct{ Error string }{err}, os.Stderr) - fmt.Println(tryDoctorText) os.Exit(code) } @@ -190,7 +186,6 @@ func DieErr(err error) { default: WriteTo(DeathMessage, ErrData{Error: err.Error()}, os.Stderr) } - fmt.Println(tryDoctorText) os.Exit(1) } @@ -289,12 +284,3 @@ func IsBase64(s string) bool { _, err := base64.StdEncoding.DecodeString(s) return err == nil } - -func IsValidURI(uri string) bool { - _, err := url.ParseRequestURI(uri) - return err == nil -} - -func IsValidEndpointURI(uri string) bool { - return (IsValidURI(uri) && strings.HasSuffix(uri, api.BaseURL)) -} diff --git a/cmd/lakectl/cmd/common_helpers_test.go b/cmd/lakectl/cmd/common_helpers_test.go index 69c341f50f7..88fcc155741 100644 --- a/cmd/lakectl/cmd/common_helpers_test.go +++ b/cmd/lakectl/cmd/common_helpers_test.go @@ -50,26 +50,3 @@ func TestIsValidSecretAccessKey(t *testing.T) { }) } } - - -func TestIsValidEndpointURI(t *testing.T) { - type args struct { - uri string - } - tests := []struct { - name string - args args - want bool - }{ - {name: "valid api uri", args: args{uri: "http://main.com/side/api/v1"}, want: true}, - {name: "invalid api uri", args: args{uri: "http://main.com/side/api/v11"}, want: false}, - {name: "invalid uri", args: args{uri: "not_uri"}, want: false}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := IsValidEndpointURI(tt.args.uri); got != tt.want { - t.Errorf("IsValidEndpointURI() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 188146ec923..f44b44a1961 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -3,14 +3,20 @@ package cmd import ( "context" "errors" - "fmt" "net/url" + "strings" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/treeverse/lakefs/pkg/api" ) +var ( + ErrCredential = errors.New("credential error") + ErrWrongEndpointURI = errors.New("wrong endpoint_uri error") + ErrUnknownConfig = errors.New("unknown configuratioin error") +) + // doctorCmd represents the doctor command var doctorCmd = &cobra.Command{ Use: "doctor", @@ -18,87 +24,68 @@ var doctorCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { err := ListRepositoriesAndAnalyze(cmd.Context()) if err == nil { - fmt.Println("LakeFS doctor could not find any configuration issues") - return + Fmt("LakeFS doctor could not find any configuration issues\n") } configFileName := viper.GetViper().ConfigFileUsed() - fmt.Println("It looks like you have a problem with your `" + configFileName + "` file.") - switch err.(type) { - case *CredentialError: - fmt.Println("It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong.") - case *WrongURIError: - fmt.Println("Probably your endpoint url is wrong.") - } - errMsg := err.Error() - if errMsg != "" { - fmt.Println(errMsg) + Fmt("It looks like you have a problem with your `%v` file.\n", configFileName) + switch { + case errors.Is(err, ErrCredential): + Fmt("It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong.\n") + case errors.Is(err, ErrWrongEndpointURI): + Fmt("Probably your endpoint url is wrong.\n") } accessKeyID := cfg.Values.Credentials.AccessKeyID if !IsValidAccessKeyID(accessKeyID) { - fmt.Println("access_key_id value looks suspicious: accessKeyID") + Fmt("access_key_id value looks suspicious: %v\n", accessKeyID) } secretAccessKey := cfg.Values.Credentials.SecretAccessKey if !IsValidSecretAccessKey(secretAccessKey) { - fmt.Println("secret_access_key value looks suspicious...") + Fmt("secret_access_key value looks suspicious...") } serverEndpoint := cfg.Values.Server.EndpointURL - if !IsValidEndpointURI(serverEndpoint) { - fmt.Println("Suspicious URI format for server.endpoint_url:", serverEndpoint) + if !strings.HasSuffix(serverEndpoint, api.BaseURL) { + Fmt("Suspicious URI format for server.endpoint_url: %v, doesn't have `%v` suffix.\n", serverEndpoint, api.BaseURL) } }, } func ListRepositoriesAndAnalyze(ctx context.Context) error { + serverEndpoint := cfg.Values.Server.EndpointURL + _, err := url.Parse(serverEndpoint) + if err != nil { + Fmt("%v\n", err.Error()) + return ErrWrongEndpointURI + } client := getClient() resp, err := client.ListRepositoriesWithResponse(ctx, &api.ListRepositoriesParams{}) if err != nil { urlErr := new(url.Error) if errors.As(err, &urlErr) { - return new(WrongURIError) - } else { - return errors.New(err.Error()) + Fmt("%v\n", err.Error()) + return ErrWrongEndpointURI + } + return err + } + if resp != nil { + if resp.JSON200 != nil { + return nil + } + if resp.JSON401 != nil { + Fmt(resp.JSON401.Message) + return ErrCredential + } + // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) + if resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200 { + return ErrWrongEndpointURI } - } else { - if resp != nil { - if resp.JSON200 != nil { - return nil - } - if resp.JSON401 != nil { - return CredentialError{resp.JSON401.Message} - } else { - // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) - if resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200 { - return new(WrongURIError) - } else { - if resp.JSONDefault != nil { - return errors.New(resp.JSONDefault.Message) - } else { - return errors.New("") - } - } - } + if resp.JSONDefault != nil { + Fmt(resp.JSONDefault.Message) } } - return errors.New("") -} - -type CredentialError struct { - Message string -} - -func (e CredentialError) Error() string { - return e.Message -} - -type WrongURIError struct { - Message string -} - -func (e WrongURIError) Error() string { - return e.Message + return ErrUnknownConfig } //nolint:gochecknoinits diff --git a/nessie/golden/lakectl_doctor_not_existed_file.golden b/nessie/golden/lakectl_doctor_not_existed_file.golden index b8ef023ffe4..a164e3f11ad 100644 --- a/nessie/golden/lakectl_doctor_not_existed_file.golden +++ b/nessie/golden/lakectl_doctor_not_existed_file.golden @@ -1,3 +1,2 @@ error reading configuration file: open not_exits.yaml: no such file or directory Error executing command. -You can try to run the 'kubectl doctor' command in order to find if there is a configuration issue in your environment. diff --git a/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden index f59ce9c38ce..c93e240d72b 100644 --- a/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden @@ -1,3 +1,3 @@ -It looks like you have a problem with your `/root/.lakectl.yaml` file. -error authenticating request -access_key_id value looks suspicious: accessKeyID +error authenticating requestIt looks like you have a problem with your `/root/.lakectl.yaml` file. +It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong. +access_key_id value looks suspicious: AKIAJOI!COZ5JBYHCSDQ diff --git a/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden index b86d71897a5..81e307d661c 100644 --- a/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden @@ -1,3 +1,3 @@ -It looks like you have a problem with your `/root/.lakectl.yaml` file. -error authenticating request +error authenticating requestIt looks like you have a problem with your `/root/.lakectl.yaml` file. +It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong. secret_access_key value looks suspicious... diff --git a/nessie/golden/lakectl_doctor_with_wrong_credentials.golden b/nessie/golden/lakectl_doctor_with_wrong_credentials.golden index e80ec10e833..1a11c2afa53 100644 --- a/nessie/golden/lakectl_doctor_with_wrong_credentials.golden +++ b/nessie/golden/lakectl_doctor_with_wrong_credentials.golden @@ -1,2 +1,2 @@ -It looks like you have a problem with your `/root/.lakectl.yaml` file. -error authenticating request +error authenticating requestIt looks like you have a problem with your `/root/.lakectl.yaml` file. +It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong. diff --git a/nessie/golden/lakectl_doctor_wrong_credentials.golden b/nessie/golden/lakectl_doctor_wrong_credentials.golden index e80ec10e833..1a11c2afa53 100644 --- a/nessie/golden/lakectl_doctor_wrong_credentials.golden +++ b/nessie/golden/lakectl_doctor_wrong_credentials.golden @@ -1,2 +1,2 @@ -It looks like you have a problem with your `/root/.lakectl.yaml` file. -error authenticating request +error authenticating requestIt looks like you have a problem with your `/root/.lakectl.yaml` file. +It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong. diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden index 36c751b088e..11d30a1f278 100644 --- a/nessie/golden/lakectl_doctor_wrong_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -1,3 +1,3 @@ It looks like you have a problem with your `/root/.lakectl.yaml` file. Probably your endpoint url is wrong. -Suspicious URI format for server.endpoint_url: http:/lakefs:8000/api/v11 +Suspicious URI format for server.endpoint_url: http://localhost:8000/api/v11, doesn't have `/api/v1` suffix. diff --git a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden index 3a274e7cd3d..5c07cc105b2 100644 --- a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden @@ -1,3 +1,4 @@ +Get "/wrong_uri/repositories": unsupported protocol scheme "" It looks like you have a problem with your `/root/.lakectl.yaml` file. Probably your endpoint url is wrong. -Suspicious URI format for server.endpoint_url: wrong_uri +Suspicious URI format for server.endpoint_url: wrong_uri, doesn't have `/api/v1` suffix. From a3c5a42c8c33f828d40a489eed41b62ee988684f Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Wed, 16 Feb 2022 15:29:29 +0200 Subject: [PATCH 22/32] small styling change --- cmd/lakectl/cmd/doctor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index f44b44a1961..d8b62f6908a 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -14,7 +14,7 @@ import ( var ( ErrCredential = errors.New("credential error") ErrWrongEndpointURI = errors.New("wrong endpoint_uri error") - ErrUnknownConfig = errors.New("unknown configuratioin error") + ErrUnknownConfig = errors.New("unknown configuratioin error") ) // doctorCmd represents the doctor command From db49f196c518b0fb6f5ac1bda8a0048af4566f79 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Wed, 16 Feb 2022 15:50:22 +0200 Subject: [PATCH 23/32] Return if no configuration issue was found --- cmd/lakectl/cmd/doctor.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index d8b62f6908a..ce6bd423e2e 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -25,6 +25,7 @@ var doctorCmd = &cobra.Command{ err := ListRepositoriesAndAnalyze(cmd.Context()) if err == nil { Fmt("LakeFS doctor could not find any configuration issues\n") + return } configFileName := viper.GetViper().ConfigFileUsed() Fmt("It looks like you have a problem with your `%v` file.\n", configFileName) From 5a45e3241f2bcd922663153bdcdeffab63f22248 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Wed, 16 Feb 2022 16:17:00 +0200 Subject: [PATCH 24/32] Fixed a test --- nessie/golden/lakectl_doctor_wrong_endpoint.golden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden index 11d30a1f278..9fbf7b8ebb5 100644 --- a/nessie/golden/lakectl_doctor_wrong_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -1,3 +1,3 @@ It looks like you have a problem with your `/root/.lakectl.yaml` file. Probably your endpoint url is wrong. -Suspicious URI format for server.endpoint_url: http://localhost:8000/api/v11, doesn't have `/api/v1` suffix. +Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11, doesn't have `/api/v1` suffix. From 2665e125bb7b912a2a38774d963ded65ce46ae5a Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Wed, 16 Feb 2022 16:44:17 +0200 Subject: [PATCH 25/32] removed unused file --- nessie/doctor_test.go | 2 +- nessie/golden/lakectl_doctor_wrong_credentials.golden | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 nessie/golden/lakectl_doctor_wrong_credentials.golden diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index 46a20fcf17c..2515be12e2b 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -17,7 +17,7 @@ func TestDoctor(t *testing.T) { RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exits.yaml", false, "lakectl_doctor_not_existed_file", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) - RunCmdAndVerifySuccessWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_wrong_credentials", emptyVars) + RunCmdAndVerifySuccessWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_credentials", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams("AKIAJOI!COZ5JBYHCSDQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_access_key_id", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_credentials", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, "TQG5JcovOozCGJnIRmIKH7Flq1tLxnuByi9/WmJ!", endPointURL)+" doctor", false, "lakectl_doctor_with_suspicious_secret_access_key", emptyVars) diff --git a/nessie/golden/lakectl_doctor_wrong_credentials.golden b/nessie/golden/lakectl_doctor_wrong_credentials.golden deleted file mode 100644 index 1a11c2afa53..00000000000 --- a/nessie/golden/lakectl_doctor_wrong_credentials.golden +++ /dev/null @@ -1,2 +0,0 @@ -error authenticating requestIt looks like you have a problem with your `/root/.lakectl.yaml` file. -It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong. From f91f9faf793796fc3da0423c888150ed55ed24e4 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Wed, 16 Feb 2022 16:58:05 +0200 Subject: [PATCH 26/32] Added a new line on output --- cmd/lakectl/cmd/doctor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index ce6bd423e2e..63f58d34215 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -42,7 +42,7 @@ var doctorCmd = &cobra.Command{ secretAccessKey := cfg.Values.Credentials.SecretAccessKey if !IsValidSecretAccessKey(secretAccessKey) { - Fmt("secret_access_key value looks suspicious...") + Fmt("secret_access_key value looks suspicious...\n") } serverEndpoint := cfg.Values.Server.EndpointURL From 834c1132f030ca6cbf511a95fcfd4d3f09c1c3a3 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Thu, 17 Feb 2022 14:07:43 +0200 Subject: [PATCH 27/32] Refcator for errors messages --- cmd/lakectl/cmd/doctor.go | 103 +++++++++++------- nessie/doctor_test.go | 2 +- ... => lakectl_doctor_not_exists_file.golden} | 0 nessie/golden/lakectl_doctor_ok.golden | 2 +- ...octor_with_suspicious_access_key_id.golden | 4 +- ...r_with_suspicious_secret_access_key.golden | 4 +- ...kectl_doctor_with_wrong_credentials.golden | 4 +- .../lakectl_doctor_wrong_endpoint.golden | 6 +- ...tl_doctor_wrong_uri_format_endpoint.golden | 5 +- 9 files changed, 77 insertions(+), 53 deletions(-) rename nessie/golden/{lakectl_doctor_not_existed_file.golden => lakectl_doctor_not_exists_file.golden} (100%) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 63f58d34215..b2ded7668cb 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -11,11 +11,42 @@ import ( "github.com/treeverse/lakefs/pkg/api" ) -var ( - ErrCredential = errors.New("credential error") - ErrWrongEndpointURI = errors.New("wrong endpoint_uri error") - ErrUnknownConfig = errors.New("unknown configuratioin error") -) +type ErrCredential struct { + Message string + Details string +} + +func (e *ErrCredential) Error() string { + return (e.Message + "\n" + e.Details + "\n") +} + +type ErrWrongEndpointURI struct { + Message string + Details string +} + +func (e *ErrWrongEndpointURI) Error() string { + return (e.Message + "\n" + e.Details + "\n") +} + +type ErrUnknownConfig struct { + Message string + Details string +} + +func (e *ErrUnknownConfig) Error() string { + return (e.Message + "\n" + e.Details + "\n") +} + +type SuccessMessage struct { + Message string +} + +var configErrorTemplate = `{{ .Message |red }} +{{ .Details | red }} +` +var successMessageTemplate = `{{ .Message | green}} +` // doctorCmd represents the doctor command var doctorCmd = &cobra.Command{ @@ -24,17 +55,12 @@ var doctorCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { err := ListRepositoriesAndAnalyze(cmd.Context()) if err == nil { - Fmt("LakeFS doctor could not find any configuration issues\n") + Write(successMessageTemplate, &SuccessMessage{"Valid configuration"}) return } - configFileName := viper.GetViper().ConfigFileUsed() - Fmt("It looks like you have a problem with your `%v` file.\n", configFileName) - switch { - case errors.Is(err, ErrCredential): - Fmt("It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong.\n") - case errors.Is(err, ErrWrongEndpointURI): - Fmt("Probably your endpoint url is wrong.\n") - } + + Write(configErrorTemplate, err) + accessKeyID := cfg.Values.Credentials.AccessKeyID if !IsValidAccessKeyID(accessKeyID) { Fmt("access_key_id value looks suspicious: %v\n", accessKeyID) @@ -47,46 +73,45 @@ var doctorCmd = &cobra.Command{ serverEndpoint := cfg.Values.Server.EndpointURL if !strings.HasSuffix(serverEndpoint, api.BaseURL) { - Fmt("Suspicious URI format for server.endpoint_url: %v, doesn't have `%v` suffix.\n", serverEndpoint, api.BaseURL) + Fmt("Suspicious URI format for server.endpoint_url: %v, doesn't end with: `%v`.\n", serverEndpoint, api.BaseURL) } }, } func ListRepositoriesAndAnalyze(ctx context.Context) error { + configFileName := viper.GetViper().ConfigFileUsed() + msgOnErrUnknownConfig := "It looks like you have a problem with your `" + configFileName + "` file." + msgOnErrWrongEndpointURI := "It looks like endpoint url is wrong." + msgOnErrCredential := "It seems like the `access_key_id` or `secret_access_key` you supplied are wrong." + serverEndpoint := cfg.Values.Server.EndpointURL _, err := url.Parse(serverEndpoint) if err != nil { - Fmt("%v\n", err.Error()) - return ErrWrongEndpointURI + return &ErrWrongEndpointURI{msgOnErrWrongEndpointURI, err.Error()} } client := getClient() resp, err := client.ListRepositoriesWithResponse(ctx, &api.ListRepositoriesParams{}) - if err != nil { - urlErr := new(url.Error) + switch { + case err != nil: + urlErr := &url.Error{} if errors.As(err, &urlErr) { - Fmt("%v\n", err.Error()) - return ErrWrongEndpointURI - } - return err - } - if resp != nil { - if resp.JSON200 != nil { - return nil - } - if resp.JSON401 != nil { - Fmt(resp.JSON401.Message) - return ErrCredential - } - // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) - if resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200 { - return ErrWrongEndpointURI - } - if resp.JSONDefault != nil { - Fmt(resp.JSONDefault.Message) + return &ErrWrongEndpointURI{msgOnErrWrongEndpointURI, err.Error()} } + return &ErrUnknownConfig{msgOnErrUnknownConfig, err.Error()} + case resp == nil: + break + case resp.JSON200 != nil: + return nil + case resp.JSON401 != nil: + return &ErrCredential{msgOnErrCredential, resp.JSON401.Message} + // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) + case resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200: + return &ErrWrongEndpointURI{msgOnErrWrongEndpointURI, ""} + case resp.JSONDefault != nil: + return &ErrUnknownConfig{msgOnErrUnknownConfig, resp.JSONDefault.Message} } - return ErrUnknownConfig + return &ErrUnknownConfig{msgOnErrUnknownConfig, "An unknown error accourd while trying to analyzing LakeCtl configuration."} } //nolint:gochecknoinits diff --git a/nessie/doctor_test.go b/nessie/doctor_test.go index 2515be12e2b..40d595f3871 100644 --- a/nessie/doctor_test.go +++ b/nessie/doctor_test.go @@ -14,7 +14,7 @@ func TestDoctor(t *testing.T) { defaultConfigPath := "/root/.lakectl.yaml" os.Create(defaultConfigPath) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_ok", emptyVars) - RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exits.yaml", false, "lakectl_doctor_not_existed_file", emptyVars) + RunCmdAndVerifyFailureWithFile(t, lakectlLocation()+" doctor -c not_exits.yaml", false, "lakectl_doctor_not_exists_file", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, endPointURL+"1")+" doctor", false, "lakectl_doctor_wrong_endpoint", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams(accessKeyID, secretAccessKey, "wrong_uri")+" doctor", false, "lakectl_doctor_wrong_uri_format_endpoint", emptyVars) RunCmdAndVerifySuccessWithFile(t, LakectlWithParams("AKIAJZZZZZZZZZZZZZZQ", secretAccessKey, endPointURL)+" doctor", false, "lakectl_doctor_with_wrong_credentials", emptyVars) diff --git a/nessie/golden/lakectl_doctor_not_existed_file.golden b/nessie/golden/lakectl_doctor_not_exists_file.golden similarity index 100% rename from nessie/golden/lakectl_doctor_not_existed_file.golden rename to nessie/golden/lakectl_doctor_not_exists_file.golden diff --git a/nessie/golden/lakectl_doctor_ok.golden b/nessie/golden/lakectl_doctor_ok.golden index e4673676cc1..759761d0da5 100644 --- a/nessie/golden/lakectl_doctor_ok.golden +++ b/nessie/golden/lakectl_doctor_ok.golden @@ -1 +1 @@ -LakeFS doctor could not find any configuration issues +Valid configuration diff --git a/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden index c93e240d72b..dc72433a405 100644 --- a/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_access_key_id.golden @@ -1,3 +1,3 @@ -error authenticating requestIt looks like you have a problem with your `/root/.lakectl.yaml` file. -It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong. +It seems like the `access_key_id` or `secret_access_key` you supplied are wrong. +error authenticating request access_key_id value looks suspicious: AKIAJOI!COZ5JBYHCSDQ diff --git a/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden index 81e307d661c..edc944883aa 100644 --- a/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden +++ b/nessie/golden/lakectl_doctor_with_suspicious_secret_access_key.golden @@ -1,3 +1,3 @@ -error authenticating requestIt looks like you have a problem with your `/root/.lakectl.yaml` file. -It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong. +It seems like the `access_key_id` or `secret_access_key` you supplied are wrong. +error authenticating request secret_access_key value looks suspicious... diff --git a/nessie/golden/lakectl_doctor_with_wrong_credentials.golden b/nessie/golden/lakectl_doctor_with_wrong_credentials.golden index 1a11c2afa53..1a092d13065 100644 --- a/nessie/golden/lakectl_doctor_with_wrong_credentials.golden +++ b/nessie/golden/lakectl_doctor_with_wrong_credentials.golden @@ -1,2 +1,2 @@ -error authenticating requestIt looks like you have a problem with your `/root/.lakectl.yaml` file. -It is possible that the `access_key_id` or `secret_access_key` you supplied are wrong. +It seems like the `access_key_id` or `secret_access_key` you supplied are wrong. +error authenticating request diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden index 9fbf7b8ebb5..f75513fa2a6 100644 --- a/nessie/golden/lakectl_doctor_wrong_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -1,3 +1,3 @@ -It looks like you have a problem with your `/root/.lakectl.yaml` file. -Probably your endpoint url is wrong. -Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11, doesn't have `/api/v1` suffix. +It looks like endpoint url is wrong. + +Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11, doesn't end with: `/api/v1`. diff --git a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden index 5c07cc105b2..d85e8d503a3 100644 --- a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden @@ -1,4 +1,3 @@ +It looks like endpoint url is wrong. Get "/wrong_uri/repositories": unsupported protocol scheme "" -It looks like you have a problem with your `/root/.lakectl.yaml` file. -Probably your endpoint url is wrong. -Suspicious URI format for server.endpoint_url: wrong_uri, doesn't have `/api/v1` suffix. +Suspicious URI format for server.endpoint_url: wrong_uri, doesn't end with: `/api/v1`. From 3d13630885703b598fcb174ebc39800a7610333c Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Sun, 20 Feb 2022 11:31:30 +0200 Subject: [PATCH 28/32] Changed errors structs names --- cmd/lakectl/cmd/doctor.go | 69 ++++++++++++------- .../lakectl_doctor_wrong_endpoint.golden | 2 +- ...tl_doctor_wrong_uri_format_endpoint.golden | 2 +- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index b2ded7668cb..4d2954310e3 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -11,43 +11,59 @@ import ( "github.com/treeverse/lakefs/pkg/api" ) -type ErrCredential struct { +type Detailed interface { + GetDetails() string +} + + +type CredentialsError struct { Message string Details string } -func (e *ErrCredential) Error() string { - return (e.Message + "\n" + e.Details + "\n") +func (e *CredentialsError) Error() string { return e.Message } + +func (e *CredentialsError) GetDetails() string { + return e.Message + "\n" + e.Details } -type ErrWrongEndpointURI struct { +type WrongEndpointURIError struct { Message string Details string } -func (e *ErrWrongEndpointURI) Error() string { - return (e.Message + "\n" + e.Details + "\n") +func (e *WrongEndpointURIError) Error() string { return e.Message } + +func (e *WrongEndpointURIError) GetDetails() string { + return e.Message + "\n" + e.Details } -type ErrUnknownConfig struct { +type UnknownConfigError struct { Message string Details string } -func (e *ErrUnknownConfig) Error() string { - return (e.Message + "\n" + e.Details + "\n") +func (e *UnknownConfigError) Error() string { return e.Message } + +func (e *UnknownConfigError) GetDetails() string { + return e.Message + "\n" + e.Details } -type SuccessMessage struct { +type UserMessage struct { Message string } -var configErrorTemplate = `{{ .Message |red }} -{{ .Details | red }} +var detailedErrorTemplate = `{{ .Message |red }} +{{ .Details }} +` +var errorTemplate = `{{ .Message |red }} ` + var successMessageTemplate = `{{ .Message | green}} ` +var analayzingMessageTemplate = `{{ .Message }} +` // doctorCmd represents the doctor command var doctorCmd = &cobra.Command{ Use: "doctor", @@ -55,25 +71,29 @@ var doctorCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { err := ListRepositoriesAndAnalyze(cmd.Context()) if err == nil { - Write(successMessageTemplate, &SuccessMessage{"Valid configuration"}) + Write(successMessageTemplate, &UserMessage{"Valid configuration"}) return } - Write(configErrorTemplate, err) + if detailedErr, ok := err.(Detailed); ok { + Write(detailedErrorTemplate, detailedErr) + } else { + Write(errorTemplate, err) + } accessKeyID := cfg.Values.Credentials.AccessKeyID if !IsValidAccessKeyID(accessKeyID) { - Fmt("access_key_id value looks suspicious: %v\n", accessKeyID) + Write(analayzingMessageTemplate, &UserMessage{"access_key_id value looks suspicious: "+accessKeyID}) } secretAccessKey := cfg.Values.Credentials.SecretAccessKey if !IsValidSecretAccessKey(secretAccessKey) { - Fmt("secret_access_key value looks suspicious...\n") + Write(analayzingMessageTemplate, &UserMessage{"secret_access_key value looks suspicious..."}) } serverEndpoint := cfg.Values.Server.EndpointURL if !strings.HasSuffix(serverEndpoint, api.BaseURL) { - Fmt("Suspicious URI format for server.endpoint_url: %v, doesn't end with: `%v`.\n", serverEndpoint, api.BaseURL) + Write(analayzingMessageTemplate, &UserMessage{"Suspicious URI format for server.endpoint_url: "+serverEndpoint+" doesn't end with: `"+api.BaseURL+"`."}) } }, } @@ -84,10 +104,11 @@ func ListRepositoriesAndAnalyze(ctx context.Context) error { msgOnErrWrongEndpointURI := "It looks like endpoint url is wrong." msgOnErrCredential := "It seems like the `access_key_id` or `secret_access_key` you supplied are wrong." + // getClient might die on url.Parse error, so check it first. serverEndpoint := cfg.Values.Server.EndpointURL _, err := url.Parse(serverEndpoint) if err != nil { - return &ErrWrongEndpointURI{msgOnErrWrongEndpointURI, err.Error()} + return &WrongEndpointURIError{msgOnErrWrongEndpointURI, err.Error()} } client := getClient() resp, err := client.ListRepositoriesWithResponse(ctx, &api.ListRepositoriesParams{}) @@ -96,22 +117,22 @@ func ListRepositoriesAndAnalyze(ctx context.Context) error { case err != nil: urlErr := &url.Error{} if errors.As(err, &urlErr) { - return &ErrWrongEndpointURI{msgOnErrWrongEndpointURI, err.Error()} + return &WrongEndpointURIError{msgOnErrWrongEndpointURI, err.Error()} } - return &ErrUnknownConfig{msgOnErrUnknownConfig, err.Error()} + return &UnknownConfigError{msgOnErrUnknownConfig, err.Error()} case resp == nil: break case resp.JSON200 != nil: return nil case resp.JSON401 != nil: - return &ErrCredential{msgOnErrCredential, resp.JSON401.Message} + return &CredentialsError{msgOnErrCredential, resp.JSON401.Message} // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) case resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200: - return &ErrWrongEndpointURI{msgOnErrWrongEndpointURI, ""} + return &WrongEndpointURIError{msgOnErrWrongEndpointURI, ""} case resp.JSONDefault != nil: - return &ErrUnknownConfig{msgOnErrUnknownConfig, resp.JSONDefault.Message} + return &UnknownConfigError{msgOnErrUnknownConfig, resp.JSONDefault.Message} } - return &ErrUnknownConfig{msgOnErrUnknownConfig, "An unknown error accourd while trying to analyzing LakeCtl configuration."} + return &UnknownConfigError{msgOnErrUnknownConfig, "An unknown error accourd while trying to analyzing LakeCtl configuration."} } //nolint:gochecknoinits diff --git a/nessie/golden/lakectl_doctor_wrong_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_endpoint.golden index f75513fa2a6..cd7db79acc6 100644 --- a/nessie/golden/lakectl_doctor_wrong_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_endpoint.golden @@ -1,3 +1,3 @@ It looks like endpoint url is wrong. -Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11, doesn't end with: `/api/v1`. +Suspicious URI format for server.endpoint_url: http://lakefs:8000/api/v11 doesn't end with: `/api/v1`. diff --git a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden index d85e8d503a3..2ecb89d5d05 100644 --- a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden @@ -1,3 +1,3 @@ It looks like endpoint url is wrong. Get "/wrong_uri/repositories": unsupported protocol scheme "" -Suspicious URI format for server.endpoint_url: wrong_uri, doesn't end with: `/api/v1`. +Suspicious URI format for server.endpoint_url: wrong_uridoesn't end with: `/api/v1`. From 4644576a465ec2f728656b06522f7ac3b72163d3 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Sun, 20 Feb 2022 11:42:25 +0200 Subject: [PATCH 29/32] Fixed linter errors --- cmd/lakectl/cmd/doctor.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 4d2954310e3..9c984257849 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -15,7 +15,6 @@ type Detailed interface { GetDetails() string } - type CredentialsError struct { Message string Details string From 5fc6254e41f311be038b7667ac1ffb44a5a51164 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Sun, 20 Feb 2022 11:57:36 +0200 Subject: [PATCH 30/32] Fixed golden file --- nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden index 2ecb89d5d05..622536ff57a 100644 --- a/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden +++ b/nessie/golden/lakectl_doctor_wrong_uri_format_endpoint.golden @@ -1,3 +1,3 @@ It looks like endpoint url is wrong. Get "/wrong_uri/repositories": unsupported protocol scheme "" -Suspicious URI format for server.endpoint_url: wrong_uridoesn't end with: `/api/v1`. +Suspicious URI format for server.endpoint_url: wrong_uri doesn't end with: `/api/v1`. From 7a1853b01064162dc4345d41c0b2337ce622d033 Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Sun, 20 Feb 2022 12:17:51 +0200 Subject: [PATCH 31/32] Fixed linter errors --- cmd/lakectl/cmd/doctor.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 9c984257849..3da6bc6b4c3 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -63,6 +63,7 @@ var successMessageTemplate = `{{ .Message | green}} var analayzingMessageTemplate = `{{ .Message }} ` + // doctorCmd represents the doctor command var doctorCmd = &cobra.Command{ Use: "doctor", @@ -82,7 +83,7 @@ var doctorCmd = &cobra.Command{ accessKeyID := cfg.Values.Credentials.AccessKeyID if !IsValidAccessKeyID(accessKeyID) { - Write(analayzingMessageTemplate, &UserMessage{"access_key_id value looks suspicious: "+accessKeyID}) + Write(analayzingMessageTemplate, &UserMessage{"access_key_id value looks suspicious: " + accessKeyID}) } secretAccessKey := cfg.Values.Credentials.SecretAccessKey @@ -92,7 +93,7 @@ var doctorCmd = &cobra.Command{ serverEndpoint := cfg.Values.Server.EndpointURL if !strings.HasSuffix(serverEndpoint, api.BaseURL) { - Write(analayzingMessageTemplate, &UserMessage{"Suspicious URI format for server.endpoint_url: "+serverEndpoint+" doesn't end with: `"+api.BaseURL+"`."}) + Write(analayzingMessageTemplate, &UserMessage{"Suspicious URI format for server.endpoint_url: " + serverEndpoint + " doesn't end with: `" + api.BaseURL + "`."}) } }, } From 04e41858a67c13a9f521776d45975f99a21bbdad Mon Sep 17 00:00:00 2001 From: Idan Novogroder Date: Mon, 21 Feb 2022 18:14:56 +0200 Subject: [PATCH 32/32] empty commit --- cmd/lakectl/cmd/doctor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/lakectl/cmd/doctor.go b/cmd/lakectl/cmd/doctor.go index 3da6bc6b4c3..9582384caab 100644 --- a/cmd/lakectl/cmd/doctor.go +++ b/cmd/lakectl/cmd/doctor.go @@ -126,7 +126,7 @@ func ListRepositoriesAndAnalyze(ctx context.Context) error { return nil case resp.JSON401 != nil: return &CredentialsError{msgOnErrCredential, resp.JSON401.Message} - // In case we get the "not found" HTML page (the status is 200 and not 404 in this case) + // In case we get the "not found" HTML page (the status is 200 and not 404 in this case). case resp.HTTPResponse != nil && resp.HTTPResponse.StatusCode == 200: return &WrongEndpointURIError{msgOnErrWrongEndpointURI, ""} case resp.JSONDefault != nil: