Files
syft/syft/pkg/type.go
T
bffe26bcc5 feat: add support for Bitnami cataloguer (#3341)
* prototype: start bitnami cataloger

Bitnami images have spdx SBOMs at predictable paths, and Syft could more
accurately identify the software in these images by scanning those
SBOMs. Start work on this by forking the sbom-cataloger as a new
bitnami-cataloger.

Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>

* wire up bitnami cataloger to run on images by default

Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>

* feat: add support for Bitnami cataloguer

Signed-off-by: juan131 <jariza@vmware.com>

* feat: use a better SPDX sample for unit tests

Signed-off-by: juan131 <jariza@vmware.com>

* bugfix: only report bitnami pkgs

Signed-off-by: juan131 <jariza@vmware.com>

* feat: adapt JSON schema, spdxutil and packagemetadata

Signed-off-by: juan131 <jariza@vmware.com>

* bugfix: integration tests

Signed-off-by: juan131 <jariza@vmware.com>

* feat: implement FileOwner interface

Signed-off-by: juan131 <jariza@vmware.com>

* bugfix: update json schema

Signed-off-by: juan131 <jariza@vmware.com>

* [wip] add bitnami owned files and fix binary package ownership filtering

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* feat: obtain bitnami pkg files based on SPDX relationships tree

Signed-off-by: juan131 <jariza@vmware.com>

* preserve type switches

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* rename bitnami entry metadata type

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* restrict find main pkg logic

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* add missing graalvm source info

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* bugfix: integration tests

Signed-off-by: juan131 <jariza@vmware.com>

* bugfix: mod tidy

Signed-off-by: juan131 <jariza@vmware.com>

---------

Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>
Signed-off-by: juan131 <jariza@vmware.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Co-authored-by: Will Murphy <willmurphyscode@users.noreply.github.com>
Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
2025-02-18 09:07:47 -05:00

251 lines
5.8 KiB
Go

package pkg
import (
"github.com/anchore/packageurl-go"
)
// Type represents a Package Type for or within a language ecosystem (there may be multiple package types within a language ecosystem)
type Type string
const (
// the full set of supported packages
UnknownPkg Type = "UnknownPackage"
AlpmPkg Type = "alpm"
ApkPkg Type = "apk"
BinaryPkg Type = "binary"
BitnamiPkg Type = "bitnami"
CocoapodsPkg Type = "pod"
ConanPkg Type = "conan"
DartPubPkg Type = "dart-pub"
DebPkg Type = "deb"
DotnetPkg Type = "dotnet"
ErlangOTPPkg Type = "erlang-otp"
GemPkg Type = "gem"
GithubActionPkg Type = "github-action"
GithubActionWorkflowPkg Type = "github-action-workflow"
GoModulePkg Type = "go-module"
GraalVMNativeImagePkg Type = "graalvm-native-image"
HackagePkg Type = "hackage"
HexPkg Type = "hex"
JavaPkg Type = "java-archive"
JenkinsPluginPkg Type = "jenkins-plugin"
KbPkg Type = "msrc-kb"
LinuxKernelPkg Type = "linux-kernel"
LinuxKernelModulePkg Type = "linux-kernel-module"
NixPkg Type = "nix"
NpmPkg Type = "npm"
OpamPkg Type = "opam"
PhpComposerPkg Type = "php-composer"
PhpPeclPkg Type = "php-pecl"
PortagePkg Type = "portage"
PythonPkg Type = "python"
Rpkg Type = "R-package"
LuaRocksPkg Type = "lua-rocks"
RpmPkg Type = "rpm"
RustPkg Type = "rust-crate"
SwiftPkg Type = "swift"
SwiplPackPkg Type = "swiplpack"
TerraformPkg Type = "terraform"
WordpressPluginPkg Type = "wordpress-plugin"
)
// AllPkgs represents all supported package types
var AllPkgs = []Type{
AlpmPkg,
ApkPkg,
BinaryPkg,
BitnamiPkg,
CocoapodsPkg,
ConanPkg,
DartPubPkg,
DebPkg,
DotnetPkg,
ErlangOTPPkg,
GemPkg,
GithubActionPkg,
GithubActionWorkflowPkg,
GraalVMNativeImagePkg,
GoModulePkg,
HackagePkg,
HexPkg,
JavaPkg,
JenkinsPluginPkg,
KbPkg,
LinuxKernelPkg,
LinuxKernelModulePkg,
NixPkg,
NpmPkg,
OpamPkg,
PhpComposerPkg,
PhpPeclPkg,
PortagePkg,
PythonPkg,
Rpkg,
LuaRocksPkg,
RpmPkg,
RustPkg,
SwiftPkg,
SwiplPackPkg,
TerraformPkg,
WordpressPluginPkg,
}
// PackageURLType returns the PURL package type for the current package.
//
//nolint:funlen, gocyclo
func (t Type) PackageURLType() string {
switch t {
case AlpmPkg:
return "alpm"
case ApkPkg:
return packageurl.TypeAlpine
case BitnamiPkg:
return packageurl.TypeBitnami
case CocoapodsPkg:
return packageurl.TypeCocoapods
case ConanPkg:
return packageurl.TypeConan
case DartPubPkg:
return packageurl.TypePub
case DebPkg:
return "deb"
case DotnetPkg:
return "dotnet"
case ErlangOTPPkg:
return packageurl.TypeOTP
case GemPkg:
return packageurl.TypeGem
case HexPkg:
return packageurl.TypeHex
case GithubActionPkg, GithubActionWorkflowPkg:
// note: this is not a real purl type, but it is the closest thing we have for now
return packageurl.TypeGithub
case GoModulePkg:
return packageurl.TypeGolang
case HackagePkg:
return packageurl.TypeHackage
case JavaPkg, JenkinsPluginPkg:
return packageurl.TypeMaven
case LinuxKernelPkg:
return "generic/linux-kernel"
case LinuxKernelModulePkg:
return packageurl.TypeGeneric
case PhpComposerPkg:
return packageurl.TypeComposer
case PhpPeclPkg:
return "pecl"
case PythonPkg:
return packageurl.TypePyPi
case PortagePkg:
return "portage"
case LuaRocksPkg:
return packageurl.TypeLuaRocks
case NixPkg:
return "nix"
case NpmPkg:
return packageurl.TypeNPM
case OpamPkg:
return "opam"
case Rpkg:
return packageurl.TypeCran
case RpmPkg:
return packageurl.TypeRPM
case RustPkg:
return "cargo"
case SwiftPkg:
return packageurl.TypeSwift
case SwiplPackPkg:
return "swiplpack"
case TerraformPkg:
return "terraform"
case WordpressPluginPkg:
return "wordpress-plugin"
default:
// TODO: should this be a "generic" purl type instead?
return ""
}
}
func TypeFromPURL(p string) Type {
purl, err := packageurl.FromString(p)
if err != nil {
return UnknownPkg
}
ptype := purl.Type
if ptype == "generic" {
ptype = purl.Name
}
return TypeByName(ptype)
}
//nolint:funlen,gocyclo
func TypeByName(name string) Type {
switch name {
case "alpm":
return AlpmPkg
case packageurl.TypeAlpine, "alpine":
return ApkPkg
case packageurl.TypeBitnami:
return BitnamiPkg
case packageurl.TypeDebian:
return DebPkg
case packageurl.TypeComposer:
return PhpComposerPkg
case "pecl":
return PhpPeclPkg
case packageurl.TypeGolang:
return GoModulePkg
case packageurl.TypeGem:
return GemPkg
case "cargo", "crate":
return RustPkg
case packageurl.TypePub:
return DartPubPkg
case "dotnet": // here to support legacy use cases
return DotnetPkg
case packageurl.TypeCocoapods:
return CocoapodsPkg
case packageurl.TypeConan:
return ConanPkg
case packageurl.TypeHackage:
return HackagePkg
case packageurl.TypeHex:
return HexPkg
case packageurl.TypeLuaRocks:
return LuaRocksPkg
case packageurl.TypeMaven:
return JavaPkg
case packageurl.TypeNPM:
return NpmPkg
case packageurl.TypePyPi:
return PythonPkg
case "portage":
return PortagePkg
case packageurl.TypeOTP:
return ErlangOTPPkg
case "linux-kernel":
return LinuxKernelPkg
case "linux-kernel-module":
return LinuxKernelModulePkg
case "nix":
return NixPkg
case "opam":
return OpamPkg
case packageurl.TypeCran:
return Rpkg
case packageurl.TypeRPM:
return RpmPkg
case packageurl.TypeSwift:
return SwiftPkg
case "swiplpack":
return SwiplPackPkg
case "terraform":
return TerraformPkg
case "wordpress-plugin":
return WordpressPluginPkg
default:
return UnknownPkg
}
}