1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
package attestation
import (
"bytes"
"github.com/moby/buildkit/exporter"
)
func Filter(attestations []exporter.Attestation, include map[string][]byte, exclude map[string][]byte) []exporter.Attestation {
if len(include) == 0 && len(exclude) == 0 {
return attestations
}
result := []exporter.Attestation{}
for _, att := range attestations {
meta := att.Metadata
if meta == nil {
meta = map[string][]byte{}
}
match := true
for k, v := range include {
if !bytes.Equal(meta[k], v) {
match = false
break
}
}
if !match {
continue
}
for k, v := range exclude {
if bytes.Equal(meta[k], v) {
match = false
break
}
}
if !match {
continue
}
result = append(result, att)
}
return result
}
|