Add error return to Repository method on Registry

The method (Registry).Repository may now return an error. This is too allow
certain implementationt to validate the name or opt to not return a repository
under certain conditions.

In conjunction with this change, error declarations have been moved into a
single file in the distribution package. Several error declarations that had
remained in the storage package have been moved into distribution, as well. The
declarations for Layer and LayerUpload have also been moved into the main
registry file, as a result.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2015-02-13 13:59:50 -08:00
parent ed8827c3c2
commit 3e906311c6
10 changed files with 79 additions and 86 deletions

View file

@ -2,6 +2,7 @@ package storage
import (
"github.com/docker/distribution"
"github.com/docker/distribution/registry/api/v2"
storagedriver "github.com/docker/distribution/registry/storage/driver"
"golang.org/x/net/context"
)
@ -36,12 +37,19 @@ func NewRegistryWithDriver(driver storagedriver.StorageDriver) distribution.Regi
// Repository returns an instance of the repository tied to the registry.
// Instances should not be shared between goroutines but are cheap to
// allocate. In general, they should be request scoped.
func (reg *registry) Repository(ctx context.Context, name string) distribution.Repository {
func (reg *registry) Repository(ctx context.Context, name string) (distribution.Repository, error) {
if err := v2.ValidateRespositoryName(name); err != nil {
return nil, distribution.ErrRepositoryNameInvalid{
Name: name,
Reason: err,
}
}
return &repository{
ctx: ctx,
registry: reg,
name: name,
}
}, nil
}
// repository provides name-scoped access to various services.