mirror of
https://github.com/anchore/syft.git
synced 2026-04-05 22:30:35 +02:00
* add location annotations + deb evidence annotations Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * rename LocationData struct and Annotation helper function Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add failing integration test for evidence coverage Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add evidence to aplm cataloger locations Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * change location annotation helper to return a location copy Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add evidence to binary cataloger locations Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * updated remaining catalogers with location annotations Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix unit tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * bump json schema Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * partial addressing of review comments Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * rename location.WithAnnotation Signed-off-by: Alex Goodman <alex.goodman@anchore.com> --------- Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package python
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pelletier/go-toml"
|
|
|
|
"github.com/anchore/syft/syft/artifact"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/anchore/syft/syft/pkg/cataloger/generic"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
// integrity check
|
|
var _ generic.Parser = parsePoetryLock
|
|
|
|
type poetryMetadata struct {
|
|
Packages []struct {
|
|
Name string `toml:"name"`
|
|
Version string `toml:"version"`
|
|
Category string `toml:"category"`
|
|
Description string `toml:"description"`
|
|
Optional bool `toml:"optional"`
|
|
} `toml:"package"`
|
|
}
|
|
|
|
// parsePoetryLock is a parser function for poetry.lock contents, returning all python packages discovered.
|
|
func parsePoetryLock(_ source.FileResolver, _ *generic.Environment, reader source.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
|
tree, err := toml.LoadReader(reader)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("unable to load poetry.lock for parsing: %w", err)
|
|
}
|
|
|
|
metadata := poetryMetadata{}
|
|
err = tree.Unmarshal(&metadata)
|
|
if err != nil {
|
|
return nil, nil, fmt.Errorf("unable to parse poetry.lock: %w", err)
|
|
}
|
|
|
|
var pkgs []pkg.Package
|
|
for _, p := range metadata.Packages {
|
|
pkgs = append(
|
|
pkgs,
|
|
newPackageForIndex(
|
|
p.Name,
|
|
p.Version,
|
|
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
|
),
|
|
)
|
|
}
|
|
|
|
return pkgs, nil, nil
|
|
}
|