mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01: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>
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package cpp
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"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"
|
|
)
|
|
|
|
var _ generic.Parser = parseConanlock
|
|
|
|
type conanLock struct {
|
|
GraphLock struct {
|
|
Nodes map[string]struct {
|
|
Ref string `json:"ref"`
|
|
PackageID string `json:"package_id"`
|
|
Context string `json:"context"`
|
|
Prev string `json:"prev"`
|
|
Requires []string `json:"requires"`
|
|
PythonRequires string `json:"py_requires"`
|
|
Options string `json:"options"`
|
|
Path string `json:"path"`
|
|
} `json:"nodes"`
|
|
} `json:"graph_lock"`
|
|
Version string `json:"version"`
|
|
ProfileHost string `json:"profile_host"`
|
|
}
|
|
|
|
// parseConanlock is a parser function for conan.lock contents, returning all packages discovered.
|
|
func parseConanlock(_ source.FileResolver, _ *generic.Environment, reader source.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
|
var pkgs []pkg.Package
|
|
var cl conanLock
|
|
if err := json.NewDecoder(reader).Decode(&cl); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
for _, node := range cl.GraphLock.Nodes {
|
|
metadata := pkg.ConanLockMetadata{
|
|
Ref: node.Ref,
|
|
Options: parseOptions(node.Options),
|
|
Path: node.Path,
|
|
Context: node.Context,
|
|
}
|
|
|
|
p := newConanlockPackage(
|
|
metadata,
|
|
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
|
)
|
|
|
|
if p != nil {
|
|
pkgs = append(pkgs, *p)
|
|
}
|
|
}
|
|
|
|
return pkgs, nil, nil
|
|
}
|
|
|
|
func parseOptions(options string) map[string]string {
|
|
o := make(map[string]string)
|
|
if len(options) == 0 {
|
|
return nil
|
|
}
|
|
|
|
kvps := strings.Split(options, "\n")
|
|
for _, kvp := range kvps {
|
|
kv := strings.Split(kvp, "=")
|
|
if len(kv) == 2 {
|
|
o[kv[0]] = kv[1]
|
|
}
|
|
}
|
|
|
|
return o
|
|
}
|