login: Remove the PAT message, it's in docker/cli now (#2261)

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
This commit is contained in:
Djordje Lukic 2023-08-02 19:19:03 +02:00 коммит произвёл GitHub
Родитель 118cd6dd75
Коммит d22f3a858a
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 0 добавлений и 29 удалений

Просмотреть файл

@ -117,8 +117,6 @@ func Exec(_ *cobra.Command) {
displayScoutQuickViewSuggestMsgOnBuild(commandArgs) displayScoutQuickViewSuggestMsgOnBuild(commandArgs)
case "pull": case "pull":
displayScoutQuickViewSuggestMsgOnPull(commandArgs) displayScoutQuickViewSuggestMsgOnPull(commandArgs)
case "login":
displayPATSuggestMsg(commandArgs)
default: default:
} }
} }

Просмотреть файл

@ -17,43 +17,16 @@
package mobycli package mobycli
import ( import (
"fmt"
"os"
"strings" "strings"
"github.com/docker/cli/cli/config"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"github.com/hashicorp/go-uuid" "github.com/hashicorp/go-uuid"
) )
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/`
)
var ( var (
patPrefixes = []string{"dckrp_", "dckr_pat_"} patPrefixes = []string{"dckrp_", "dckr_pat_"}
) )
// displayPATSuggestMsg displays a message suggesting users to use PATs instead of passwords to reduce scope.
func displayPATSuggestMsg(cmdArgs []string) {
if os.Getenv("DOCKER_PAT_SUGGEST") == "false" {
return
}
if !isUsingDefaultRegistry(cmdArgs) {
return
}
authCfg, err := config.LoadDefaultConfigFile(os.Stderr).GetAuthConfig(registry.IndexServer)
if err != nil {
return
}
if !isUsingPassword(authCfg.Password) {
return
}
fmt.Fprintf(os.Stderr, "\n"+patSuggestMsg+"\n")
}
func isUsingDefaultRegistry(cmdArgs []string) bool { func isUsingDefaultRegistry(cmdArgs []string) bool {
for i := 1; i < len(cmdArgs); i++ { for i := 1; i < len(cmdArgs); i++ {
if strings.HasPrefix(cmdArgs[i], "-") { if strings.HasPrefix(cmdArgs[i], "-") {