2016-09-08 13:11:39 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2017-01-11 16:54:52 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-09-08 13:11:39 -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-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/registry"
|
2017-03-09 13:23:45 -05:00
|
|
|
"github.com/pkg/errors"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
func newPushCommand(dockerCli *command.DockerCli) *cobra.Command {
|
2016-09-08 13:11:39 -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-09-08 13:11:39 -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-09-08 13:11:39 -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-09-08 13:11:39 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-01-11 16:54:52 -05:00
|
|
|
if _, ok := named.(reference.Canonical); ok {
|
2017-03-09 13:23:45 -05:00
|
|
|
return errors.Errorf("invalid name: %s", name)
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
2017-01-11 16:54:52 -05:00
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
named = reference.TagNameOnly(named)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
repoInfo, err := registry.ParseRepositoryInfo(named)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-09-09 15:38:00 -04:00
|
|
|
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
|
2016-09-08 13:11:39 -04:00
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
|
2016-09-08 13:11:39 -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-09-08 13:11:39 -04:00
|
|
|
}
|