github.com/kunnos/engine@v1.13.1/cli/command/plugin/push.go (about) 1 package plugin 2 3 import ( 4 "fmt" 5 6 "golang.org/x/net/context" 7 8 "github.com/docker/docker/cli" 9 "github.com/docker/docker/cli/command" 10 "github.com/docker/docker/cli/command/image" 11 "github.com/docker/docker/pkg/jsonmessage" 12 "github.com/docker/docker/reference" 13 "github.com/docker/docker/registry" 14 "github.com/spf13/cobra" 15 ) 16 17 func newPushCommand(dockerCli *command.DockerCli) *cobra.Command { 18 cmd := &cobra.Command{ 19 Use: "push [OPTIONS] PLUGIN[:TAG]", 20 Short: "Push a plugin to a registry", 21 Args: cli.ExactArgs(1), 22 RunE: func(cmd *cobra.Command, args []string) error { 23 return runPush(dockerCli, args[0]) 24 }, 25 } 26 27 flags := cmd.Flags() 28 29 command.AddTrustedFlags(flags, true) 30 31 return cmd 32 } 33 34 func runPush(dockerCli *command.DockerCli, name string) error { 35 named, err := reference.ParseNamed(name) // FIXME: validate 36 if err != nil { 37 return err 38 } 39 if reference.IsNameOnly(named) { 40 named = reference.WithDefaultTag(named) 41 } 42 ref, ok := named.(reference.NamedTagged) 43 if !ok { 44 return fmt.Errorf("invalid name: %s", named.String()) 45 } 46 47 ctx := context.Background() 48 49 repoInfo, err := registry.ParseRepositoryInfo(named) 50 if err != nil { 51 return err 52 } 53 authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index) 54 55 encodedAuth, err := command.EncodeAuthToBase64(authConfig) 56 if err != nil { 57 return err 58 } 59 responseBody, err := dockerCli.Client().PluginPush(ctx, ref.String(), encodedAuth) 60 if err != nil { 61 return err 62 } 63 defer responseBody.Close() 64 65 if command.IsTrusted() { 66 repoInfo.Class = "plugin" 67 return image.PushTrustedReference(dockerCli, repoInfo, named, authConfig, responseBody) 68 } 69 70 return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) 71 }