mirror of
https://github.com/anchore/syft
synced 2024-11-10 06:14:16 +00:00
create the dpkg analyzer
Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
parent
5bc17310b6
commit
61139007ca
1 changed files with 60 additions and 0 deletions
60
imgbom/analyzer/dpkg/analyzer.go
Normal file
60
imgbom/analyzer/dpkg/analyzer.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package dpkg
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/anchore/imgbom/imgbom/pkg"
|
||||
"github.com/anchore/stereoscope/pkg/file"
|
||||
"github.com/anchore/stereoscope/pkg/tree"
|
||||
)
|
||||
|
||||
type Analyzer struct {
|
||||
selectedFiles []file.Reference
|
||||
}
|
||||
|
||||
func NewAnalyzer() *Analyzer {
|
||||
return &Analyzer{}
|
||||
}
|
||||
|
||||
func (a *Analyzer) SelectFiles(trees []*tree.FileTree) []file.Reference {
|
||||
files := make([]file.Reference, 0)
|
||||
for _, tree := range trees {
|
||||
// TODO: extract into function/slice/etc
|
||||
file := tree.File("/var/lib/dpkg/status")
|
||||
if file != nil {
|
||||
files = append(files, *file)
|
||||
}
|
||||
}
|
||||
|
||||
a.selectedFiles = files
|
||||
|
||||
return files
|
||||
}
|
||||
|
||||
func (a *Analyzer) Analyze(contents map[file.Reference]string) ([]pkg.Package, error) {
|
||||
packages := make([]pkg.Package, 0)
|
||||
for _, reference := range a.selectedFiles {
|
||||
content, ok := contents[reference]
|
||||
if !ok {
|
||||
// TODO: this needs handling
|
||||
panic(reference)
|
||||
}
|
||||
|
||||
entries, err := ParseEntries(strings.NewReader(content))
|
||||
if err != nil {
|
||||
// TODO: punt for now, we need to handle this
|
||||
panic(err)
|
||||
}
|
||||
for _, entry := range entries {
|
||||
packages = append(packages, pkg.Package{
|
||||
Name: entry.Package,
|
||||
Version: entry.Version,
|
||||
Type: pkg.DebPkg,
|
||||
Source: []file.Reference{reference},
|
||||
Metadata: entry,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
return packages, nil
|
||||
}
|
Loading…
Reference in a new issue