Remove forked reference package. Use normalized named values
everywhere and familiar functions to convert back to familiar
strings for UX and storage compatibility.
Enforce that the source repository in the distribution metadata
is always a normalized string, ignore invalid values which are not.
Update distribution tests to use normalized values.
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
Upstream-commit: 635d686a88
Component: cli
71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package plugin
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
"github.com/docker/distribution/reference"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/cli/command"
|
|
"github.com/docker/docker/cli/command/image"
|
|
"github.com/docker/docker/pkg/jsonmessage"
|
|
"github.com/docker/docker/registry"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newPushCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "push [OPTIONS] PLUGIN[:TAG]",
|
|
Short: "Push a plugin to a registry",
|
|
Args: cli.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
return runPush(dockerCli, args[0])
|
|
},
|
|
}
|
|
|
|
flags := cmd.Flags()
|
|
|
|
command.AddTrustSigningFlags(flags)
|
|
|
|
return cmd
|
|
}
|
|
|
|
func runPush(dockerCli *command.DockerCli, name string) error {
|
|
named, err := reference.ParseNormalizedNamed(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, ok := named.(reference.Canonical); ok {
|
|
return fmt.Errorf("invalid name: %s", name)
|
|
}
|
|
|
|
named = reference.TagNameOnly(named)
|
|
|
|
ctx := context.Background()
|
|
|
|
repoInfo, err := registry.ParseRepositoryInfo(named)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index)
|
|
|
|
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
responseBody, err := dockerCli.Client().PluginPush(ctx, reference.FamiliarString(named), encodedAuth)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer responseBody.Close()
|
|
|
|
if command.IsTrusted() {
|
|
repoInfo.Class = "plugin"
|
|
return image.PushTrustedReference(dockerCli, repoInfo, named, authConfig, responseBody)
|
|
}
|
|
|
|
return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil)
|
|
}
|