github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/plugin/push.go (about) 1 package plugin 2 3 import ( 4 "context" 5 6 "github.com/distribution/reference" 7 "github.com/docker/cli/cli" 8 "github.com/docker/cli/cli/command" 9 "github.com/docker/cli/cli/command/image" 10 registrytypes "github.com/docker/docker/api/types/registry" 11 "github.com/docker/docker/pkg/jsonmessage" 12 "github.com/docker/docker/registry" 13 "github.com/pkg/errors" 14 "github.com/spf13/cobra" 15 ) 16 17 type pushOptions struct { 18 name string 19 untrusted bool 20 } 21 22 func newPushCommand(dockerCli command.Cli) *cobra.Command { 23 var opts pushOptions 24 cmd := &cobra.Command{ 25 Use: "push [OPTIONS] PLUGIN[:TAG]", 26 Short: "Push a plugin to a registry", 27 Args: cli.ExactArgs(1), 28 RunE: func(cmd *cobra.Command, args []string) error { 29 opts.name = args[0] 30 return runPush(cmd.Context(), dockerCli, opts) 31 }, 32 } 33 34 flags := cmd.Flags() 35 36 command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled()) 37 38 return cmd 39 } 40 41 func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error { 42 named, err := reference.ParseNormalizedNamed(opts.name) 43 if err != nil { 44 return err 45 } 46 if _, ok := named.(reference.Canonical); ok { 47 return errors.Errorf("invalid name: %s", opts.name) 48 } 49 50 named = reference.TagNameOnly(named) 51 52 repoInfo, err := registry.ParseRepositoryInfo(named) 53 if err != nil { 54 return err 55 } 56 authConfig := command.ResolveAuthConfig(dockerCli.ConfigFile(), repoInfo.Index) 57 encodedAuth, err := registrytypes.EncodeAuthConfig(authConfig) 58 if err != nil { 59 return err 60 } 61 62 responseBody, err := dockerCli.Client().PluginPush(ctx, reference.FamiliarString(named), encodedAuth) 63 if err != nil { 64 return err 65 } 66 defer responseBody.Close() 67 68 if !opts.untrusted { 69 return image.PushTrustedReference(dockerCli, repoInfo, named, authConfig, responseBody) 70 } 71 72 return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) 73 }