mirror of
https://github.com/anchore/syft.git
synced 2025-11-22 02:43:19 +01:00
* migrate location structs to file package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * replace source.Location refs with file package call Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove hardlink test for file based catalogers Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove hardlink test for all-regular-files testing Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * migrate file resolver implementations to separate package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * [wip] migrate resolvers to internal Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * migrate resolvers to syft/internal Signed-off-by: Alex Goodman <alex.goodman@anchore.com> --------- Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: <>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package python
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pelletier/go-toml"
|
|
|
|
"github.com/anchore/syft/syft/artifact"
|
|
"github.com/anchore/syft/syft/file"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/anchore/syft/syft/pkg/cataloger/generic"
|
|
)
|
|
|
|
// 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(_ file.Resolver, _ *generic.Environment, reader file.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
|
|
}
|