2016-05-16 11:50:55 -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-05-16 11:50:55 -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-05-16 11:50:55 -04:00
|
|
|
cmd := &cobra.Command{
|
2016-06-17 12:14:23 -04:00
|
|
|
Use: "push PLUGIN",
|
2016-05-16 11:50:55 -04:00
|
|
|
Short: "Push a plugin",
|
|
|
|
Args: cli.ExactArgs(1),
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return runPush(dockerCli, args[0])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2016-09-08 14:54:01 -04:00
|
|
|
func runPush(dockerCli *command.DockerCli, name string) error {
|
2016-05-16 11:50:55 -04:00
|
|
|
named, err := reference.ParseNamed(name) // FIXME: validate
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-06-17 12:13:24 -04:00
|
|
|
if reference.IsNameOnly(named) {
|
|
|
|
named = reference.WithDefaultTag(named)
|
|
|
|
}
|
2016-05-16 11:50:55 -04: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 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
|
|
|
|
}
|
|
|
|
return dockerCli.Client().PluginPush(ctx, ref.String(), encodedAuth)
|
|
|
|
}
|