diff --git a/api/client/plugin/install.go b/api/client/plugin/install.go index ef890b1f90..486dc4f622 100644 --- a/api/client/plugin/install.go +++ b/api/client/plugin/install.go @@ -3,12 +3,15 @@ package plugin import ( + "bufio" "fmt" + "strings" "github.com/docker/docker/api/client" "github.com/docker/docker/cli" "github.com/docker/docker/reference" "github.com/docker/docker/registry" + "github.com/docker/engine-api/types" "github.com/spf13/cobra" "golang.org/x/net/context" ) @@ -36,8 +39,8 @@ func newInstallCommand(dockerCli *client.DockerCli) *cobra.Command { return cmd } -func runInstall(dockerCli *client.DockerCli, options pluginOptions) error { - named, err := reference.ParseNamed(options.name) // FIXME: validate +func runInstall(dockerCli *client.DockerCli, opts pluginOptions) error { + named, err := reference.ParseNamed(opts.name) // FIXME: validate if err != nil { return err } @@ -56,6 +59,34 @@ func runInstall(dockerCli *client.DockerCli, options pluginOptions) error { if err != nil { return err } - // TODO: pass noEnable flag - return dockerCli.Client().PluginInstall(ctx, ref.String(), encodedAuth, options.grantPerms, false, dockerCli.In(), dockerCli.Out()) + + requestPrivilege := dockerCli.RegistryAuthenticationPrivilegedFunc(repoInfo.Index, "plugin install") + + // TODO: pass acceptAllPermissions and noEnable flag + options := types.PluginInstallOptions{ + RegistryAuth: encodedAuth, + Disabled: false, + AcceptAllPermissions: opts.grantPerms, + AcceptPermissionsFunc: acceptPrivileges(dockerCli, opts.name), + PrivilegeFunc: requestPrivilege, + } + + return dockerCli.Client().PluginInstall(ctx, ref.String(), options) +} + +func acceptPrivileges(dockerCli *client.DockerCli, name string) func(privileges types.PluginPrivileges) (bool, error) { + return func(privileges types.PluginPrivileges) (bool, error) { + fmt.Fprintf(dockerCli.Out(), "Plugin %q requested the following privileges:\n", name) + for _, privilege := range privileges { + fmt.Fprintf(dockerCli.Out(), " - %s: %v\n", privilege.Name, privilege.Value) + } + + fmt.Fprint(dockerCli.Out(), "Do you grant the above permissions? [y/N] ") + reader := bufio.NewReader(dockerCli.In()) + line, _, err := reader.ReadLine() + if err != nil { + return false, err + } + return strings.ToLower(string(line)) == "y", nil + } }