github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/gosbom/pkg/cataloger/dart/package.go (about) 1 package dart 2 3 import ( 4 "github.com/nextlinux/gosbom/gosbom/file" 5 "github.com/nextlinux/gosbom/gosbom/pkg" 6 7 "github.com/anchore/packageurl-go" 8 ) 9 10 func newPubspecLockPackage(name string, raw pubspecLockPackage, locations ...file.Location) pkg.Package { 11 metadata := pkg.DartPubMetadata{ 12 Name: name, 13 Version: raw.Version, 14 HostedURL: raw.getHostedURL(), 15 VcsURL: raw.getVcsURL(), 16 } 17 18 p := pkg.Package{ 19 Name: name, 20 Version: raw.Version, 21 Locations: file.NewLocationSet(locations...), 22 PURL: packageURL(metadata), 23 Language: pkg.Dart, 24 Type: pkg.DartPubPkg, 25 MetadataType: pkg.DartPubMetadataType, 26 Metadata: metadata, 27 } 28 29 p.SetID() 30 31 return p 32 } 33 34 func packageURL(m pkg.DartPubMetadata) string { 35 var qualifiers packageurl.Qualifiers 36 37 if m.HostedURL != "" { 38 qualifiers = append(qualifiers, packageurl.Qualifier{ 39 Key: "hosted_url", 40 Value: m.HostedURL, 41 }) 42 } else if m.VcsURL != "" { // Default to using Hosted if somehow both are provided 43 qualifiers = append(qualifiers, packageurl.Qualifier{ 44 Key: "vcs_url", 45 Value: m.VcsURL, 46 }) 47 } 48 49 return packageurl.NewPackageURL( 50 packageurl.TypePub, 51 "", 52 m.Name, 53 m.Version, 54 qualifiers, 55 "", 56 ).ToString() 57 }