From ddeb7eb4edc5d22154da5b5bdb9c074611fcefc3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 19 Oct 2024 13:23:29 +0200 Subject: [PATCH] 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. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 378a3d7d3608308aa8ac01a954497916e0110653) Signed-off-by: Sebastiaan van Stijn --- cli/command/registry.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cli/command/registry.go b/cli/command/registry.go index a9c19b8c71..55754a8449 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -19,9 +19,13 @@ import ( "github.com/pkg/errors" ) -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/" +const ( + registerSuggest = "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." + 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/" +) // RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info // for the given command. @@ -128,8 +132,10 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword argUser = strings.TrimSpace(argUser) if argUser == "" { if serverAddress == registry.IndexServer { - // if this is a default registry (docker hub), then display the following message. - 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.") + // When signing in to the default (Docker Hub) registry, we display + // hints for creating an account, and (if hints are enabled), using + // a token instead of a password. + _, _ = fmt.Fprintln(cli.Out(), registerSuggest) if hints.Enabled() { fmt.Fprintln(cli.Out(), patSuggest) fmt.Fprintln(cli.Out())