api/server/router: use types/registry.AuthConfig

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-03-03 10:23:18 +01:00
parent 818ee96219
commit d8a43399a8
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
9 changed files with 34 additions and 32 deletions

View File

@ -19,6 +19,7 @@ import (
"github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters" "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/api/types/versions"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
@ -296,8 +297,8 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
return nil return nil
} }
func getAuthConfigs(header http.Header) map[string]types.AuthConfig { func getAuthConfigs(header http.Header) map[string]registry.AuthConfig {
authConfigs := map[string]types.AuthConfig{} authConfigs := map[string]registry.AuthConfig{}
authConfigsEncoded := header.Get("X-Registry-Config") authConfigsEncoded := header.Get("X-Registry-Config")
if authConfigsEncoded == "" { if authConfigsEncoded == "" {

View File

@ -5,11 +5,11 @@ import (
"github.com/docker/distribution" "github.com/docker/distribution"
"github.com/docker/distribution/reference" "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 // Backend is all the methods that need to be implemented
// to provide image specific functionality. // to provide image specific functionality.
type Backend interface { type Backend interface {
GetRepository(context.Context, reference.Named, *types.AuthConfig) (distribution.Repository, error) GetRepository(context.Context, reference.Named, *registry.AuthConfig) (distribution.Repository, error)
} }

View File

@ -12,7 +12,6 @@ import (
"github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/manifest/schema2"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
"github.com/docker/docker/api/server/httputils" "github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs" "github.com/docker/docker/errdefs"
v1 "github.com/opencontainers/image-spec/specs-go/v1" 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") w.Header().Set("Content-Type", "application/json")
var ( var (
config = &types.AuthConfig{} config = &registry.AuthConfig{}
authEncoded = r.Header.Get(registry.AuthHeader) authEncoded = r.Header.Get(registry.AuthHeader)
distributionInspect registry.DistributionInspect 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 { if err := json.NewDecoder(authJSON).Decode(&config); err != nil {
// for a search it is not an error if no auth was given // 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 // to increase compatibility with the existing api it is defaulting to be empty
config = &types.AuthConfig{} config = &registry.AuthConfig{}
} }
} }

View File

@ -36,7 +36,7 @@ type importExportBackend interface {
} }
type registryBackend 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 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 *types.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 *types.AuthConfig, metaHeaders map[string][]string) (*registry.SearchResults, error) SearchRegistryForImages(ctx context.Context, searchFilters filters.Args, term string, limit int, authConfig *registry.AuthConfig, metaHeaders map[string][]string) (*registry.SearchResults, error)
} }

View File

@ -65,13 +65,13 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
} }
authEncoded := r.Header.Get(registry.AuthHeader) authEncoded := r.Header.Get(registry.AuthHeader)
authConfig := &types.AuthConfig{} authConfig := &registry.AuthConfig{}
if authEncoded != "" { if authEncoded != "" {
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
// for a pull it is not an error if no auth was given // 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 // to increase compatibility with the existing api it is defaulting to be empty
authConfig = &types.AuthConfig{} authConfig = &registry.AuthConfig{}
} }
} }
progressErr = s.backend.PullImage(ctx, image, tag, platform, metaHeaders, authConfig, output) 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 { if err := httputils.ParseForm(r); err != nil {
return err return err
} }
authConfig := &types.AuthConfig{} authConfig := &registry.AuthConfig{}
authEncoded := r.Header.Get(registry.AuthHeader) authEncoded := r.Header.Get(registry.AuthHeader)
if authEncoded != "" { if authEncoded != "" {
@ -107,7 +107,7 @@ func (s *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter,
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
// to increase compatibility to existing api it is defaulting to be empty // to increase compatibility to existing api it is defaulting to be empty
authConfig = &types.AuthConfig{} authConfig = &registry.AuthConfig{}
} }
} else { } else {
// the old format is supported for compatibility if there was no authConfig header // 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 return err
} }
var ( var (
config *types.AuthConfig config *registry.AuthConfig
authEncoded = r.Header.Get(registry.AuthHeader) authEncoded = r.Header.Get(registry.AuthHeader)
headers = map[string][]string{} 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 { if err := json.NewDecoder(authJSON).Decode(&config); err != nil {
// for a search it is not an error if no auth was given // 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 // to increase compatibility with the existing api it is defaulting to be empty
config = &types.AuthConfig{} config = &registry.AuthConfig{}
} }
} }
for k, v := range r.Header { for k, v := range r.Header {

View File

@ -6,22 +6,23 @@ import (
"net/http" "net/http"
"github.com/docker/distribution/reference" "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/filters"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/plugin" "github.com/docker/docker/plugin"
) )
// Backend for Plugin // Backend for Plugin
type Backend interface { type Backend interface {
Disable(name string, config *enginetypes.PluginDisableConfig) error Disable(name string, config *types.PluginDisableConfig) error
Enable(name string, config *enginetypes.PluginEnableConfig) error Enable(name string, config *types.PluginEnableConfig) error
List(filters.Args) ([]enginetypes.Plugin, error) List(filters.Args) ([]types.Plugin, error)
Inspect(name string) (*enginetypes.Plugin, error) Inspect(name string) (*types.Plugin, error)
Remove(name string, config *enginetypes.PluginRmConfig) error Remove(name string, config *types.PluginRmConfig) error
Set(name string, args []string) error Set(name string, args []string) error
Privileges(ctx context.Context, ref reference.Named, metaHeaders http.Header, authConfig *enginetypes.AuthConfig) (enginetypes.PluginPrivileges, 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 *enginetypes.AuthConfig, privileges enginetypes.PluginPrivileges, outStream io.Writer, opts ...plugin.CreateOpt) 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 *enginetypes.AuthConfig, outStream io.Writer) 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 *enginetypes.AuthConfig, privileges enginetypes.PluginPrivileges, 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 *enginetypes.PluginCreateOptions) error CreateFromContext(ctx context.Context, tarCtx io.ReadCloser, options *types.PluginCreateOptions) error
} }

View File

@ -17,7 +17,7 @@ import (
"github.com/pkg/errors" "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{} metaHeaders := map[string][]string{}
for k, v := range headers { for k, v := range headers {
@ -28,11 +28,11 @@ func parseHeaders(headers http.Header) (map[string][]string, *types.AuthConfig)
// Get X-Registry-Auth // Get X-Registry-Auth
authEncoded := headers.Get(registry.AuthHeader) authEncoded := headers.Get(registry.AuthHeader)
authConfig := &types.AuthConfig{} authConfig := &registry.AuthConfig{}
if authEncoded != "" { if authEncoded != "" {
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded)) authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil { if err := json.NewDecoder(authJSON).Decode(authConfig); err != nil {
authConfig = &types.AuthConfig{} authConfig = &registry.AuthConfig{}
} }
} }

View File

@ -7,6 +7,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
) )
@ -30,7 +31,7 @@ type Backend interface {
SystemDiskUsage(ctx context.Context, opts DiskUsageOptions) (*types.DiskUsage, error) SystemDiskUsage(ctx context.Context, opts DiskUsageOptions) (*types.DiskUsage, error)
SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{}) SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{})
UnsubscribeFromEvents(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 // ClusterBackend is all the methods that need to be implemented

View File

@ -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 { 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) err := json.NewDecoder(r.Body).Decode(&config)
r.Body.Close() r.Body.Close()
if err != nil { if err != nil {