From 55d1a5682638eb0d28eb52409802a2572177794b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 3 Mar 2022 10:31:58 +0100 Subject: [PATCH] plugin: use types/registry.AuthConfig Signed-off-by: Sebastiaan van Stijn --- api/server/router/plugin/plugin_routes.go | 1 + plugin/backend_linux.go | 15 ++++++++------- plugin/backend_unsupported.go | 9 +++++---- plugin/fetch_linux.go | 4 ++-- plugin/registry.go | 6 +++--- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/api/server/router/plugin/plugin_routes.go b/api/server/router/plugin/plugin_routes.go index 66e6c6d553..87035b93cd 100644 --- a/api/server/router/plugin/plugin_routes.go +++ b/api/server/router/plugin/plugin_routes.go @@ -12,6 +12,7 @@ import ( "github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/streamformatter" "github.com/pkg/errors" diff --git a/plugin/backend_linux.go b/plugin/backend_linux.go index be1cf73c31..9c873ae446 100644 --- a/plugin/backend_linux.go +++ b/plugin/backend_linux.go @@ -23,6 +23,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/dockerversion" "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/authorization" @@ -121,12 +122,12 @@ func computePrivileges(c types.PluginConfig) types.PluginPrivileges { Value: []string{"true"}, }) } - for _, mount := range c.Mounts { - if mount.Source != nil { + for _, mnt := range c.Mounts { + if mnt.Source != nil { privileges = append(privileges, types.PluginPrivilege{ Name: "mount", Description: "host path to mount", - Value: []string{*mount.Source}, + Value: []string{*mnt.Source}, }) } } @@ -158,7 +159,7 @@ func computePrivileges(c types.PluginConfig) types.PluginPrivileges { } // Privileges pulls a plugin config and computes the privileges required to install it. -func (pm *Manager) Privileges(ctx context.Context, ref reference.Named, metaHeader http.Header, authConfig *types.AuthConfig) (types.PluginPrivileges, error) { +func (pm *Manager) Privileges(ctx context.Context, ref reference.Named, metaHeader http.Header, authConfig *registry.AuthConfig) (types.PluginPrivileges, error) { var ( config types.PluginConfig configSeen bool @@ -206,7 +207,7 @@ func (pm *Manager) Privileges(ctx context.Context, ref reference.Named, metaHead // Upgrade upgrades a plugin // // TODO: replace reference package usage with simpler url.Parse semantics -func (pm *Manager) Upgrade(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *types.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) (err error) { +func (pm *Manager) Upgrade(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *registry.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) (err error) { p, err := pm.config.Store.GetV2Plugin(name) if err != nil { return err @@ -254,7 +255,7 @@ func (pm *Manager) Upgrade(ctx context.Context, ref reference.Named, name string // Pull pulls a plugin, check if the correct privileges are provided and install the plugin. // // TODO: replace reference package usage with simpler url.Parse semantics -func (pm *Manager) Pull(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *types.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer, opts ...CreateOpt) (err error) { +func (pm *Manager) Pull(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *registry.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer, opts ...CreateOpt) (err error) { pm.muGC.RLock() defer pm.muGC.RUnlock() @@ -350,7 +351,7 @@ next: } // Push pushes a plugin to the registry. -func (pm *Manager) Push(ctx context.Context, name string, metaHeader http.Header, authConfig *types.AuthConfig, outStream io.Writer) error { +func (pm *Manager) Push(ctx context.Context, name string, metaHeader http.Header, authConfig *registry.AuthConfig, outStream io.Writer) error { p, err := pm.config.Store.GetV2Plugin(name) if err != nil { return err diff --git a/plugin/backend_unsupported.go b/plugin/backend_unsupported.go index 98d35c1dfa..06422356e2 100644 --- a/plugin/backend_unsupported.go +++ b/plugin/backend_unsupported.go @@ -12,6 +12,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/registry" ) var errNotSupported = errors.New("plugins are not supported on this platform") @@ -32,17 +33,17 @@ func (pm *Manager) Inspect(refOrID string) (tp *types.Plugin, err error) { } // Privileges pulls a plugin config and computes the privileges required to install it. -func (pm *Manager) Privileges(ctx context.Context, ref reference.Named, metaHeader http.Header, authConfig *types.AuthConfig) (types.PluginPrivileges, error) { +func (pm *Manager) Privileges(ctx context.Context, ref reference.Named, metaHeader http.Header, authConfig *registry.AuthConfig) (types.PluginPrivileges, error) { return nil, errNotSupported } // Pull pulls a plugin, check if the correct privileges are provided and install the plugin. -func (pm *Manager) Pull(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *types.AuthConfig, privileges types.PluginPrivileges, out io.Writer, opts ...CreateOpt) error { +func (pm *Manager) Pull(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *registry.AuthConfig, privileges types.PluginPrivileges, out io.Writer, opts ...CreateOpt) error { return errNotSupported } // Upgrade pulls a plugin, check if the correct privileges are provided and install the plugin. -func (pm *Manager) Upgrade(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *types.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) error { +func (pm *Manager) Upgrade(ctx context.Context, ref reference.Named, name string, metaHeader http.Header, authConfig *registry.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) error { return errNotSupported } @@ -52,7 +53,7 @@ func (pm *Manager) List(pluginFilters filters.Args) ([]types.Plugin, error) { } // Push pushes a plugin to the store. -func (pm *Manager) Push(ctx context.Context, name string, metaHeader http.Header, authConfig *types.AuthConfig, out io.Writer) error { +func (pm *Manager) Push(ctx context.Context, name string, metaHeader http.Header, authConfig *registry.AuthConfig, out io.Writer) error { return errNotSupported } diff --git a/plugin/fetch_linux.go b/plugin/fetch_linux.go index fe00e88874..b05881fb16 100644 --- a/plugin/fetch_linux.go +++ b/plugin/fetch_linux.go @@ -12,7 +12,7 @@ import ( "github.com/containerd/containerd/remotes" "github.com/containerd/containerd/remotes/docker" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/registry" progressutils "github.com/docker/docker/distribution/utils" "github.com/docker/docker/pkg/chrootarchive" "github.com/docker/docker/pkg/ioutils" @@ -59,7 +59,7 @@ func setupProgressOutput(outStream io.Writer, cancel func()) (progress.Output, f // fetch the content related to the passed in reference into the blob store and appends the provided images.Handlers // There is no need to use remotes.FetchHandler since it already gets set -func (pm *Manager) fetch(ctx context.Context, ref reference.Named, auth *types.AuthConfig, out progress.Output, metaHeader http.Header, handlers ...images.Handler) (err error) { +func (pm *Manager) fetch(ctx context.Context, ref reference.Named, auth *registry.AuthConfig, out progress.Output, metaHeader http.Header, handlers ...images.Handler) (err error) { // We need to make sure we have a domain on the reference withDomain, err := reference.ParseNormalizedNamed(ref.String()) if err != nil { diff --git a/plugin/registry.go b/plugin/registry.go index e7643b6aaf..d4e8a55e0b 100644 --- a/plugin/registry.go +++ b/plugin/registry.go @@ -10,7 +10,7 @@ import ( "github.com/containerd/containerd/remotes" "github.com/containerd/containerd/remotes/docker" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/dockerversion" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -27,7 +27,7 @@ func scope(ref reference.Named, push bool) string { return scope } -func (pm *Manager) newResolver(ctx context.Context, tracker docker.StatusTracker, auth *types.AuthConfig, headers http.Header, httpFallback bool) (remotes.Resolver, error) { +func (pm *Manager) newResolver(ctx context.Context, tracker docker.StatusTracker, auth *registry.AuthConfig, headers http.Header, httpFallback bool) (remotes.Resolver, error) { if headers == nil { headers = http.Header{} } @@ -55,7 +55,7 @@ func registryHTTPClient(config *tls.Config) *http.Client { } } -func (pm *Manager) registryHostsFn(auth *types.AuthConfig, httpFallback bool) docker.RegistryHosts { +func (pm *Manager) registryHostsFn(auth *registry.AuthConfig, httpFallback bool) docker.RegistryHosts { return func(hostname string) ([]docker.RegistryHost, error) { eps, err := pm.config.RegistryService.LookupPullEndpoints(hostname) if err != nil {