github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/dart/parse_pubspec.go (about) 1 package dart 2 3 import ( 4 "context" 5 "fmt" 6 7 "go.yaml.in/yaml/v3" 8 9 "github.com/anchore/syft/syft/artifact" 10 "github.com/anchore/syft/syft/file" 11 "github.com/anchore/syft/syft/pkg" 12 "github.com/anchore/syft/syft/pkg/cataloger/generic" 13 ) 14 15 type pubspecPackage struct { 16 Name string `mapstructure:"name" yaml:"name"` 17 Version string `mapstructure:"version" yaml:"version"` 18 Homepage string `mapstructure:"homepage" yaml:"homepage"` 19 Repository string `mapstructure:"repository" yaml:"repository"` 20 Documentation string `mapstructure:"documentation" yaml:"documentation"` 21 PublishTo string `mapstructure:"publish_to" yaml:"publish_to"` 22 Environment dartPubspecEnvironment `mapstructure:"environment" yaml:"environment"` 23 Platforms []string `mapstructure:"platforms" yaml:"platforms"` 24 IgnoredAdvisories []string `mapstructure:"ignored_advisories" yaml:"ignored_advisories"` 25 } 26 27 type dartPubspecEnvironment struct { 28 SDK string `mapstructure:"sdk" yaml:"sdk"` 29 Flutter string `mapstructure:"flutter" yaml:"flutter"` 30 } 31 32 func parsePubspec(ctx context.Context, resolver file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) { 33 var pkgs []pkg.Package 34 35 dec := yaml.NewDecoder(reader) 36 37 var p pubspecPackage 38 if err := dec.Decode(&p); err != nil { 39 return nil, nil, fmt.Errorf("failed to parse pubspec.yml file: %w", err) 40 } 41 42 pkgs = append(pkgs, 43 newPubspecPackage( 44 ctx, 45 resolver, 46 p, 47 reader.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), 48 ), 49 ) 50 51 return pkgs, nil, nil 52 }