-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cli/command: some cleanups / refactoring, and fixes related to auth #4190
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
Merged
Conversation
This file contains hidden or 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
Member
Author
|
@rumpl @laurazard ptal 🤗 |
1 task
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #4190 +/- ##
==========================================
- Coverage 58.86% 58.85% -0.01%
==========================================
Files 572 572
Lines 49576 49492 -84
==========================================
- Hits 29182 29130 -52
+ Misses 18624 18598 -26
+ Partials 1770 1764 -6 |
Member
Author
|
oh! I think I forgot to push some of the changes. let me dig them up |
17df83e to
1b617d6
Compare
…error ConfigureAuth used the readInput() utility to read the username and password. However, this utility did not return errors it encountered, but instead did an os.Exit(1). A result of this was that the terminal was not restored if an error happened. When reading the password, the terminal is configured to disable echo (i.e. characters are not printed), and failing to restore the previous state means that the terminal is now "non-functional". This patch: - changes readInput() to return errors it encounters - uses a defer() to restore terminal state Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
…sword 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>
Also adds a TODO to verify if this special handling is still needed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This also simplifies the code a bit. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Replace uses of this function in favor of the implementation in the API types, so that we have a single, canonical implementation. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
…mage replace the local code with RetrieveAuthTokenFromImage, which does exactly the same; https://github.com/docker/cli/blob/623356001f6310fef7a8cca0b9ba0ac1b735bb38/cli/command/registry.go#L163-L188 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
…lity This utility provides the same logic as was implemented here (and using it aligns with the "docker pull" equivalent). Also added a TODO to replace this function with the regular "docker pull" code. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1b617d6 to
5d856a5
Compare
Member
Author
|
all green now 👍 |
vvoland
approved these changes
Apr 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: ConfigureAuth: fix terminal state not being restored on error
ConfigureAuth used the readInput() utility to read the username and password.
However, this utility did not return errors it encountered, but instead did
an os.Exit(1). A result of this was that the terminal was not restored if
an error happened. When reading the password, the terminal is configured to
disable echo (i.e. characters are not printed), and failing to restore
the previous state means that the terminal is now "non-functional".
This patch:
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.
cli/command/registry: remove intermediate var that collided
This also simplifies the code a bit.
cli/command: replace EncodeAuthToBase64 for registry.EncodeAuthConfig
Replace uses of this function in favor of the implementation in the
API types, so that we have a single, canonical implementation.
cli/command/container/create: pullImage(): use RetrieveAuthTokenFromImage
replace the local code with RetrieveAuthTokenFromImage, which does exactly the same;
cli/cli/command/registry.go
Lines 163 to 188 in 6233560
cli/command/container/create: pullImage() remove intermediate vars
cli/command/container: pullImage: use DisplayJSONMessagesToStream utility
This utility provides the same logic as was implemented here (and using it
aligns with the "docker pull" equivalent).
Also added a TODO to replace this function with the regular "docker pull"
code.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)