File: filter.go

package info (click to toggle)
docker.io 26.1.5%2Bdfsg1-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 68,644 kB
  • sloc: sh: 5,748; makefile: 912; ansic: 664; asm: 228; python: 162
file content (45 lines) | stat: -rw-r--r-- 756 bytes parent folder | download | duplicates (7)
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
}