MCPcopy Create free account
hub / github.com/cli/cli / FilterAttestations

Function FilterAttestations

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

Source from the content-addressed store, hash-verified

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

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