Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update Referrers API for distribution-spec v1.1.0-rc3 #553

Merged
merged 10 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix typo
Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
  • Loading branch information
Wwwsylvia committed Jul 24, 2023
commit c83bd0d0d39d671bce6b1c14393068091f2feca1
18 changes: 9 additions & 9 deletions registry/remote/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ import (
)

const (
// headerdockerContentDigest is the "Docker-Content-Digest" header.
// headerDockerContentDigest is the "Docker-Content-Digest" header.
// If present on the response, it contains the canonical digest of the
// uploaded blob.
//
// References:
// - https://docs.docker.com/registry/spec/api/#digest-header
// - https://github.com/opencontainers/distribution-spec/blob/v1.1.0-rc1/spec.md#pull
Wwwsylvia marked this conversation as resolved.
Show resolved Hide resolved
headerdockerContentDigest = "Docker-Content-Digest"
headerDockerContentDigest = "Docker-Content-Digest"

// headerOCIFiltersApplied is the "OCI-Filters-Applied" header.
// If present on the response, it contains a comma-separated list of the
Expand Down Expand Up @@ -1442,13 +1442,13 @@ func (s *manifestStore) generateDescriptor(resp *http.Response, ref registry.Ref

// 4. Validate Server Digest (if present)
var serverHeaderDigest digest.Digest
if serverHeaderDigestStr := resp.Header.Get(headerdockerContentDigest); serverHeaderDigestStr != "" {
if serverHeaderDigestStr := resp.Header.Get(headerDockerContentDigest); serverHeaderDigestStr != "" {
if serverHeaderDigest, err = digest.Parse(serverHeaderDigestStr); err != nil {
return ocispec.Descriptor{}, fmt.Errorf(
"%s %q: invalid response header value: `%s: %s`; %w",
resp.Request.Method,
resp.Request.URL,
headerdockerContentDigest,
headerDockerContentDigest,
serverHeaderDigestStr,
err,
)
Expand All @@ -1465,7 +1465,7 @@ func (s *manifestStore) generateDescriptor(resp *http.Response, ref registry.Ref
// immediate fail
return ocispec.Descriptor{}, fmt.Errorf(
"HTTP %s request missing required header %q",
httpMethod, headerdockerContentDigest,
httpMethod, headerDockerContentDigest,
)
}
// Otherwise, just trust the client-supplied digest
Expand All @@ -1487,7 +1487,7 @@ func (s *manifestStore) generateDescriptor(resp *http.Response, ref registry.Ref
return ocispec.Descriptor{}, fmt.Errorf(
"%s %q: invalid response; digest mismatch in %s: received %q when expecting %q",
resp.Request.Method, resp.Request.URL,
headerdockerContentDigest, contentDigest,
headerDockerContentDigest, contentDigest,
refDigest,
)
}
Expand Down Expand Up @@ -1519,7 +1519,7 @@ func calculateDigestFromResponse(resp *http.Response, maxMetadataBytes int64) (d
// OCI distribution-spec states the Docker-Content-Digest header is optional.
// Reference: https://github.com/opencontainers/distribution-spec/blob/v1.0.1/spec.md#legacy-docker-support-http-headers
func verifyContentDigest(resp *http.Response, expected digest.Digest) error {
digestStr := resp.Header.Get(headerdockerContentDigest)
digestStr := resp.Header.Get(headerDockerContentDigest)

if len(digestStr) == 0 {
return nil
Expand All @@ -1530,15 +1530,15 @@ func verifyContentDigest(resp *http.Response, expected digest.Digest) error {
return fmt.Errorf(
"%s %q: invalid response header: `%s: %s`",
resp.Request.Method, resp.Request.URL,
headerdockerContentDigest, digestStr,
headerDockerContentDigest, digestStr,
)
}

if contentDigest != expected {
return fmt.Errorf(
"%s %q: invalid response; digest mismatch in %s: received %q when expecting %q",
resp.Request.Method, resp.Request.URL,
headerdockerContentDigest, contentDigest,
headerDockerContentDigest, contentDigest,
expected,
)
}
Expand Down
6 changes: 3 additions & 3 deletions registry/remote/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func TestRepository_Mount(t *testing.T) {
t.Errorf("unexpected value for 'from' parameter; got %q want %q", got, want)
}
gotMount++
w.Header().Set(headerdockerContentDigest, blobDesc.Digest.String())
w.Header().Set(headerDockerContentDigest, blobDesc.Digest.String())
w.WriteHeader(201)
return
default:
Expand Down Expand Up @@ -3101,7 +3101,7 @@ func Test_generateBlobDescriptorWithVariousDockerContentDigestHeaders(t *testing
resp := http.Response{
Header: http.Header{
"Content-Type": []string{"application/vnd.docker.distribution.manifest.v2+json"},
headerdockerContentDigest: []string{dcdIOStruct.serverCalculatedDigest.String()},
headerDockerContentDigest: []string{dcdIOStruct.serverCalculatedDigest.String()},
},
}
if method == http.MethodGet {
Expand Down Expand Up @@ -5114,7 +5114,7 @@ func Test_ManifestStore_generateDescriptorWithVariousDockerContentDigestHeaders(
resp := http.Response{
Header: http.Header{
"Content-Type": []string{"application/vnd.docker.distribution.manifest.v2+json"},
headerdockerContentDigest: []string{dcdIOStruct.serverCalculatedDigest.String()},
headerDockerContentDigest: []string{dcdIOStruct.serverCalculatedDigest.String()},
},
}
if method == http.MethodGet {
Expand Down