mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 00:43:20 +01:00
* remove centralize pURL generation Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * port java cataloger to new generic cataloger pattern Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove common.GenericCataloger Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update format test fixtures to reflect ID updates Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix package sort instability for encode-decode-encode cycles Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package pkg
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/anchore/packageurl-go"
|
|
"github.com/anchore/syft/syft/linux"
|
|
)
|
|
|
|
const (
|
|
PURLQualifierArch = "arch"
|
|
PURLQualifierDistro = "distro"
|
|
PURLQualifierEpoch = "epoch"
|
|
PURLQualifierVCSURL = "vcs_url"
|
|
|
|
// PURLQualifierUpstream this qualifier is not in the pURL spec, but is used by grype to perform indirect matching based on source information
|
|
PURLQualifierUpstream = "upstream"
|
|
|
|
purlCargoPkgType = "cargo"
|
|
purlGradlePkgType = "gradle"
|
|
)
|
|
|
|
func PURLQualifiers(vars map[string]string, release *linux.Release) (q packageurl.Qualifiers) {
|
|
keys := make([]string, 0, len(vars))
|
|
for k := range vars {
|
|
keys = append(keys, k)
|
|
}
|
|
sort.Strings(keys)
|
|
|
|
for _, k := range keys {
|
|
val := vars[k]
|
|
if val == "" {
|
|
continue
|
|
}
|
|
q = append(q, packageurl.Qualifier{
|
|
Key: k,
|
|
Value: vars[k],
|
|
})
|
|
}
|
|
|
|
distroQualifiers := []string{}
|
|
|
|
if release == nil {
|
|
return q
|
|
}
|
|
|
|
if release.ID != "" {
|
|
distroQualifiers = append(distroQualifiers, release.ID)
|
|
}
|
|
|
|
if release.VersionID != "" {
|
|
distroQualifiers = append(distroQualifiers, release.VersionID)
|
|
} else if release.BuildID != "" {
|
|
distroQualifiers = append(distroQualifiers, release.BuildID)
|
|
}
|
|
|
|
q = append(q, packageurl.Qualifier{
|
|
Key: PURLQualifierDistro,
|
|
Value: strings.Join(distroQualifiers, "-"),
|
|
})
|
|
|
|
return q
|
|
}
|