mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 07:56:36 +01:00
feat: report unknowns in sbom (#2998)
Signed-off-by: Keith Zantow <kzantow@gmail.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
co-authored by
Alex Goodman
parent
4d7ed9f749
commit
ccbee94b87
@@ -9,6 +9,7 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/anchore/syft/internal/log"
|
||||
"github.com/anchore/syft/internal/unknown"
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
@@ -22,25 +23,33 @@ var mixLockDelimiter = regexp.MustCompile(`[%{}\n" ,:]+`)
|
||||
|
||||
// parseMixLock parses a mix.lock and returns the discovered Elixir packages.
|
||||
func parseMixLock(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||
var errs error
|
||||
r := bufio.NewReader(reader)
|
||||
|
||||
var packages []pkg.Package
|
||||
lineNum := 0
|
||||
for {
|
||||
lineNum++
|
||||
line, err := r.ReadString('\n')
|
||||
switch {
|
||||
case errors.Is(err, io.EOF):
|
||||
return packages, nil, nil
|
||||
if errs == nil {
|
||||
errs = unknown.IfEmptyf(packages, "unable to determine packages")
|
||||
}
|
||||
return packages, nil, errs
|
||||
case err != nil:
|
||||
return nil, nil, fmt.Errorf("failed to parse mix.lock file: %w", err)
|
||||
}
|
||||
tokens := mixLockDelimiter.Split(line, -1)
|
||||
if len(tokens) < 6 {
|
||||
errs = unknown.Appendf(errs, reader, "unable to read mix lock line %d: %s", lineNum, line)
|
||||
continue
|
||||
}
|
||||
name, version, hash, hashExt := tokens[1], tokens[4], tokens[5], tokens[len(tokens)-2]
|
||||
|
||||
if name == "" {
|
||||
log.WithFields("path", reader.RealPath).Debug("skipping empty package name from mix.lock file")
|
||||
errs = unknown.Appendf(errs, reader, "skipping empty package name from mix.lock file, for line: %d: %s", lineNum, line)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user