Use mcdsl/terminal for all password prompts
Replace direct golang.org/x/term calls with mcdsl/terminal.ReadPassword across mciasctl (6 sites), mciasgrpcctl (1 site), and mciasdb (1 site). Aligns with the new CLI security standard in engineering-standards.md. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,8 @@ import (
|
||||
|
||||
"git.wntrmute.dev/mc/mcias/internal/auth"
|
||||
"git.wntrmute.dev/mc/mcias/internal/model"
|
||||
"golang.org/x/term"
|
||||
|
||||
"git.wntrmute.dev/mc/mcdsl/terminal"
|
||||
)
|
||||
|
||||
func (t *tool) runAccount(args []string) {
|
||||
@@ -233,20 +234,14 @@ func (t *tool) accountResetTOTP(args []string) {
|
||||
// readPassword reads a password from the terminal without echo.
|
||||
// Falls back to a regular line read if stdin is not a terminal (e.g. in tests).
|
||||
func readPassword(prompt string) (string, error) {
|
||||
fmt.Fprint(os.Stderr, prompt)
|
||||
fd := int(os.Stdin.Fd()) //nolint:gosec // G115: file descriptors are non-negative and fit in int on all supported platforms
|
||||
if term.IsTerminal(fd) {
|
||||
pw, err := term.ReadPassword(fd)
|
||||
fmt.Fprintln(os.Stderr) // newline after hidden input
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("read password from terminal: %w", err)
|
||||
}
|
||||
return string(pw), nil
|
||||
pw, err := terminal.ReadPassword(prompt)
|
||||
if err == nil {
|
||||
return pw, nil
|
||||
}
|
||||
// Not a terminal: read a plain line (for piped input in tests).
|
||||
// Fallback for piped input (e.g. tests).
|
||||
fmt.Fprint(os.Stderr, prompt)
|
||||
var line string
|
||||
_, err := fmt.Fscanln(os.Stdin, &line)
|
||||
if err != nil {
|
||||
if _, err := fmt.Fscanln(os.Stdin, &line); err != nil {
|
||||
return "", fmt.Errorf("read password: %w", err)
|
||||
}
|
||||
return line, nil
|
||||
|
||||
Reference in New Issue
Block a user