-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[27.x backport] cli/command: PromptUserForCredentials: assorted minor improvements and (linting) fixes #5611
Merged
thaJeztah
merged 8 commits into
docker:27.x
from
thaJeztah:27.x_backport_login_minor_refactor
Nov 14, 2024
Merged
[27.x backport] cli/command: PromptUserForCredentials: assorted minor improvements and (linting) fixes #5611
thaJeztah
merged 8 commits into
docker:27.x
from
thaJeztah:27.x_backport_login_minor_refactor
Nov 14, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This function has multiple conditional branches, which makes it harder to see at a glance whether authConfig may be partially populated. This patch instead returns a fresh instance for error returns to prevent any confusion. It also removes the named output variables, as they're now no longer used, and the returned types should already be descriptive enough to understand what's returned. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 3a84850) Signed-off-by: Sebastiaan van Stijn <[email protected]>
remove isDefaultRegistry and inline it where it's used; the code-comment already outlines what we're looking for, so the intermediate var didn't add much currently. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit a55cfe5) Signed-off-by: Sebastiaan van Stijn <[email protected]>
move the "post" check for username being empty inside the branch that's handling the username, as it's the only branch where username is mutated after checking if it's empty. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 581cf36) Signed-off-by: Sebastiaan van Stijn <[email protected]>
- move trimming defaultUsername inside the if-branch, as it's the only location where the result of the trimmed username is use. - do the reverse for trimming argUser, because the result of trimming argUser is used outside of the if-branch (not just for the condition). putting it inside the condition makes it easy to assume the result is only used locally. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit eda78e9) Signed-off-by: Sebastiaan van Stijn <[email protected]>
we don't support empty passwords; when prompting the user for a password, we already trim the result, but we didn't do the same for a password that's passed through stdin or through the `-p` / `--password` flag. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit a21a5f4) Signed-off-by: Sebastiaan van Stijn <[email protected]>
…e fail If restoring the terminal state fails, "echo" no longer works, which means that anything the user types is no longer shown. The login itself may already have succeeded, so we should not fail the command, but it's good to inform the user that this happened, which may give them a clue why things no longer work as they expect them to work. With this patch: docker login -u yourname Password: Error: failed to restore terminal state to echo input: something bad happened Login Succeeded We should consider printing instructions how to restore this manually (other than restarting the shell). e.g., 'run stty echo' when in a Linux or macOS shell, but PowerShell and CMD.exe may need different instructions. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 3d8b495) Signed-off-by: Sebastiaan van Stijn <[email protected]>
This message resulted in code-lines that were too long; move it to a const together with the other hint. While at it, also suppress unhandled error, and touch-up the code-comment. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 378a3d7) Signed-off-by: Sebastiaan van Stijn <[email protected]>
Keep the linters (and my IDE) happy; these errors should be safe to ignore. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 4b7a1e4) Signed-off-by: Sebastiaan van Stijn <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 27.x #5611 +/- ##
==========================================
- Coverage 58.65% 58.36% -0.29%
==========================================
Files 345 336 -9
Lines 29053 28791 -262
==========================================
- Hits 17040 16805 -235
+ Misses 11042 11019 -23
+ Partials 971 967 -4 |
laurazard
approved these changes
Nov 14, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area/authentication
kind/enhancement
kind/refactor
PR's that refactor, or clean-up code
status/2-code-review
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
cli/command: PromptUserForCredentials: remove named output variables
This function has multiple conditional branches, which makes it harder
to see at a glance whether authConfig may be partially populated. This
patch instead returns a fresh instance for error returns to prevent any
confusion.
It also removes the named output variables, as they're now no longer used,
and the returned types should already be descriptive enough to understand
what's returned.
cli/command: PromptUserForCredentials: inline isDefaultRegistry
remove isDefaultRegistry and inline it where it's used; the code-comment
already outlines what we're looking for, so the intermediate var didn't
add much currently.
cli/command: PromptUserForCredentials: move "post" check for empty name
move the "post" check for username being empty inside the branch
that's handling the username, as it's the only branch where username
is mutated after checking if it's empty.
cli/command: PromptUserForCredentials: move trimming where it's used
location where the result of the trimmed username is use.
argUser is used outside of the if-branch (not just for the condition).
putting it inside the condition makes it easy to assume the result is
only used locally.
cli/command: PromptUserForCredentials: always trim password
we don't support empty passwords; when prompting the user for a password,
we already trim the result, but we didn't do the same for a password that's
passed through stdin or through the
-p
/--password
flag.cli/command: PromptUserForCredentials: print error on terminal restore fail
If restoring the terminal state fails, "echo" no longer works, which means
that anything the user types is no longer shown. The login itself may already
have succeeded, so we should not fail the command, but it's good to inform
the user that this happened, which may give them a clue why things no longer
work as they expect them to work.
With this patch:
We should consider printing instructions how to restore this manually (other
than restarting the shell). e.g., 'run stty echo' when in a Linux or macOS shell,
but PowerShell and CMD.exe may need different instructions.
cli/command: PromptUserForCredentials: use consts for all hints
This message resulted in code-lines that were too long; move it to a
const together with the other hint. While at it, also suppress unhandled
error, and touch-up the code-comment.
cli/command: PromptUserForCredentials: suppress unhandled errors
Keep the linters (and my IDE) happy; these errors should be safe to ignore.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)