Skip to content

Commit

Permalink
feat: add cloud k8s distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Oct 13, 2023
1 parent 7c98227 commit 24f2a8b
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pkg/detector/library/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewDriver(libType ftypes.LangType) (Driver, bool) {
case ftypes.Bitnami:
ecosystem = vulnerability.Bitnami
comparer = compare.GenericComparer{}
case ftypes.K8sComponent:
case ftypes.K8sUpstream:
ecosystem = vulnerability.Kubernetes
comparer = compare.GenericComparer{}
default:
Expand Down
64 changes: 35 additions & 29 deletions pkg/fanal/types/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,41 @@ const (

// Programming language dependencies
const (
Bundler LangType = "bundler"
GemSpec LangType = "gemspec"
Cargo LangType = "cargo"
Composer LangType = "composer"
Npm LangType = "npm"
NuGet LangType = "nuget"
DotNetCore LangType = "dotnet-core"
Pip LangType = "pip"
Pipenv LangType = "pipenv"
Poetry LangType = "poetry"
CondaPkg LangType = "conda-pkg"
PythonPkg LangType = "python-pkg"
NodePkg LangType = "node-pkg"
Yarn LangType = "yarn"
Pnpm LangType = "pnpm"
Jar LangType = "jar"
Pom LangType = "pom"
Gradle LangType = "gradle"
GoBinary LangType = "gobinary"
GoModule LangType = "gomod"
JavaScript LangType = "javascript"
RustBinary LangType = "rustbinary"
Conan LangType = "conan"
Cocoapods LangType = "cocoapods"
Swift LangType = "swift"
Pub LangType = "pub"
Hex LangType = "hex"
Bitnami LangType = "bitnami"
K8sComponent LangType = "kubernetes"
Bundler LangType = "bundler"
GemSpec LangType = "gemspec"
Cargo LangType = "cargo"
Composer LangType = "composer"
Npm LangType = "npm"
NuGet LangType = "nuget"
DotNetCore LangType = "dotnet-core"
Pip LangType = "pip"
Pipenv LangType = "pipenv"
Poetry LangType = "poetry"
CondaPkg LangType = "conda-pkg"
PythonPkg LangType = "python-pkg"
NodePkg LangType = "node-pkg"
Yarn LangType = "yarn"
Pnpm LangType = "pnpm"
Jar LangType = "jar"
Pom LangType = "pom"
Gradle LangType = "gradle"
GoBinary LangType = "gobinary"
GoModule LangType = "gomod"
JavaScript LangType = "javascript"
RustBinary LangType = "rustbinary"
Conan LangType = "conan"
Cocoapods LangType = "cocoapods"
Swift LangType = "swift"
Pub LangType = "pub"
Hex LangType = "hex"
Bitnami LangType = "bitnami"

K8sUpstream LangType = "kubernetes"
EKS LangType = "eks" // Amazon Elastic Kubernetes Service
GKE LangType = "gke" // Google Kubernetes Engine
AKS LangType = "aks" // Azure Kubernetes Service
RKE LangType = "rke" // Rancher Kubernetes Engine
OCP LangType = "ocp" // Red Hat OpenShift Container Platform
)

// Config files
Expand Down
16 changes: 13 additions & 3 deletions pkg/purl/purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,20 @@ func (p *PackageURL) LangType() ftypes.LangType {
case packageurl.TypeBitnami:
return ftypes.Bitnami
case TypeK8s:
if p.Namespace == "" {
return ftypes.K8sComponent
switch p.Namespace {
case NamespaceEKS:
return ftypes.EKS
case NamespaceGKE:
return ftypes.GKE
case NamespaceAKS:
return ftypes.AKS
case NamespaceRKE:
return ftypes.RKE
case NamespaceOCP:
return ftypes.OCP
case "":
return ftypes.Kubernetes
}
// Cloud k8s distributions, such as EKS, are not supported yet.
return TypeUnknown
default:
return TypeUnknown
Expand Down
44 changes: 44 additions & 0 deletions pkg/purl/purl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,47 @@ func TestPackage(t *testing.T) {
})
}
}

func TestPackageURL_LangType(t *testing.T) {
tests := []struct {
name string
purl packageurl.PackageURL
want ftypes.LangType
}{
{
name: "maven",
purl: packageurl.PackageURL{
Type: packageurl.TypeMaven,
Namespace: "org.springframework",
Name: "spring-core",
Version: "5.0.4.RELEASE",
},
want: ftypes.Jar,
},
{
name: "k8s",
purl: packageurl.PackageURL{
Type: purl.TypeK8s,
Name: "kubelet",
Version: "1.21.1",
},
want: ftypes.K8sUpstream,
},
{
name: "eks",
purl: packageurl.PackageURL{
Type: purl.TypeK8s,
Namespace: purl.NamespaceEKS,
Name: "kubelet",
Version: "1.21.1",
},
want: ftypes.EKS,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &purl.PackageURL{PackageURL: tt.purl}
assert.Equalf(t, tt.want, p.LangType(), "LangType()")
})
}
}
2 changes: 1 addition & 1 deletion pkg/sbom/cyclonedx/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestUnmarshaler_Unmarshal(t *testing.T) {
FilePath: "node-core-components",
},
{
Type: ftypes.K8sComponent,
Type: ftypes.K8sUpstream,
Libraries: ftypes.Packages{
{
Name: "k8s.io/apiserver",
Expand Down
12 changes: 6 additions & 6 deletions pkg/scanner/langpkg/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (

var (
PkgTargets = map[ftypes.LangType]string{
ftypes.PythonPkg: "Python",
ftypes.CondaPkg: "Conda",
ftypes.GemSpec: "Ruby",
ftypes.NodePkg: "Node.js",
ftypes.Jar: "Java",
ftypes.K8sComponent: "Kubernetes",
ftypes.PythonPkg: "Python",
ftypes.CondaPkg: "Conda",
ftypes.GemSpec: "Ruby",
ftypes.NodePkg: "Node.js",
ftypes.Jar: "Java",
ftypes.K8sUpstream: "Kubernetes",
}
)

Expand Down

0 comments on commit 24f2a8b

Please sign in to comment.