Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2259 from landism/matt/add_current_pat_prefix
Browse files Browse the repository at this point in the history
compose-cli: fix PAT detection for PAT suggestion
  • Loading branch information
milas authored Jul 26, 2023
2 parents 6b231d6 + accd15c commit 118cd6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cli/mobycli/pat_suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ const (
// patSuggestMsg is a message to suggest the use of PAT (personal access tokens).
patSuggestMsg = `Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/`
)

// patPrefix represents a docker personal access token prefix.
patPrefix = "dckrp_"
var (
patPrefixes = []string{"dckrp_", "dckr_pat_"}
)

// displayPATSuggestMsg displays a message suggesting users to use PATs instead of passwords to reduce scope.
Expand Down Expand Up @@ -71,8 +72,10 @@ func isUsingPassword(pass string) bool {
if _, err := uuid.ParseUUID(pass); err == nil {
return false
}
if strings.HasPrefix(pass, patPrefix) {
return false
for _, patPrefix := range patPrefixes {
if strings.HasPrefix(pass, patPrefix) {
return false
}
}
return true
}
5 changes: 5 additions & 0 deletions cli/mobycli/pat_suggest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func TestIsUsingPassword(t *testing.T) {
"dckrp_ee5607c41bcd",
false,
},
{
"prefixed personal access token",
"dckr_pat_ee5607c41bcd",
false,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
Expand Down

0 comments on commit 118cd6d

Please sign in to comment.