Skip to content
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

login: Add message about using PATs #4478

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

rumpl
Copy link
Member

@rumpl rumpl commented Aug 2, 2023

- What I did

Added a hint about using PATs

$ docker login
Log in with your Docker ID or email address to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com/ to create one.
You can log in with your password or a Personal Access Token (PAT). Using a limited-scope PAT grants better security and is required for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/

Username: 

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2023

Codecov Report

Merging #4478 (9947f4b) into master (06de1f8) will decrease coverage by 0.43%.
The diff coverage is 0.00%.

❗ Current head 9947f4b differs from pull request most recent head 8d51f36. Consider uploading reports for the commit 8d51f36 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4478      +/-   ##
==========================================
- Coverage   59.39%   58.97%   -0.43%     
==========================================
  Files         288      286       -2     
  Lines       24782    24779       -3     
==========================================
- Hits        14720    14614     -106     
- Misses       9175     9278     +103     
  Partials      887      887              

@@ -106,7 +106,12 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes
if flUser = strings.TrimSpace(flUser); flUser == "" {
if isDefaultRegistry {
// if this is a default registry (docker hub), then display the following message.
fmt.Fprintln(cli.Out(), "Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.")
fmt.Fprintln(cli.Out(), "Log in with your Docker ID or email address to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com/ to create one.")
if os.Getenv("DOCKER_CLI_HINTS") != "false" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 should also be supported. It feels more natural for an env variable.

How about using strconv.ParseBool withh fallback to true (hints enabled by default) if err != nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should also handle "no", like yaml does? I'm joking, this check comes from compose-cli.

I kinda like only one possible value here

Copy link
Member Author

@rumpl rumpl Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nice possibility is to flip the check, have a DOCKER_NO_CLI_HINTS and only check that the variable is defined.

Examples

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd prefer DOCKER_NO_CLI_HINTS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOCKER_DISABLE_CLI_HINTS would be an option.

I think we came with DOCKER_CLI_HINTS in a similar fashion as DOCKER_BUILDKIT; initially that was "opt-in", but the intent was to make that "opt-out" after incubation.

DOCKER_CLI_HINTS (and DOCKER_BUILDKIT) is more agnostic w.r.t. it being enable/disable. And can start with "opt-in" (DOCKER_CLI_HINTS=1) and when it's the default, "opt-out" (DOCKER_CLI_HINTS=0), or for situations where the config would disable it and you wanted to enable it for a specific call (through env var), as DOCKER_DISABLE_CLI_HINTS=false is kinda awkward because of the double negative.

w.r.t. accepted values, if we do look at value (beyond "non-empty"), I agree that we should use ParseBool if the value is non-empty, which would match other env-vars, such as DOCKER_BUILDKIT;

cli/cli/command/cli.go

Lines 164 to 171 in 06de1f8

// use DOCKER_BUILDKIT env var value if set and not empty
if v := os.Getenv("DOCKER_BUILDKIT"); v != "" {
enabled, err := strconv.ParseBool(v)
if err != nil {
return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value")
}
return enabled, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to ParseBool and DOCKER_NO_CLI_HINTS

Copy link
Member

@neersighted neersighted Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have DOCKER_CLI_HINTS in the wrapper (see docker/for-mac#6904 for evidence of people building on it); we might have to continue with that out of inertia, or at least propagate any changes we make here back to the Scout hints implementation (cc @eunomie)

@rumpl rumpl requested a review from thaJeztah August 2, 2023 12:11
@rumpl rumpl force-pushed the feat-pat-suggest branch 2 times, most recently from 78df3b5 to d73fc86 Compare August 3, 2023 08:31
Copy link
Member

@laurazard laurazard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@vvoland vvoland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; it's beautiful now!

Comment on lines +116 to +117
fmt.Fprintln(cli.Out(), patSuggest)
fmt.Fprintln(cli.Out())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably can't / shouldn't change the existing (old) hint, but perhaps we should use cli.Err() here (so that it can be redirected)

Comment on lines +23 to +25
const patSuggest = "You can log in with your password or a Personal Access " +
"Token (PAT). Using a limited-scope PAT grants better security and is required " +
"for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use a string-literal for this (back-tick)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn’t use them because we don’t want newlines

@neersighted neersighted self-assigned this Aug 10, 2023
@Quikexxxx

This comment was marked as spam.

@neersighted
Copy link
Member

I'm going to merge this as-is, given no further discussion around the env var, and the desire to stay consistent (for now) with what was already done in the CLI wrapper for Scout.

@neersighted neersighted merged commit 3dbf1af into docker:master Aug 16, 2023
74 checks passed
@neersighted neersighted added this to the 25.0.0 milestone Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants