mirror of
https://github.com/anchore/syft.git
synced 2026-11-02 23:46:35 +01:00
Add CycloneDX decoder (#811)
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
package rust
|
||||
|
||||
import "github.com/anchore/syft/syft/pkg"
|
||||
package pkg
|
||||
|
||||
type CargoMetadata struct {
|
||||
Packages []pkg.CargoPackageMetadata `toml:"package"`
|
||||
Packages []CargoPackageMetadata `toml:"package"`
|
||||
}
|
||||
|
||||
// Pkgs returns all of the packages referenced within the Cargo.lock metadata.
|
||||
func (m CargoMetadata) Pkgs() []*pkg.Package {
|
||||
pkgs := make([]*pkg.Package, 0)
|
||||
func (m CargoMetadata) Pkgs() []*Package {
|
||||
pkgs := make([]*Package, 0)
|
||||
|
||||
for _, p := range m.Packages {
|
||||
if p.Dependencies == nil {
|
||||
@@ -20,7 +20,7 @@ func parseCargoLock(_ string, reader io.Reader) ([]*pkg.Package, []artifact.Rela
|
||||
return nil, nil, fmt.Errorf("unable to load Cargo.lock for parsing: %v", err)
|
||||
}
|
||||
|
||||
metadata := CargoMetadata{}
|
||||
metadata := pkg.CargoMetadata{}
|
||||
err = tree.Unmarshal(&metadata)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("unable to parse Cargo.lock: %v", err)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// MetadataType represents the data shape stored within pkg.Package.Metadata.
|
||||
type MetadataType string
|
||||
|
||||
@@ -33,3 +37,17 @@ var AllMetadataTypes = []MetadataType{
|
||||
GolangBinMetadataType,
|
||||
PhpComposerJSONMetadataType,
|
||||
}
|
||||
|
||||
var MetadataTypeByName = map[MetadataType]reflect.Type{
|
||||
ApkMetadataType: reflect.TypeOf(ApkMetadata{}),
|
||||
DpkgMetadataType: reflect.TypeOf(DpkgMetadata{}),
|
||||
GemMetadataType: reflect.TypeOf(GemMetadata{}),
|
||||
JavaMetadataType: reflect.TypeOf(JavaMetadata{}),
|
||||
NpmPackageJSONMetadataType: reflect.TypeOf(NpmPackageJSONMetadata{}),
|
||||
RpmdbMetadataType: reflect.TypeOf(RpmdbMetadata{}),
|
||||
PythonPackageMetadataType: reflect.TypeOf(PythonPackageMetadata{}),
|
||||
RustCargoPackageMetadataType: reflect.TypeOf(CargoMetadata{}),
|
||||
KbPackageMetadataType: reflect.TypeOf(KbPackageMetadata{}),
|
||||
GolangBinMetadataType: reflect.TypeOf(GolangBinMetadata{}),
|
||||
PhpComposerJSONMetadataType: reflect.TypeOf(PhpComposerJSONMetadata{}),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user