repository.go 972 B

12345678910111213141516171819202122232425262728293031323334
  1. package distribution
  2. import (
  3. "context"
  4. "github.com/distribution/reference"
  5. "github.com/docker/distribution"
  6. "github.com/docker/docker/errdefs"
  7. )
  8. // GetRepository returns a repository from the registry.
  9. func GetRepository(ctx context.Context, ref reference.Named, config *ImagePullConfig) (repository distribution.Repository, lastError error) {
  10. repoInfo, err := config.RegistryService.ResolveRepository(ref)
  11. if err != nil {
  12. return nil, errdefs.InvalidParameter(err)
  13. }
  14. // makes sure name is not empty or `scratch`
  15. if err := validateRepoName(repoInfo.Name); err != nil {
  16. return nil, errdefs.InvalidParameter(err)
  17. }
  18. endpoints, err := config.RegistryService.LookupPullEndpoints(reference.Domain(repoInfo.Name))
  19. if err != nil {
  20. return nil, err
  21. }
  22. for _, endpoint := range endpoints {
  23. repository, lastError = newRepository(ctx, repoInfo, endpoint, nil, config.AuthConfig, "pull")
  24. if lastError == nil {
  25. break
  26. }
  27. }
  28. return repository, lastError
  29. }