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

Commit

Permalink
Merge branch 'accept-any-manifest'
Browse files Browse the repository at this point in the history
  • Loading branch information
tt committed Oct 3, 2018
2 parents 567645a + d3817d4 commit 0591d1e
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions registry/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"io/ioutil"
"net/http"

manifestV1 "github.com/docker/distribution/manifest/schema1"
manifestV2 "github.com/docker/distribution/manifest/schema2"
"github.com/docker/distribution"
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/manifest/schema2"
digest "github.com/opencontainers/go-digest"
)

func (registry *Registry) Manifest(repository, reference string) (*manifestV1.SignedManifest, error) {
func (registry *Registry) Manifest(repository, reference string) (*schema1.SignedManifest, error) {
url := registry.url("/v2/%s/manifests/%s", repository, reference)
registry.Logf("registry.manifest.get url=%s repository=%s reference=%s", url, repository, reference)

Expand All @@ -19,7 +20,7 @@ func (registry *Registry) Manifest(repository, reference string) (*manifestV1.Si
return nil, err
}

req.Header.Set("Accept", manifestV1.MediaTypeManifest)
req.Header.Set("Accept", schema1.MediaTypeManifest)
resp, err := registry.Client.Do(req)
if err != nil {
return nil, err
Expand All @@ -31,7 +32,7 @@ func (registry *Registry) Manifest(repository, reference string) (*manifestV1.Si
return nil, err
}

signedManifest := &manifestV1.SignedManifest{}
signedManifest := &schema1.SignedManifest{}
err = signedManifest.UnmarshalJSON(body)
if err != nil {
return nil, err
Expand All @@ -40,7 +41,7 @@ func (registry *Registry) Manifest(repository, reference string) (*manifestV1.Si
return signedManifest, nil
}

func (registry *Registry) ManifestV2(repository, reference string) (*manifestV2.DeserializedManifest, error) {
func (registry *Registry) ManifestV2(repository, reference string) (*schema2.DeserializedManifest, error) {
url := registry.url("/v2/%s/manifests/%s", repository, reference)
registry.Logf("registry.manifest.get url=%s repository=%s reference=%s", url, repository, reference)

Expand All @@ -49,7 +50,7 @@ func (registry *Registry) ManifestV2(repository, reference string) (*manifestV2.
return nil, err
}

req.Header.Set("Accept", manifestV2.MediaTypeManifest)
req.Header.Set("Accept", schema2.MediaTypeManifest)
resp, err := registry.Client.Do(req)
if err != nil {
return nil, err
Expand All @@ -61,7 +62,7 @@ func (registry *Registry) ManifestV2(repository, reference string) (*manifestV2.
return nil, err
}

deserialized := &manifestV2.DeserializedManifest{}
deserialized := &schema2.DeserializedManifest{}
err = deserialized.UnmarshalJSON(body)
if err != nil {
return nil, err
Expand Down Expand Up @@ -101,22 +102,22 @@ func (registry *Registry) DeleteManifest(repository string, digest digest.Digest
return nil
}

func (registry *Registry) PutManifest(repository, reference string, signedManifest *manifestV1.SignedManifest) error {
func (registry *Registry) PutManifest(repository, reference string, manifest distribution.Manifest) error {
url := registry.url("/v2/%s/manifests/%s", repository, reference)
registry.Logf("registry.manifest.put url=%s repository=%s reference=%s", url, repository, reference)

body, err := signedManifest.MarshalJSON()
mediaType, payload, err := manifest.Payload()
if err != nil {
return err
}

buffer := bytes.NewBuffer(body)
buffer := bytes.NewBuffer(payload)
req, err := http.NewRequest("PUT", url, buffer)
if err != nil {
return err
}

req.Header.Set("Content-Type", manifestV1.MediaTypeManifest)
req.Header.Set("Content-Type", mediaType)
resp, err := registry.Client.Do(req)
if resp != nil {
defer resp.Body.Close()
Expand Down

0 comments on commit 0591d1e

Please sign in to comment.