mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
distro: identify uses the scope resolvers now, not images
Signed-off-by: Alfredo Deza <adeza@anchore.com>
This commit is contained in:
parent
923d220a90
commit
d22c1d0838
@ -4,18 +4,16 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/anchore/imgbom/imgbom/scope"
|
||||||
"github.com/anchore/imgbom/internal/log"
|
"github.com/anchore/imgbom/internal/log"
|
||||||
"github.com/anchore/stereoscope/pkg/file"
|
"github.com/anchore/stereoscope/pkg/file"
|
||||||
"github.com/anchore/stereoscope/pkg/image"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// returns a distro or nil
|
// returns a distro or nil
|
||||||
type parseFunc func(string) *Distro
|
type parseFunc func(string) *Distro
|
||||||
|
|
||||||
// Identify parses distro-specific files to determine distro metadata like version and release
|
// Identify parses distro-specific files to determine distro metadata like version and release
|
||||||
func Identify(img *image.Image) *Distro {
|
func Identify(s scope.Scope) *Distro {
|
||||||
// TODO: implement me based off of https://github.com/anchore/anchore-engine/blob/78b23d7e8f007005c070673405b5e23730a660e0/anchore_engine/analyzers/utils.py#L131
|
|
||||||
|
|
||||||
identityFiles := map[file.Path]parseFunc{
|
identityFiles := map[file.Path]parseFunc{
|
||||||
"/etc/os-release": parseOsRelease,
|
"/etc/os-release": parseOsRelease,
|
||||||
// Debian and Debian-based distros have the same contents linked from this path
|
// Debian and Debian-based distros have the same contents linked from this path
|
||||||
@ -24,18 +22,37 @@ func Identify(img *image.Image) *Distro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for path, fn := range identityFiles {
|
for path, fn := range identityFiles {
|
||||||
contents, err := img.FileContentsFromSquash(path) // TODO: this call replaced with "MultipleFileContents"
|
// this is always a slice with a single ref, the API is odd because it was meant for images
|
||||||
|
refs, err := s.FilesByPath(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("unable to get path refs from %s: %s", path, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(refs) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ref := refs[0]
|
||||||
|
|
||||||
|
contents, err := s.MultipleFileContentsByRef(ref)
|
||||||
|
log.Infof("contents are: %+v", contents)
|
||||||
|
content, ok := contents[ref]
|
||||||
|
// XXX is it possible to get a ref and no contents at all?
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("unable to get contents from %s: %s", path, err)
|
log.Debugf("unable to get contents from %s: %s", path, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if contents == "" {
|
if content == "" {
|
||||||
log.Debugf("no contents in file, skipping: %s", path)
|
log.Debugf("no contents in file, skipping: %s", path)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
distro := fn(contents)
|
|
||||||
|
distro := fn(content)
|
||||||
|
|
||||||
if distro == nil {
|
if distro == nil {
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user