From b4972a6bab3965ecd186c392d058f7bb43fd8e7a Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 19 May 2015 19:56:27 -0700 Subject: [PATCH] Break down type dependencies Each type no longer requires holding a reference to repository. Added implementation for signatures get. Signed-off-by: Derek McGowan (github: dmcgowan) --- docs/client/blob_writer.go | 6 +++--- docs/client/repository.go | 42 ++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/docs/client/blob_writer.go b/docs/client/blob_writer.go index 55223520..9ebd4183 100644 --- a/docs/client/blob_writer.go +++ b/docs/client/blob_writer.go @@ -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 { diff --git a/docs/client/repository.go b/docs/client/repository.go index 123ef6ce..a1117ac2 100644 --- a/docs/client/repository.go +++ b/docs/client/repository.go @@ -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) {