Description
An issue with harbor login --password-stdin when password is provided via piped input.
Previously, the login flow used term.ReadPassword(---), which expects an interactive terminal (TTY). This caused failures or incorrect behavior when stdin was piped (non-interactive).
This change introduces GetSecretStdin(...) which:
Detects whether stdin is interactive or piped
Uses hidden password input for interactive terminals
Reads directly from stdin when input is piped
Steps to Reproduce
Run command:
- echo "mypassword" | harbor login example.com -u user --password-stdin
Observe behavior
Expected Behavior
CLI should correctly read password from stdin when piped
Password should not be modified (including leading/trailing spaces)
Actual Behavior
Login may fail or behave incorrectly when stdin is piped
Password may be altered due to TrimSpace removing valid whitespace
Environment
- OS: macOS (also reproducible on other platforms)
- Tool version: harbor-cli (main branch before fix)
- Other relevant details: stdin is non-interactive when using pipe
Additional Context
Note: Running full go test ./pkg/utils may fail in sandbox environments due to attempts to write under $HOME/.harbor, which is unrelated to this change..
Description
An issue with harbor login --password-stdin when password is provided via piped input.
Previously, the login flow used term.ReadPassword(---), which expects an interactive terminal (TTY). This caused failures or incorrect behavior when stdin was piped (non-interactive).
This change introduces GetSecretStdin(...) which:
Detects whether stdin is interactive or piped
Uses hidden password input for interactive terminals
Reads directly from stdin when input is piped
Steps to Reproduce
Run command:
Observe behavior
Expected Behavior
CLI should correctly read password from stdin when piped
Password should not be modified (including leading/trailing spaces)
Actual Behavior
Login may fail or behave incorrectly when stdin is piped
Password may be altered due to TrimSpace removing valid whitespace
Environment
Additional Context
Note: Running full go test ./pkg/utils may fail in sandbox environments due to attempts to write under $HOME/.harbor, which is unrelated to this change..