github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/lua/package.go (about)

     1  package lua
     2  
     3  import (
     4  	"context"
     5  	"path"
     6  
     7  	"github.com/anchore/packageurl-go"
     8  	"github.com/anchore/syft/syft/file"
     9  	"github.com/anchore/syft/syft/pkg"
    10  	"github.com/anchore/syft/syft/pkg/cataloger/internal/licenses"
    11  )
    12  
    13  func newLuaRocksPackage(ctx context.Context, resolver file.Resolver, u luaRocksPackage, indexLocation file.Location) pkg.Package {
    14  	license := pkg.NewLicensesFromLocationWithContext(ctx, indexLocation, u.License)
    15  	if len(license) == 0 {
    16  		license = licenses.FindInDirs(ctx, resolver, path.Dir(indexLocation.Path()))
    17  	}
    18  	p := pkg.Package{
    19  		Name:      u.Name,
    20  		Version:   u.Version,
    21  		PURL:      packageURL(u.Name, u.Version),
    22  		Locations: file.NewLocationSet(indexLocation),
    23  		Language:  pkg.Lua,
    24  		Licenses:  pkg.NewLicenseSet(license...),
    25  		Type:      pkg.LuaRocksPkg,
    26  		Metadata: pkg.LuaRocksPackage{
    27  			Name:         u.Name,
    28  			Version:      u.Version,
    29  			License:      u.License,
    30  			Homepage:     u.Homepage,
    31  			Description:  u.Description,
    32  			URL:          u.Repository.URL,
    33  			Dependencies: u.Dependencies,
    34  		},
    35  	}
    36  
    37  	p.SetID()
    38  
    39  	return p
    40  }
    41  
    42  // packageURL returns the PURL for the specific Lua Rock package (see https://github.com/package-url/purl-spec)
    43  func packageURL(name, version string) string {
    44  	return packageurl.NewPackageURL(
    45  		packageurl.TypeLuaRocks,
    46  		"",
    47  		name,
    48  		version,
    49  		nil,
    50  		"",
    51  	).ToString()
    52  }