Skip to content

Commit 6c643bc

Browse files
committed
lookup auth-config without depending on RepositoryInfo
Simplify how we lookup auth-config, as we don't need the additional information provided by RepositoryInfo. There's still more layers to peel off, which will be done in follow-ups. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a18dae0 commit 6c643bc

5 files changed

Lines changed: 18 additions & 16 deletions

File tree

daemon/containerd/image_builder.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import (
3434
"github.com/docker/docker/pkg/progress"
3535
"github.com/docker/docker/pkg/streamformatter"
3636
"github.com/docker/docker/pkg/stringid"
37-
registrypkg "github.com/docker/docker/registry"
3837
imagespec "github.com/moby/docker-image-spec/specs-go/v1"
3938
"github.com/opencontainers/go-digest"
4039
"github.com/opencontainers/image-spec/identity"
@@ -144,12 +143,7 @@ func (i *ImageService) pullForBuilder(ctx context.Context, name string, authConf
144143
pullRegistryAuth := &registry.AuthConfig{}
145144
if len(authConfigs) > 0 {
146145
// The request came with a full auth config, use it
147-
repoInfo, err := i.registryService.ResolveRepository(ref)
148-
if err != nil {
149-
return nil, err
150-
}
151-
152-
resolvedConfig := registrypkg.ResolveAuthConfig(authConfigs, repoInfo.Index)
146+
resolvedConfig := i.registryService.ResolveAuthConfig(authConfigs, ref)
153147
pullRegistryAuth = &resolvedConfig
154148
}
155149

daemon/containerd/service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/containerd/log"
1616
"github.com/containerd/platforms"
1717
"github.com/distribution/reference"
18+
registrytypes "github.com/docker/docker/api/types/registry"
1819
"github.com/docker/docker/container"
1920
daemonevents "github.com/docker/docker/daemon/events"
2021
dimages "github.com/docker/docker/daemon/images"
@@ -45,7 +46,7 @@ type ImageService struct {
4546
}
4647

4748
type registryResolver interface {
48-
ResolveRepository(name reference.Named) (*registry.RepositoryInfo, error)
49+
ResolveAuthConfig(map[string]registrytypes.AuthConfig, reference.Named) registrytypes.AuthConfig
4950
LookupPullEndpoints(hostname string) ([]registry.APIEndpoint, error)
5051
LookupPushEndpoints(hostname string) ([]registry.APIEndpoint, error)
5152
}

daemon/images/image_builder.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/docker/docker/pkg/progress"
1919
"github.com/docker/docker/pkg/streamformatter"
2020
"github.com/docker/docker/pkg/stringid"
21-
registrypkg "github.com/docker/docker/registry"
2221
"github.com/opencontainers/go-digest"
2322
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2423
"github.com/pkg/errors"
@@ -158,12 +157,7 @@ func (i *ImageService) pullForBuilder(ctx context.Context, name string, authConf
158157
pullRegistryAuth := &registry.AuthConfig{}
159158
if len(authConfigs) > 0 {
160159
// The request came with a full auth config, use it
161-
repoInfo, err := i.registryService.ResolveRepository(ref)
162-
if err != nil {
163-
return nil, err
164-
}
165-
166-
resolvedConfig := registrypkg.ResolveAuthConfig(authConfigs, repoInfo.Index)
160+
resolvedConfig := i.registryService.ResolveAuthConfig(authConfigs, ref)
167161
pullRegistryAuth = &resolvedConfig
168162
}
169163

distribution/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ type ImagePushConfig struct {
7878

7979
// RegistryResolver is used for TLS configuration and endpoint lookup.
8080
type RegistryResolver interface {
81+
ResolveAuthConfig(map[string]registry.AuthConfig, reference.Named) registry.AuthConfig
8182
LookupPushEndpoints(hostname string) (endpoints []registrypkg.APIEndpoint, err error)
8283
LookupPullEndpoints(hostname string) (endpoints []registrypkg.APIEndpoint, err error)
83-
ResolveRepository(name reference.Named) (*registrypkg.RepositoryInfo, error)
8484
}
8585

8686
// ImageConfigStore handles storing and getting image configurations

registry/service.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,26 @@ func (s *Service) Auth(ctx context.Context, authConfig *registry.AuthConfig, use
103103

104104
// ResolveRepository splits a repository name into its components
105105
// and configuration of the associated registry.
106+
//
107+
// Deprecated: this function was only used internally and is no longer used. It will be removed in the next release.
106108
func (s *Service) ResolveRepository(name reference.Named) (*RepositoryInfo, error) {
107109
s.mu.RLock()
108110
defer s.mu.RUnlock()
109111
// TODO(thaJeztah): remove error return as it's no longer used.
110112
return newRepositoryInfo(s.config, name), nil
111113
}
112114

115+
// ResolveAuthConfig looks up authentication for the given reference from the
116+
// given authConfigs.
117+
//
118+
// IMPORTANT: This function is for internal use and should not be used by external projects.
119+
func (s *Service) ResolveAuthConfig(authConfigs map[string]registry.AuthConfig, ref reference.Named) registry.AuthConfig {
120+
s.mu.RLock()
121+
defer s.mu.RUnlock()
122+
registryInfo := newIndexInfo(s.config, reference.Domain(ref))
123+
return ResolveAuthConfig(authConfigs, registryInfo)
124+
}
125+
113126
// APIEndpoint represents a remote API endpoint
114127
type APIEndpoint struct {
115128
Mirror bool

0 commit comments

Comments
 (0)