Skip to content

Commit 3dbf1af

Browse files
authored
Merge pull request #4478 from rumpl/feat-pat-suggest
login: Add message about using PATs
2 parents 9bd5ec5 + 8d51f36 commit 3dbf1af

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

cli/command/registry.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/docker/cli/cli/config/configfile"
1212
configtypes "github.com/docker/cli/cli/config/types"
13+
"github.com/docker/cli/cli/hints"
1314
"github.com/docker/cli/cli/streams"
1415
"github.com/docker/distribution/reference"
1516
"github.com/docker/docker/api/types"
@@ -19,6 +20,10 @@ import (
1920
"github.com/pkg/errors"
2021
)
2122

23+
const patSuggest = "You can log in with your password or a Personal Access " +
24+
"Token (PAT). Using a limited-scope PAT grants better security and is required " +
25+
"for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/"
26+
2227
// RegistryAuthenticationPrivilegedFunc returns a RequestPrivilegeFunc from the specified registry index info
2328
// for the given command.
2429
func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInfo, cmdName string) types.RequestPrivilegeFunc {
@@ -105,7 +110,11 @@ func ConfigureAuth(cli Cli, flUser, flPassword string, authconfig *registrytypes
105110
if flUser = strings.TrimSpace(flUser); flUser == "" {
106111
if isDefaultRegistry {
107112
// if this is a default registry (docker hub), then display the following message.
108-
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.")
113+
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.")
114+
if hints.Enabled() {
115+
fmt.Fprintln(cli.Out(), patSuggest)
116+
fmt.Fprintln(cli.Out())
117+
}
109118
}
110119
promptWithDefault(cli.Out(), "Username", authconfig.Username)
111120
var err error

cli/hints/hints.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package hints
2+
3+
import (
4+
"os"
5+
"strconv"
6+
)
7+
8+
// Enabled returns whether cli hints are enabled or not
9+
func Enabled() bool {
10+
if v := os.Getenv("DOCKER_CLI_HINTS"); v != "" {
11+
enabled, err := strconv.ParseBool(v)
12+
if err != nil {
13+
return true
14+
}
15+
return enabled
16+
}
17+
return true
18+
}

0 commit comments

Comments
 (0)