2016-05-16 11:50:55 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-01-11 16:54:52 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-05-16 11:50:55 -04:00
|
|
|
"github.com/docker/docker/cli"
|
2016-09-08 14:54:01 -04:00
|
|
|
"github.com/docker/docker/cli/command"
|
2016-12-27 15:51:00 -05:00
|
|
|
"github.com/docker/docker/cli/command/image"
|
2016-12-12 18:05:53 -05:00
|
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
2016-05-16 11:50:55 -04:00
|
|
|
"github.com/docker/docker/registry"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
func newPushCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-05-16 11:50:55 -04:00
|
|
|
cmd := &cobra.Command{
|
2017-01-27 10:17:02 -05:00
|
|
|
Use: "push [OPTIONS] PLUGIN[:TAG]",
|
2016-11-14 11:38:06 -05:00
|
|
|
Short: "Push a plugin to a registry",
|
2016-05-16 11:50:55 -04:00
|
|
|
Args: cli.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runPush(dockerCli, args[0])
|
|
|
|
},
|
|
|
|
}
|
2016-12-27 15:51:00 -05:00
|
|
|
|
|
|
|
flags := cmd.Flags()
|
|
|
|
|
2017-01-17 09:46:07 -05:00
|
|
|
command.AddTrustSigningFlags(flags)
|
2016-12-27 15:51:00 -05:00
|
|
|
|
2016-05-16 11:50:55 -04:00
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
func runPush(dockerCli *command.DockerCli, name string) error {
|
2017-01-11 16:54:52 -05:00
|
|
|
named, err := reference.ParseNormalizedNamed(name)
|
2016-05-16 11:50:55 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-01-11 16:54:52 -05:00
|
|
|
if _, ok := named.(reference.Canonical); ok {
|
|
|
|
return fmt.Errorf("invalid name: %s", name)
|
2016-06-17 12:13:24 -04:00
|
|
|
}
|
2017-01-11 16:54:52 -05:00
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
named = reference.TagNameOnly(named)
|
2016-05-16 11:50:55 -04:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
repoInfo, err := registry.ParseRepositoryInfo(named)
|
2016-06-29 05:26:42 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-09-09 15:38:00 -04:00
|
|
|
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
|
2016-05-16 11:50:55 -04:00
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
|
2016-05-16 11:50:55 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-01-11 16:54:52 -05:00
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
responseBody, err := dockerCli.Client().PluginPush(ctx, reference.FamiliarString(named), encodedAuth)
|
2016-12-12 18:05:53 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer responseBody.Close()
|
2016-12-27 15:51:00 -05:00
|
|
|
|
|
|
|
if command.IsTrusted() {
|
|
|
|
repoInfo.Class = "plugin"
|
|
|
|
return image.PushTrustedReference(dockerCli, repoInfo, named, authConfig, responseBody)
|
|
|
|
}
|
|
|
|
|
2016-12-12 18:05:53 -05:00
|
|
|
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
|
2016-05-16 11:50:55 -04:00
|
|
|
}
|