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

provide digest error for OCI artifacts #341

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions pkg/contexts/ocm/accessmethods/ociartifact/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ func (m *accessMethod) getArtifact() (oci.ArtifactAccess, *oci.RefSpec, error) {
}

func (m *accessMethod) Digest() digest.Digest {
d, _ := m.GetDigest()
return d
}

func (m *accessMethod) GetDigest() (digest.Digest, error) {
m.lock.Lock()
defer m.lock.Unlock()

Expand All @@ -194,11 +199,11 @@ func (m *accessMethod) Digest() digest.Digest {
m.art = art
blob, err := art.Blob()
if err == nil {
return blob.Digest()
return blob.Digest(), nil
}
m.finalizer.Close(blob)
}
return ""
return "", err
}

func (m *accessMethod) Get() ([]byte, error) {
Expand Down
20 changes: 18 additions & 2 deletions pkg/contexts/ocm/digester/digesters/artifact/digester.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,30 @@ func (d *Digester) DetermineDigest(reftyp string, acc cpi.AccessMethod, preferre
// not reached (endless for)
}
if ociartifact.Is(acc.AccessSpec()) {
dig := acc.(accessio.DigestSource).Digest()
var (
dig digest.Digest
err error
)

// first: check for error providing interface
if s, ok := acc.(DigestSource); ok {
dig, err = s.GetDigest()
} else {
// second: fallback to standard digest interface
dig = acc.(accessio.DigestSource).Digest()
}

if dig != "" {
if d.GetType().HashAlgorithm != signing.NormalizeHashAlgorithm(dig.Algorithm().String()) {
return nil, nil
}
return cpi.NewDigestDescriptor(dig.Hex(), d.GetType()), nil
}
return nil, errors.Newf("cannot determine digest")
return nil, errors.NewEf(err, "cannot determine digest")
}
return nil, nil
}

type DigestSource interface {
GetDigest() (digest.Digest, error)
}