MCPcopy Index your code
hub / github.com/cli/cli / FilterAttestations

Function FilterAttestations

pkg/cmd/attestation/api/attestation.go:32–58  ·  view source on GitHub ↗
(predicateType string, attestations []*Attestation)

Source from the content-addressed store, hash-verified

30}
31
32func FilterAttestations(predicateType string, attestations []*Attestation) ([]*Attestation, error) {
33 filteredAttestations := []*Attestation{}
34
35 for _, each := range attestations {
36 dsseEnvelope := each.Bundle.GetDsseEnvelope()
37 if dsseEnvelope != nil {
38 if dsseEnvelope.PayloadType != "application/vnd.in-toto+json" {
39 // Don't fail just because an entry isn't intoto
40 continue
41 }
42 var intotoStatement IntotoStatement
43 if err := json.Unmarshal([]byte(dsseEnvelope.Payload), &intotoStatement); err != nil {
44 // Don't fail just because a single entry can't be unmarshalled
45 continue
46 }
47 if intotoStatement.PredicateType == predicateType {
48 filteredAttestations = append(filteredAttestations, each)
49 }
50 }
51 }
52
53 if len(filteredAttestations) == 0 {
54 return nil, fmt.Errorf("no attestations found with predicate type: %s", predicateType)
55 }
56
57 return filteredAttestations, nil
58}

Callers 4

TestFilterAttestationsFunction · 0.92
getAttestationsFunction · 0.92
runDownloadFunction · 0.92
OnGetByDigestSuccessFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by 1

TestFilterAttestationsFunction · 0.74