registry: DefaultService.Auth(): skip parsing default registry
There's no need to parse or validate the default registry, as it's
a constant value.
@@ -108,10 +108,10 @@ func (s *DefaultService) LoadInsecureRegistries(registries []string) error {
// 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) {
// TODO Use ctx when searching for repositories
+ var registryHostName = IndexHostname
+
+ if authConfig.ServerAddress != "" {
serverAddress := authConfig.ServerAddress
- if serverAddress == "" {
- serverAddress = IndexServer
- }
if !strings.HasPrefix(serverAddress, "https://") && !strings.HasPrefix(serverAddress, "http://") {
serverAddress = "https://" + serverAddress
}
@@ -119,11 +119,13 @@ func (s *DefaultService) Auth(ctx context.Context, authConfig *types.AuthConfig,
if err != nil {
return "", "", errdefs.InvalidParameter(errors.Errorf("unable to parse server address: %v", err))
}
+ registryHostName = u.Host
+ }
// Lookup endpoints for authentication using "LookupPushEndpoints", which
// excludes mirrors to prevent sending credentials of the upstream registry
// to a mirror.
- endpoints, err := s.LookupPushEndpoints(u.Host)
+ endpoints, err := s.LookupPushEndpoints(registryHostName)
if err != nil {
return "", "", errdefs.InvalidParameter(err)
}
