-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbom.go
52 lines (45 loc) · 984 Bytes
/
sbom.go
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
46
47
48
49
50
51
52
package main
import (
"io"
"github.com/anchore/syft/syft/format/syftjson"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/sbom"
)
func getBOM(f io.Reader) *sbom.SBOM {
dec := syftjson.NewFormatDecoder()
bom, formatID, version, err := dec.Decode(f)
if err != nil {
panic(err)
}
_ = formatID
_ = version
return bom
}
func findEntrypoint(b *sbom.SBOM, entrypoint string) bool {
pkgChan := b.Artifacts.Packages.Enumerate()
pkgs := make([]pkg.Package, 0, 128)
for pkg := range pkgChan {
pkgs = append(pkgs, pkg)
}
for _, pkg := range pkgs {
if findEntrypointInMetadata(pkg.Metadata, entrypoint) {
return true
}
}
return false
}
func findEntrypointInMetadata(m any, entrypoint string) bool {
switch r := m.(type) {
case pkg.DpkgDBEntry:
return inDpkgPath(r, entrypoint)
}
return false
}
func inDpkgPath(r pkg.DpkgDBEntry, want string) bool {
for _, f := range r.Files {
if f.Path == want {
return true
}
}
return false
}