fix: trim CRLF from password read from stdin
bufio's reader.ReadString includes any CRLF characters and we don't want these in the resulting token because this leads to errors in the authentication like this: ``` ✗ failed to get Git repository "https://github.com/kingdon-ci/jenkins-infra": Get "https://api.github.com/repos/kingdon-ci/jenkins-infra": net/http: invalid header field value "Bearer gho_NNNNNsecrettokenMMMMM\n" for key Authorization ``` Signed-off-by: Max Jonas Werner <mail@makk.es>
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -171,6 +172,9 @@ func homeDir() string {
|
||||
return os.Getenv("USERPROFILE") // windows
|
||||
}
|
||||
|
||||
// readPasswordFromStdin reads a password from stdin and returns the input
|
||||
// with trailing newline and/or carriage return removed. It also makes sure that terminal
|
||||
// echoing is turned off if stdin is a terminal.
|
||||
func readPasswordFromStdin(prompt string) (string, error) {
|
||||
var out string
|
||||
var err error
|
||||
@@ -187,5 +191,5 @@ func readPasswordFromStdin(prompt string) (string, error) {
|
||||
return "", fmt.Errorf("could not read from stdin: %w", err)
|
||||
}
|
||||
fmt.Println()
|
||||
return out, nil
|
||||
return strings.TrimRight(out, "\r\n"), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user