mirror of
https://github.com/anchore/syft.git
synced 2025-11-21 18:33:18 +01:00
* add kernel handler Signed-off-by: Avi Deitcher <avi@deitcher.net> * [wip] combine kernel and kernel module cataloging Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * [wip] combine kernel and kernel module cataloging Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: Avi Deitcher <avi@deitcher.net> * rename Kernel package to LinuxKernel package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * split kernel and module packages within cataloger Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * wire up application configuration with kernel cataloger options Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * dont use references for packages on relationships Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix linting and tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * kernel cataloger should be resistent to partial failure Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * log upon kernel module metadata missing Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add tests for linux kernel cataloger Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update integration tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update cli package test counts Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add evidence annotations for kernel packages Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * reduce noise in cli test output Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * missed cli test to reduce noise for Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix package counts Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update docs with linux kernel cataloging refs Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * bump json schema with new metadata fields Signed-off-by: Alex Goodman <alex.goodman@anchore.com> --------- Signed-off-by: Avi Deitcher <avi@deitcher.net> Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Signed-off-by: <> Co-authored-by: Alex Goodman <alex.goodman@anchore.com>
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package kernel
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/anchore/packageurl-go"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
const linuxKernelPackageName = "linux-kernel"
|
|
|
|
func newLinuxKernelPackage(metadata pkg.LinuxKernelMetadata, locations ...source.Location) pkg.Package {
|
|
p := pkg.Package{
|
|
Name: linuxKernelPackageName,
|
|
Version: metadata.Version,
|
|
Locations: source.NewLocationSet(locations...),
|
|
PURL: packageURL(linuxKernelPackageName, metadata.Version),
|
|
Type: pkg.LinuxKernelPkg,
|
|
MetadataType: pkg.LinuxKernelMetadataType,
|
|
Metadata: metadata,
|
|
}
|
|
|
|
p.SetID()
|
|
|
|
return p
|
|
}
|
|
|
|
func newLinuxKernelModulePackage(metadata pkg.LinuxKernelModuleMetadata, locations ...source.Location) pkg.Package {
|
|
var licenses []string
|
|
if metadata.License != "" {
|
|
licenses = []string{metadata.License}
|
|
} else {
|
|
licenses = []string{}
|
|
}
|
|
|
|
p := pkg.Package{
|
|
Name: metadata.Name,
|
|
Version: metadata.Version,
|
|
Locations: source.NewLocationSet(locations...),
|
|
Licenses: licenses,
|
|
PURL: packageURL(metadata.Name, metadata.Version),
|
|
Type: pkg.LinuxKernelModulePkg,
|
|
MetadataType: pkg.LinuxKernelModuleMetadataType,
|
|
Metadata: metadata,
|
|
}
|
|
|
|
p.SetID()
|
|
|
|
return p
|
|
}
|
|
|
|
// packageURL returns the PURL for the specific Kernel package (see https://github.com/package-url/purl-spec)
|
|
func packageURL(name, version string) string {
|
|
var namespace string
|
|
|
|
fields := strings.SplitN(name, "/", 2)
|
|
if len(fields) > 1 {
|
|
namespace = fields[0]
|
|
name = fields[1]
|
|
}
|
|
|
|
return packageurl.NewPackageURL(
|
|
packageurl.TypeGeneric,
|
|
namespace,
|
|
name,
|
|
version,
|
|
nil,
|
|
"",
|
|
).ToString()
|
|
}
|