2016-05-16 15:50:55 +00:00
|
|
|
// +build experimental
|
|
|
|
|
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/client"
|
|
|
|
"github.com/docker/docker/cli"
|
|
|
|
"github.com/docker/docker/reference"
|
|
|
|
"github.com/docker/docker/registry"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newPushCommand(dockerCli *client.DockerCli) *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
2016-06-17 16:14:23 +00:00
|
|
|
Use: "push PLUGIN",
|
2016-05-16 15:50:55 +00:00
|
|
|
Short: "Push a plugin",
|
|
|
|
Args: cli.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runPush(dockerCli, args[0])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func runPush(dockerCli *client.DockerCli, name string) error {
|
|
|
|
named, err := reference.ParseNamed(name) // FIXME: validate
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-06-17 16:13:24 +00:00
|
|
|
if reference.IsNameOnly(named) {
|
|
|
|
named = reference.WithDefaultTag(named)
|
|
|
|
}
|
2016-05-16 15:50:55 +00:00
|
|
|
ref, ok := named.(reference.NamedTagged)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid name: %s", named.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
repoInfo, err := registry.ParseRepositoryInfo(named)
|
2016-06-29 09:26:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-16 15:50:55 +00:00
|
|
|
authConfig := dockerCli.ResolveAuthConfig(ctx, repoInfo.Index)
|
|
|
|
|
|
|
|
encodedAuth, err := client.EncodeAuthToBase64(authConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return dockerCli.Client().PluginPush(ctx, ref.String(), encodedAuth)
|
|
|
|
}
|