registry: un-export DefaultService
The DefaultService was not really meant to be used outside of the package, so un-export it, and change NewService()'s signature to return a Service interface. To un-export this type, a test in daemon/images was updated to not use DefaultService, but now using the registry.Service interface itself. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
541ed077a6
commit
569dc6d692
|
@ -11,16 +11,15 @@ import (
|
||||||
"github.com/docker/docker/registry"
|
"github.com/docker/docker/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeService struct {
|
type fakeService struct {
|
||||||
registry.DefaultService
|
registry.Service
|
||||||
|
|
||||||
shouldReturnError bool
|
shouldReturnError bool
|
||||||
|
|
||||||
term string
|
term string
|
||||||
results []registrytypes.SearchResult
|
results []registrytypes.SearchResult
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FakeService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) {
|
func (s *fakeService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) {
|
||||||
if s.shouldReturnError {
|
if s.shouldReturnError {
|
||||||
return nil, errors.New("Search unknown error")
|
return nil, errors.New("Search unknown error")
|
||||||
}
|
}
|
||||||
|
@ -76,7 +75,7 @@ func TestSearchRegistryForImagesErrors(t *testing.T) {
|
||||||
}
|
}
|
||||||
for index, e := range errorCases {
|
for index, e := range errorCases {
|
||||||
daemon := &ImageService{
|
daemon := &ImageService{
|
||||||
registryService: &FakeService{
|
registryService: &fakeService{
|
||||||
shouldReturnError: e.shouldReturnError,
|
shouldReturnError: e.shouldReturnError,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -322,7 +321,7 @@ func TestSearchRegistryForImages(t *testing.T) {
|
||||||
}
|
}
|
||||||
for index, s := range successCases {
|
for index, s := range successCases {
|
||||||
daemon := &ImageService{
|
daemon := &ImageService{
|
||||||
registryService: &FakeService{
|
registryService: &fakeService{
|
||||||
term: term,
|
term: term,
|
||||||
results: s.registryResults,
|
results: s.registryResults,
|
||||||
},
|
},
|
||||||
|
|
|
@ -519,7 +519,7 @@ func TestMirrorEndpointLookup(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
s := DefaultService{config: cfg}
|
s := defaultService{config: cfg}
|
||||||
|
|
||||||
imageName, err := reference.WithName(IndexName + "/test/image")
|
imageName, err := reference.WithName(IndexName + "/test/image")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -36,23 +36,23 @@ type Service interface {
|
||||||
LoadInsecureRegistries([]string) error
|
LoadInsecureRegistries([]string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultService is a registry service. It tracks configuration data such as a list
|
// defaultService is a registry service. It tracks configuration data such as a list
|
||||||
// of mirrors.
|
// of mirrors.
|
||||||
type DefaultService struct {
|
type defaultService struct {
|
||||||
config *serviceConfig
|
config *serviceConfig
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewService returns a new instance of DefaultService ready to be
|
// NewService returns a new instance of defaultService ready to be
|
||||||
// installed into an engine.
|
// installed into an engine.
|
||||||
func NewService(options ServiceOptions) (*DefaultService, error) {
|
func NewService(options ServiceOptions) (Service, error) {
|
||||||
config, err := newServiceConfig(options)
|
config, err := newServiceConfig(options)
|
||||||
|
|
||||||
return &DefaultService{config: config}, err
|
return &defaultService{config: config}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceConfig returns the public registry service configuration.
|
// ServiceConfig returns the public registry service configuration.
|
||||||
func (s *DefaultService) ServiceConfig() *registrytypes.ServiceConfig {
|
func (s *defaultService) ServiceConfig() *registrytypes.ServiceConfig {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ func (s *DefaultService) ServiceConfig() *registrytypes.ServiceConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadAllowNondistributableArtifacts loads allow-nondistributable-artifacts registries for Service.
|
// LoadAllowNondistributableArtifacts loads allow-nondistributable-artifacts registries for Service.
|
||||||
func (s *DefaultService) LoadAllowNondistributableArtifacts(registries []string) error {
|
func (s *defaultService) LoadAllowNondistributableArtifacts(registries []string) error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func (s *DefaultService) LoadAllowNondistributableArtifacts(registries []string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadMirrors loads registry mirrors for Service
|
// LoadMirrors loads registry mirrors for Service
|
||||||
func (s *DefaultService) LoadMirrors(mirrors []string) error {
|
func (s *defaultService) LoadMirrors(mirrors []string) error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func (s *DefaultService) LoadMirrors(mirrors []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadInsecureRegistries loads insecure registries for Service
|
// LoadInsecureRegistries loads insecure registries for Service
|
||||||
func (s *DefaultService) LoadInsecureRegistries(registries []string) error {
|
func (s *defaultService) LoadInsecureRegistries(registries []string) error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ func (s *DefaultService) LoadInsecureRegistries(registries []string) error {
|
||||||
// Auth contacts the public registry with the provided credentials,
|
// Auth contacts the public registry with the provided credentials,
|
||||||
// and returns OK if authentication was successful.
|
// and returns OK if authentication was successful.
|
||||||
// It can be used to verify the validity of a client's credentials.
|
// It can be used to verify the validity of a client's credentials.
|
||||||
func (s *DefaultService) Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error) {
|
func (s *defaultService) Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error) {
|
||||||
// TODO Use ctx when searching for repositories
|
// TODO Use ctx when searching for repositories
|
||||||
var registryHostName = IndexHostname
|
var registryHostName = IndexHostname
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ func splitReposSearchTerm(reposName string) (string, string) {
|
||||||
|
|
||||||
// Search queries the public registry for images matching the specified
|
// Search queries the public registry for images matching the specified
|
||||||
// search terms, and returns the results.
|
// search terms, and returns the results.
|
||||||
func (s *DefaultService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) {
|
func (s *defaultService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error) {
|
||||||
// TODO Use ctx when searching for repositories
|
// TODO Use ctx when searching for repositories
|
||||||
if err := validateNoScheme(term); err != nil {
|
if err := validateNoScheme(term); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -229,7 +229,7 @@ func (s *DefaultService) Search(ctx context.Context, term string, limit int, aut
|
||||||
|
|
||||||
// ResolveRepository splits a repository name into its components
|
// ResolveRepository splits a repository name into its components
|
||||||
// and configuration of the associated registry.
|
// and configuration of the associated registry.
|
||||||
func (s *DefaultService) ResolveRepository(name reference.Named) (*RepositoryInfo, error) {
|
func (s *defaultService) ResolveRepository(name reference.Named) (*RepositoryInfo, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
return newRepositoryInfo(s.config, name)
|
return newRepositoryInfo(s.config, name)
|
||||||
|
@ -247,7 +247,7 @@ type APIEndpoint struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLSConfig constructs a client TLS configuration based on server defaults
|
// TLSConfig constructs a client TLS configuration based on server defaults
|
||||||
func (s *DefaultService) TLSConfig(hostname string) (*tls.Config, error) {
|
func (s *defaultService) TLSConfig(hostname string) (*tls.Config, error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
@ -255,13 +255,13 @@ func (s *DefaultService) TLSConfig(hostname string) (*tls.Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// tlsConfig constructs a client TLS configuration based on server defaults
|
// tlsConfig constructs a client TLS configuration based on server defaults
|
||||||
func (s *DefaultService) tlsConfig(hostname string) (*tls.Config, error) {
|
func (s *defaultService) tlsConfig(hostname string) (*tls.Config, error) {
|
||||||
return newTLSConfig(hostname, isSecureIndex(s.config, hostname))
|
return newTLSConfig(hostname, isSecureIndex(s.config, hostname))
|
||||||
}
|
}
|
||||||
|
|
||||||
// LookupPullEndpoints creates a list of v2 endpoints to try to pull from, in order of preference.
|
// LookupPullEndpoints creates a list of v2 endpoints to try to pull from, in order of preference.
|
||||||
// It gives preference to mirrors over the actual registry, and HTTPS over plain HTTP.
|
// It gives preference to mirrors over the actual registry, and HTTPS over plain HTTP.
|
||||||
func (s *DefaultService) LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
func (s *defaultService) LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
@ -270,7 +270,7 @@ func (s *DefaultService) LookupPullEndpoints(hostname string) (endpoints []APIEn
|
||||||
|
|
||||||
// LookupPushEndpoints creates a list of v2 endpoints to try to push to, in order of preference.
|
// LookupPushEndpoints creates a list of v2 endpoints to try to push to, in order of preference.
|
||||||
// It gives preference to HTTPS over plain HTTP. Mirrors are not included.
|
// It gives preference to HTTPS over plain HTTP. Mirrors are not included.
|
||||||
func (s *DefaultService) LookupPushEndpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
func (s *defaultService) LookupPushEndpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/docker/go-connections/tlsconfig"
|
"github.com/docker/go-connections/tlsconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *DefaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
func (s *defaultService) lookupV2Endpoints(hostname string) (endpoints []APIEndpoint, err error) {
|
||||||
tlsConfig := tlsconfig.ServerDefault()
|
tlsConfig := tlsconfig.ServerDefault()
|
||||||
if hostname == DefaultNamespace || hostname == IndexHostname {
|
if hostname == DefaultNamespace || hostname == IndexHostname {
|
||||||
for _, mirror := range s.config.Mirrors {
|
for _, mirror := range s.config.Mirrors {
|
||||||
|
|
Loading…
Reference in New Issue