mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 17:03:17 +01:00
* add github actions usage cataloger Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * update integration and cli tests with github actions sample Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add support for shared workflows Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * split github actions usage cataloger Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * add source explanation for github action types Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * a github purl does not always mean the package is a github action Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> * keep github action catalogers as dir only catalogers Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> --------- Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
201 lines
4.6 KiB
Go
201 lines
4.6 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"
|
|
CocoapodsPkg Type = "pod"
|
|
ConanPkg Type = "conan"
|
|
DartPubPkg Type = "dart-pub"
|
|
DebPkg Type = "deb"
|
|
DotnetPkg Type = "dotnet"
|
|
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"
|
|
PhpComposerPkg Type = "php-composer"
|
|
PortagePkg Type = "portage"
|
|
PythonPkg Type = "python"
|
|
Rpkg Type = "R-package"
|
|
RpmPkg Type = "rpm"
|
|
RustPkg Type = "rust-crate"
|
|
SwiftPkg Type = "swift"
|
|
)
|
|
|
|
// AllPkgs represents all supported package types
|
|
var AllPkgs = []Type{
|
|
AlpmPkg,
|
|
ApkPkg,
|
|
BinaryPkg,
|
|
CocoapodsPkg,
|
|
ConanPkg,
|
|
DartPubPkg,
|
|
DebPkg,
|
|
DotnetPkg,
|
|
GemPkg,
|
|
GithubActionPkg,
|
|
GithubActionWorkflowPkg,
|
|
GoModulePkg,
|
|
HackagePkg,
|
|
HexPkg,
|
|
JavaPkg,
|
|
JenkinsPluginPkg,
|
|
KbPkg,
|
|
LinuxKernelPkg,
|
|
LinuxKernelModulePkg,
|
|
NixPkg,
|
|
NpmPkg,
|
|
PhpComposerPkg,
|
|
PortagePkg,
|
|
PythonPkg,
|
|
Rpkg,
|
|
RpmPkg,
|
|
RustPkg,
|
|
SwiftPkg,
|
|
}
|
|
|
|
// PackageURLType returns the PURL package type for the current package.
|
|
//
|
|
//nolint:funlen
|
|
func (t Type) PackageURLType() string {
|
|
switch t {
|
|
case AlpmPkg:
|
|
return "alpm"
|
|
case ApkPkg:
|
|
return packageurl.TypeAlpine
|
|
case CocoapodsPkg:
|
|
return packageurl.TypeCocoapods
|
|
case ConanPkg:
|
|
return packageurl.TypeConan
|
|
case DartPubPkg:
|
|
return packageurl.TypePub
|
|
case DebPkg:
|
|
return "deb"
|
|
case DotnetPkg:
|
|
return packageurl.TypeDotnet
|
|
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 PythonPkg:
|
|
return packageurl.TypePyPi
|
|
case PortagePkg:
|
|
return "portage"
|
|
case NixPkg:
|
|
return "nix"
|
|
case NpmPkg:
|
|
return packageurl.TypeNPM
|
|
case Rpkg:
|
|
return packageurl.TypeCran
|
|
case RpmPkg:
|
|
return packageurl.TypeRPM
|
|
case RustPkg:
|
|
return "cargo"
|
|
case SwiftPkg:
|
|
return packageurl.TypeSwift
|
|
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)
|
|
}
|
|
|
|
func TypeByName(name string) Type {
|
|
switch name {
|
|
case packageurl.TypeDebian:
|
|
return DebPkg
|
|
case packageurl.TypeRPM:
|
|
return RpmPkg
|
|
case "alpm":
|
|
return AlpmPkg
|
|
case packageurl.TypeAlpine, "alpine":
|
|
return ApkPkg
|
|
case packageurl.TypeMaven:
|
|
return JavaPkg
|
|
case packageurl.TypeComposer:
|
|
return PhpComposerPkg
|
|
case packageurl.TypeGolang:
|
|
return GoModulePkg
|
|
case packageurl.TypeNPM:
|
|
return NpmPkg
|
|
case packageurl.TypePyPi:
|
|
return PythonPkg
|
|
case packageurl.TypeGem:
|
|
return GemPkg
|
|
case "cargo", "crate":
|
|
return RustPkg
|
|
case packageurl.TypePub:
|
|
return DartPubPkg
|
|
case packageurl.TypeDotnet:
|
|
return DotnetPkg
|
|
case packageurl.TypeCocoapods:
|
|
return CocoapodsPkg
|
|
case packageurl.TypeConan:
|
|
return ConanPkg
|
|
case packageurl.TypeHackage:
|
|
return HackagePkg
|
|
case "portage":
|
|
return PortagePkg
|
|
case packageurl.TypeHex:
|
|
return HexPkg
|
|
case "linux-kernel":
|
|
return LinuxKernelPkg
|
|
case "linux-kernel-module":
|
|
return LinuxKernelModulePkg
|
|
case "nix":
|
|
return NixPkg
|
|
case packageurl.TypeCran:
|
|
return Rpkg
|
|
case packageurl.TypeSwift:
|
|
return SwiftPkg
|
|
default:
|
|
return UnknownPkg
|
|
}
|
|
}
|