2016-09-08 13:11:39 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
"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/reference"
|
|
|
|
"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-09-08 13:11:39 -04:00
|
|
|
cmd := &cobra.Command{
|
2016-11-25 06:46:24 -05:00
|
|
|
Use: "push 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 {
|
2016-09-08 13:11:39 -04:00
|
|
|
named, err := reference.ParseNamed(name) // FIXME: validate
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if reference.IsNameOnly(named) {
|
|
|
|
named = reference.WithDefaultTag(named)
|
|
|
|
}
|
|
|
|
ref, ok := named.(reference.NamedTagged)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid name: %s", named.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2016-12-12 18:05:53 -05:00
|
|
|
responseBody, err := dockerCli.Client().PluginPush(ctx, ref.String(), encodedAuth)
|
|
|
|
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
|
|
|
}
|