зеркало из https://github.com/docker/compose-cli.git
Merge pull request #2259 from landism/matt/add_current_pat_prefix
compose-cli: fix PAT detection for PAT suggestion
This commit is contained in:
Коммит
118cd6dd75
|
@ -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.
|
||||
|
@ -71,8 +72,10 @@ func isUsingPassword(pass string) bool {
|
|||
if _, err := uuid.ParseUUID(pass); err == nil {
|
||||
return false
|
||||
}
|
||||
for _, patPrefix := range patPrefixes {
|
||||
if strings.HasPrefix(pass, patPrefix) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче