diff --git a/internal/configuration/Configuration.go b/internal/configuration/Configuration.go index 129d656..21122a7 100644 --- a/internal/configuration/Configuration.go +++ b/internal/configuration/Configuration.go @@ -145,7 +145,7 @@ func generateDefaultConfig() { serverSettings = Configuration{ SaltAdmin: saltAdmin, } - username := askForUsername() + username := askForUsername(1) password := askForPassword() port := askForPort() url := askForUrl(port) @@ -199,7 +199,11 @@ func Save() { } // Asks for username or loads it from env and returns input as string if valid -func askForUsername() string { +func askForUsername(try int) string { + if try > 5 { + fmt.Println("Too many invalid entries! If you are running the setup with Docker, make sure to start the container with the -it flag.") + os.Exit(1) + } fmt.Print("Username: ") envUsername := Environment.AdminName if envUsername != "" { @@ -211,7 +215,7 @@ func askForUsername() string { return username } fmt.Println("Username needs to be at least 4 characters long") - return askForUsername() + return askForUsername(try + 1) } // Asks for password or loads it from env and returns input as string if valid diff --git a/internal/configuration/Configuration_test.go b/internal/configuration/Configuration_test.go index 1ebd8b8..e479274 100644 --- a/internal/configuration/Configuration_test.go +++ b/internal/configuration/Configuration_test.go @@ -95,7 +95,7 @@ func TestUpgradeDb(t *testing.T) { func TestAskForUsername(t *testing.T) { original := testconfiguration.StartMockInputStdin("admin") - output := askForUsername() + output := askForUsername(1) testconfiguration.StopMockInputStdin(original) test.IsEqualString(t, output, "admin") }