Break down type dependencies

Each type no longer requires holding a reference to repository.
Added implementation for signatures get.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
Derek McGowan 2015-05-19 19:56:27 -07:00
parent a3276fcc5b
commit 13894e8736
2 changed files with 32 additions and 16 deletions

View file

@ -14,8 +14,8 @@ import (
)
type httpBlobUpload struct {
repo distribution.Repository
client *http.Client
statter distribution.BlobStatter
client *http.Client
uuid string
startedAt time.Time
@ -146,7 +146,7 @@ func (hbu *httpBlobUpload) Commit(ctx context.Context, desc distribution.Descrip
return distribution.Descriptor{}, hbu.handleErrorResponse(resp)
}
return hbu.repo.Blobs(ctx).Stat(ctx, desc.Digest)
return hbu.statter.Stat(ctx, desc.Digest)
}
func (hbu *httpBlobUpload) Cancel(ctx context.Context) error {

View file

@ -58,32 +58,42 @@ func (r *repository) Name() string {
func (r *repository) Blobs(ctx context.Context) distribution.BlobStore {
statter := &blobStatter{
repository: r,
name: r.Name(),
ub: r.ub,
client: r.client,
}
return &blobs{
repository: r,
statter: cache.NewCachedBlobStatter(cache.NewInMemoryBlobDescriptorCacheProvider(), statter),
name: r.Name(),
ub: r.ub,
client: r.client,
statter: cache.NewCachedBlobStatter(cache.NewInMemoryBlobDescriptorCacheProvider(), statter),
}
}
func (r *repository) Manifests() distribution.ManifestService {
return &manifests{
repository: r,
name: r.Name(),
ub: r.ub,
client: r.client,
}
}
func (r *repository) Signatures() distribution.SignatureService {
return &signatures{
repository: r,
manifests: r.Manifests(),
}
}
type signatures struct {
*repository
manifests distribution.ManifestService
}
func (s *signatures) Get(dgst digest.Digest) ([][]byte, error) {
panic("not implemented")
m, err := s.manifests.Get(dgst)
if err != nil {
return nil, err
}
return m.Signatures()
}
func (s *signatures) Put(dgst digest.Digest, signatures ...[]byte) error {
@ -91,7 +101,9 @@ func (s *signatures) Put(dgst digest.Digest, signatures ...[]byte) error {
}
type manifests struct {
*repository
name string
ub *v2.URLBuilder
client *http.Client
}
func (ms *manifests) Tags() ([]string, error) {
@ -239,7 +251,9 @@ func (ms *manifests) Delete(dgst digest.Digest) error {
}
type blobs struct {
*repository
name string
ub *v2.URLBuilder
client *http.Client
statter distribution.BlobStatter
}
@ -290,12 +304,12 @@ func (bs *blobs) Open(ctx context.Context, dgst digest.Digest) (distribution.Rea
return nil, err
}
blobURL, err := bs.ub.BuildBlobURL(bs.Name(), stat.Digest)
blobURL, err := bs.ub.BuildBlobURL(bs.name, stat.Digest)
if err != nil {
return nil, err
}
return transport.NewHTTPReadSeeker(bs.repository.client, blobURL, stat.Length), nil
return transport.NewHTTPReadSeeker(bs.client, blobURL, stat.Length), nil
}
func (bs *blobs) ServeBlob(ctx context.Context, w http.ResponseWriter, r *http.Request, dgst digest.Digest) error {
@ -344,7 +358,7 @@ func (bs *blobs) Create(ctx context.Context) (distribution.BlobWriter, error) {
}
return &httpBlobUpload{
repo: bs.repository,
statter: bs.statter,
client: bs.client,
uuid: uuid,
startedAt: time.Now(),
@ -360,7 +374,9 @@ func (bs *blobs) Resume(ctx context.Context, id string) (distribution.BlobWriter
}
type blobStatter struct {
*repository
name string
ub *v2.URLBuilder
client *http.Client
}
func (bs *blobStatter) Stat(ctx context.Context, dgst digest.Digest) (distribution.Descriptor, error) {