From d8a43399a80586c9b8105111d364637f314c6c02 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 3 Mar 2022 10:23:18 +0100 Subject: [PATCH] api/server/router: use types/registry.AuthConfig Signed-off-by: Sebastiaan van Stijn --- api/server/router/build/build_routes.go | 5 ++-- api/server/router/distribution/backend.go | 4 ++-- .../distribution/distribution_routes.go | 5 ++-- api/server/router/image/backend.go | 6 ++--- api/server/router/image/image_routes.go | 12 +++++----- api/server/router/plugin/backend.go | 23 ++++++++++--------- api/server/router/plugin/plugin_routes.go | 6 ++--- api/server/router/system/backend.go | 3 ++- api/server/router/system/system_routes.go | 2 +- 9 files changed, 34 insertions(+), 32 deletions(-) diff --git a/api/server/router/build/build_routes.go b/api/server/router/build/build_routes.go index 9b57e68963..76bbf4beab 100644 --- a/api/server/router/build/build_routes.go +++ b/api/server/router/build/build_routes.go @@ -19,6 +19,7 @@ import ( "github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" @@ -296,8 +297,8 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r * return nil } -func getAuthConfigs(header http.Header) map[string]types.AuthConfig { - authConfigs := map[string]types.AuthConfig{} +func getAuthConfigs(header http.Header) map[string]registry.AuthConfig { + authConfigs := map[string]registry.AuthConfig{} authConfigsEncoded := header.Get("X-Registry-Config") if authConfigsEncoded == "" { diff --git a/api/server/router/distribution/backend.go b/api/server/router/distribution/backend.go index 6df6ad719a..1adb424872 100644 --- a/api/server/router/distribution/backend.go +++ b/api/server/router/distribution/backend.go @@ -5,11 +5,11 @@ import ( "github.com/docker/distribution" "github.com/docker/distribution/reference" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/registry" ) // Backend is all the methods that need to be implemented // to provide image specific functionality. type Backend interface { - GetRepository(context.Context, reference.Named, *types.AuthConfig) (distribution.Repository, error) + GetRepository(context.Context, reference.Named, *registry.AuthConfig) (distribution.Repository, error) } diff --git a/api/server/router/distribution/distribution_routes.go b/api/server/router/distribution/distribution_routes.go index 48107d1456..9a94cc38a7 100644 --- a/api/server/router/distribution/distribution_routes.go +++ b/api/server/router/distribution/distribution_routes.go @@ -12,7 +12,6 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/reference" "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/errdefs" v1 "github.com/opencontainers/image-spec/specs-go/v1" @@ -27,7 +26,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res w.Header().Set("Content-Type", "application/json") var ( - config = &types.AuthConfig{} + config = ®istry.AuthConfig{} authEncoded = r.Header.Get(registry.AuthHeader) distributionInspect registry.DistributionInspect ) @@ -37,7 +36,7 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res if err := json.NewDecoder(authJSON).Decode(&config); err != nil { // for a search it is not an error if no auth was given // to increase compatibility with the existing api it is defaulting to be empty - config = &types.AuthConfig{} + config = ®istry.AuthConfig{} } } diff --git a/api/server/router/image/backend.go b/api/server/router/image/backend.go index ece336bef4..e81d10d23e 100644 --- a/api/server/router/image/backend.go +++ b/api/server/router/image/backend.go @@ -36,7 +36,7 @@ type importExportBackend interface { } type registryBackend interface { - PullImage(ctx context.Context, image, tag string, platform *specs.Platform, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error - SearchRegistryForImages(ctx context.Context, searchFilters filters.Args, term string, limit int, authConfig *types.AuthConfig, metaHeaders map[string][]string) (*registry.SearchResults, error) + PullImage(ctx context.Context, image, tag string, platform *specs.Platform, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error + PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *registry.AuthConfig, outStream io.Writer) error + SearchRegistryForImages(ctx context.Context, searchFilters filters.Args, term string, limit int, authConfig *registry.AuthConfig, metaHeaders map[string][]string) (*registry.SearchResults, error) } diff --git a/api/server/router/image/image_routes.go b/api/server/router/image/image_routes.go index 1184102cd8..6abcf9c189 100644 --- a/api/server/router/image/image_routes.go +++ b/api/server/router/image/image_routes.go @@ -65,13 +65,13 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite } authEncoded := r.Header.Get(registry.AuthHeader) - authConfig := &types.AuthConfig{} + authConfig := ®istry.AuthConfig{} if authEncoded != "" { authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { // for a pull it is not an error if no auth was given // to increase compatibility with the existing api it is defaulting to be empty - authConfig = &types.AuthConfig{} + authConfig = ®istry.AuthConfig{} } } progressErr = s.backend.PullImage(ctx, image, tag, platform, metaHeaders, authConfig, output) @@ -99,7 +99,7 @@ func (s *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter, if err := httputils.ParseForm(r); err != nil { return err } - authConfig := &types.AuthConfig{} + authConfig := ®istry.AuthConfig{} authEncoded := r.Header.Get(registry.AuthHeader) if authEncoded != "" { @@ -107,7 +107,7 @@ func (s *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter, authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { // to increase compatibility to existing api it is defaulting to be empty - authConfig = &types.AuthConfig{} + authConfig = ®istry.AuthConfig{} } } else { // the old format is supported for compatibility if there was no authConfig header @@ -360,7 +360,7 @@ func (s *imageRouter) getImagesSearch(ctx context.Context, w http.ResponseWriter return err } var ( - config *types.AuthConfig + config *registry.AuthConfig authEncoded = r.Header.Get(registry.AuthHeader) headers = map[string][]string{} ) @@ -370,7 +370,7 @@ func (s *imageRouter) getImagesSearch(ctx context.Context, w http.ResponseWriter if err := json.NewDecoder(authJSON).Decode(&config); err != nil { // for a search it is not an error if no auth was given // to increase compatibility with the existing api it is defaulting to be empty - config = &types.AuthConfig{} + config = ®istry.AuthConfig{} } } for k, v := range r.Header { diff --git a/api/server/router/plugin/backend.go b/api/server/router/plugin/backend.go index d885ebb33a..b62045ff87 100644 --- a/api/server/router/plugin/backend.go +++ b/api/server/router/plugin/backend.go @@ -6,22 +6,23 @@ import ( "net/http" "github.com/docker/distribution/reference" - enginetypes "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/plugin" ) // Backend for Plugin type Backend interface { - Disable(name string, config *enginetypes.PluginDisableConfig) error - Enable(name string, config *enginetypes.PluginEnableConfig) error - List(filters.Args) ([]enginetypes.Plugin, error) - Inspect(name string) (*enginetypes.Plugin, error) - Remove(name string, config *enginetypes.PluginRmConfig) error + Disable(name string, config *types.PluginDisableConfig) error + Enable(name string, config *types.PluginEnableConfig) error + List(filters.Args) ([]types.Plugin, error) + Inspect(name string) (*types.Plugin, error) + Remove(name string, config *types.PluginRmConfig) error Set(name string, args []string) error - Privileges(ctx context.Context, ref reference.Named, metaHeaders http.Header, authConfig *enginetypes.AuthConfig) (enginetypes.PluginPrivileges, error) - Pull(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *enginetypes.AuthConfig, privileges enginetypes.PluginPrivileges, outStream io.Writer, opts ...plugin.CreateOpt) error - Push(ctx context.Context, name string, metaHeaders http.Header, authConfig *enginetypes.AuthConfig, outStream io.Writer) error - Upgrade(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *enginetypes.AuthConfig, privileges enginetypes.PluginPrivileges, outStream io.Writer) error - CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *enginetypes.PluginCreateOptions) error + Privileges(ctx context.Context, ref reference.Named, metaHeaders http.Header, authConfig *registry.AuthConfig) (types.PluginPrivileges, error) + Pull(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *registry.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer, opts ...plugin.CreateOpt) error + Push(ctx context.Context, name string, metaHeaders http.Header, authConfig *registry.AuthConfig, outStream io.Writer) error + Upgrade(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *registry.AuthConfig, privileges types.PluginPrivileges, outStream io.Writer) error + CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) error } diff --git a/api/server/router/plugin/plugin_routes.go b/api/server/router/plugin/plugin_routes.go index 175a0f7537..66e6c6d553 100644 --- a/api/server/router/plugin/plugin_routes.go +++ b/api/server/router/plugin/plugin_routes.go @@ -17,7 +17,7 @@ import ( "github.com/pkg/errors" ) -func parseHeaders(headers http.Header) (map[string][]string, *types.AuthConfig) { +func parseHeaders(headers http.Header) (map[string][]string, *registry.AuthConfig) { metaHeaders := map[string][]string{} for k, v := range headers { @@ -28,11 +28,11 @@ func parseHeaders(headers http.Header) (map[string][]string, *types.AuthConfig) // Get X-Registry-Auth authEncoded := headers.Get(registry.AuthHeader) - authConfig := &types.AuthConfig{} + authConfig := ®istry.AuthConfig{} if authEncoded != "" { authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { - authConfig = &types.AuthConfig{} + authConfig = ®istry.AuthConfig{} } } diff --git a/api/server/router/system/backend.go b/api/server/router/system/backend.go index 940bd4050e..fedb46ffa3 100644 --- a/api/server/router/system/backend.go +++ b/api/server/router/system/backend.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" ) @@ -30,7 +31,7 @@ type Backend interface { SystemDiskUsage(ctx context.Context, opts DiskUsageOptions) (*types.DiskUsage, error) SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{}) UnsubscribeFromEvents(chan interface{}) - AuthenticateToRegistry(ctx context.Context, authConfig *types.AuthConfig) (string, string, error) + AuthenticateToRegistry(ctx context.Context, authConfig *registry.AuthConfig) (string, string, error) } // ClusterBackend is all the methods that need to be implemented diff --git a/api/server/router/system/system_routes.go b/api/server/router/system/system_routes.go index d95b5fc13f..bb7897d229 100644 --- a/api/server/router/system/system_routes.go +++ b/api/server/router/system/system_routes.go @@ -281,7 +281,7 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r * } func (s *systemRouter) postAuth(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - var config *types.AuthConfig + var config *registry.AuthConfig err := json.NewDecoder(r.Body).Decode(&config) r.Body.Close() if err != nil {