Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge branch 'generalize-methods'
Browse files Browse the repository at this point in the history
  • Loading branch information
tt committed Oct 4, 2018
2 parents 0591d1e + e8ba69f commit 47ecf50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ digest := digest.NewDigestFromHex(
"sha256",
"a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4",
)
reader, err := hub.DownloadLayer("heroku/cedar", digest)
)
reader, err := hub.DownloadBlob("heroku/cedar", digest)
if reader != nil {
defer reader.Close()
}
Expand All @@ -116,14 +115,13 @@ digest := digest.NewDigestFromHex(
"sha256",
"a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4",
)
exists, err := hub.HasLayer("example/repo", digest)
)
exists, err := hub.HasBlob("example/repo", digest)
if err != nil {
//
}
if !exists {
stream :=;
hub.UploadLayer("example/repo", digest, stream)
stream :=
hub.UploadBlob("example/repo", digest, stream)
}
```

Expand Down
18 changes: 9 additions & 9 deletions registry/layer.go → registry/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
digest "github.com/opencontainers/go-digest"
)

func (registry *Registry) DownloadLayer(repository string, digest digest.Digest) (io.ReadCloser, error) {
func (registry *Registry) DownloadBlob(repository string, digest digest.Digest) (io.ReadCloser, error) {
url := registry.url("/v2/%s/blobs/%s", repository, digest)
registry.Logf("registry.layer.download url=%s repository=%s digest=%s", url, repository, digest)
registry.Logf("registry.blob.download url=%s repository=%s digest=%s", url, repository, digest)

resp, err := registry.Client.Get(url)
if err != nil {
Expand All @@ -21,7 +21,7 @@ func (registry *Registry) DownloadLayer(repository string, digest digest.Digest)
return resp.Body, nil
}

func (registry *Registry) UploadLayer(repository string, digest digest.Digest, content io.Reader) error {
func (registry *Registry) UploadBlob(repository string, digest digest.Digest, content io.Reader) error {
uploadUrl, err := registry.initiateUpload(repository)
if err != nil {
return err
Expand All @@ -30,7 +30,7 @@ func (registry *Registry) UploadLayer(repository string, digest digest.Digest, c
q.Set("digest", digest.String())
uploadUrl.RawQuery = q.Encode()

registry.Logf("registry.layer.upload url=%s repository=%s digest=%s", uploadUrl, repository, digest)
registry.Logf("registry.blob.upload url=%s repository=%s digest=%s", uploadUrl, repository, digest)

upload, err := http.NewRequest("PUT", uploadUrl.String(), content)
if err != nil {
Expand All @@ -42,9 +42,9 @@ func (registry *Registry) UploadLayer(repository string, digest digest.Digest, c
return err
}

func (registry *Registry) HasLayer(repository string, digest digest.Digest) (bool, error) {
func (registry *Registry) HasBlob(repository string, digest digest.Digest) (bool, error) {
checkUrl := registry.url("/v2/%s/blobs/%s", repository, digest)
registry.Logf("registry.layer.check url=%s repository=%s digest=%s", checkUrl, repository, digest)
registry.Logf("registry.blob.check url=%s repository=%s digest=%s", checkUrl, repository, digest)

resp, err := registry.Client.Head(checkUrl)
if resp != nil {
Expand All @@ -69,9 +69,9 @@ func (registry *Registry) HasLayer(repository string, digest digest.Digest) (boo
return false, err
}

func (registry *Registry) LayerMetadata(repository string, digest digest.Digest) (distribution.Descriptor, error) {
func (registry *Registry) BlobMetadata(repository string, digest digest.Digest) (distribution.Descriptor, error) {
checkUrl := registry.url("/v2/%s/blobs/%s", repository, digest)
registry.Logf("registry.layer.check url=%s repository=%s digest=%s", checkUrl, repository, digest)
registry.Logf("registry.blob.check url=%s repository=%s digest=%s", checkUrl, repository, digest)

resp, err := registry.Client.Head(checkUrl)
if resp != nil {
Expand All @@ -89,7 +89,7 @@ func (registry *Registry) LayerMetadata(repository string, digest digest.Digest)

func (registry *Registry) initiateUpload(repository string) (*url.URL, error) {
initiateUrl := registry.url("/v2/%s/blobs/uploads/", repository)
registry.Logf("registry.layer.initiate-upload url=%s repository=%s", initiateUrl, repository)
registry.Logf("registry.blob.initiate-upload url=%s repository=%s", initiateUrl, repository)

resp, err := registry.Client.Post(initiateUrl, "application/octet-stream", nil)
if resp != nil {
Expand Down

0 comments on commit 47ecf50

Please sign in to comment.