Merge pull request #3795 from thaJeztah/ignore_stubs_in_aliases

fix broken alias check is buildx is installed as alias for builder
This commit is contained in:
Sebastiaan van Stijn 2022-09-30 02:24:04 +02:00 committed by GitHub
commit a496a7d501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import (
"os"
"strings"
pluginmanager "github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli/command"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -26,9 +27,11 @@ func processAliases(dockerCli command.Cli, cmd *cobra.Command, args, osArgs []st
if _, ok := allowedAliases[k]; !ok {
return args, osArgs, errors.Errorf("not allowed to alias %q (allowed: %#v)", k, allowedAliases)
}
if _, _, err := cmd.Find(strings.Split(v, " ")); err == nil {
if c, _, err := cmd.Find(strings.Split(v, " ")); err == nil {
if c.Annotations[pluginmanager.CommandAnnotationPlugin] != "true" {
return args, osArgs, errors.Errorf("not allowed to alias with builtin %q as target", v)
}
}
aliases = append(aliases, [2][]string{{k}, {v}})
}

View File

@ -218,12 +218,12 @@ func runDocker(dockerCli *command.DockerCli) error {
return err
}
err = pluginmanager.AddPluginCommandStubs(dockerCli, cmd)
args, os.Args, err = processAliases(dockerCli, cmd, args, os.Args)
if err != nil {
return err
}
args, os.Args, err = processAliases(dockerCli, cmd, args, os.Args)
err = pluginmanager.AddPluginCommandStubs(dockerCli, cmd)
if err != nil {
return err
}