cli/command: ConfigureAuth: trim whitespace both for username and password

changes readInput() to trim whitespace. The existing code tried to be
conservative and only trimmed whitespace for username (not for password).
Passwords with leading/trailing whitespace would be _very_ unlikely, and
trimming whitespace is generally accepted.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-12 21:16:03 +02:00
parent d0ec8fa5cf
commit 68d791e56d
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 3 additions and 3 deletions

View File

@ -118,7 +118,6 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes
if err != nil { if err != nil {
return err return err
} }
flUser = strings.TrimSpace(flUser)
if flUser == "" { if flUser == "" {
flUser = authconfig.Username flUser = authconfig.Username
} }
@ -153,13 +152,14 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes
} }
// readInput reads, and returns user input from in. It tries to return a // readInput reads, and returns user input from in. It tries to return a
// single line, not including the end-of-line bytes. // single line, not including the end-of-line bytes, and trims leading
// and trailing whitespace.
func readInput(in io.Reader) (string, error) { func readInput(in io.Reader) (string, error) {
line, _, err := bufio.NewReader(in).ReadLine() line, _, err := bufio.NewReader(in).ReadLine()
if err != nil { if err != nil {
return "", errors.Wrap(err, "error while reading input") return "", errors.Wrap(err, "error while reading input")
} }
return string(line), nil return strings.TrimSpace(string(line)), nil
} }
func promptWithDefault(out io.Writer, prompt string, configDefault string) { func promptWithDefault(out io.Writer, prompt string, configDefault string) {