diff --git a/pkg/fanal/analyzer/language/python/pipenv/pipenv.go b/pkg/fanal/analyzer/language/python/pipenv/pipenv.go index 06fc1f35dccf..aa82480bf4f5 100644 --- a/pkg/fanal/analyzer/language/python/pipenv/pipenv.go +++ b/pkg/fanal/analyzer/language/python/pipenv/pipenv.go @@ -4,6 +4,7 @@ import ( "context" "os" "path/filepath" + "slices" "golang.org/x/xerrors" @@ -11,7 +12,6 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/analyzer" "github.com/aquasecurity/trivy/pkg/fanal/analyzer/language" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) func init() { @@ -34,7 +34,7 @@ func (a pipenvLibraryAnalyzer) Analyze(_ context.Context, input analyzer.Analysi func (a pipenvLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool { fileName := filepath.Base(filePath) - return utils.StringInSlice(fileName, requiredFiles) + return slices.Contains(requiredFiles, fileName) } func (a pipenvLibraryAnalyzer) Type() analyzer.Type { diff --git a/pkg/fanal/analyzer/os/amazonlinux/amazonlinux.go b/pkg/fanal/analyzer/os/amazonlinux/amazonlinux.go index 2dc96646719f..1c3302088e80 100644 --- a/pkg/fanal/analyzer/os/amazonlinux/amazonlinux.go +++ b/pkg/fanal/analyzer/os/amazonlinux/amazonlinux.go @@ -5,6 +5,7 @@ import ( "context" "io" "os" + "slices" "strings" "golang.org/x/xerrors" @@ -12,7 +13,6 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) func init() { @@ -63,7 +63,7 @@ func (a amazonlinuxOSAnalyzer) parseRelease(r io.Reader) (types.OS, error) { } func (a amazonlinuxOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, requiredFiles) + return slices.Contains(requiredFiles, filePath) } func (a amazonlinuxOSAnalyzer) Type() analyzer.Type { diff --git a/pkg/fanal/analyzer/os/debian/debian.go b/pkg/fanal/analyzer/os/debian/debian.go index 5c5f3c766229..8d6c7a9014df 100644 --- a/pkg/fanal/analyzer/os/debian/debian.go +++ b/pkg/fanal/analyzer/os/debian/debian.go @@ -4,13 +4,13 @@ import ( "bufio" "context" "os" + "slices" "golang.org/x/xerrors" "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) func init() { @@ -38,7 +38,7 @@ func (a debianOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInpu } func (a debianOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, requiredFiles) + return slices.Contains(requiredFiles, filePath) } func (a debianOSAnalyzer) Type() analyzer.Type { diff --git a/pkg/fanal/analyzer/os/redhatbase/alma.go b/pkg/fanal/analyzer/os/redhatbase/alma.go index eddf7d82f80b..11b4aa94008b 100644 --- a/pkg/fanal/analyzer/os/redhatbase/alma.go +++ b/pkg/fanal/analyzer/os/redhatbase/alma.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "os" + "slices" "strings" "golang.org/x/xerrors" @@ -11,7 +12,6 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) const almaAnalyzerVersion = 1 @@ -46,7 +46,7 @@ func (a almaOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) } func (a almaOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, a.requiredFiles()) + return slices.Contains(a.requiredFiles(), filePath) } func (a almaOSAnalyzer) requiredFiles() []string { diff --git a/pkg/fanal/analyzer/os/redhatbase/centos.go b/pkg/fanal/analyzer/os/redhatbase/centos.go index 4a57e3e9eac1..2401e6a76b21 100644 --- a/pkg/fanal/analyzer/os/redhatbase/centos.go +++ b/pkg/fanal/analyzer/os/redhatbase/centos.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "os" + "slices" "strings" "golang.org/x/xerrors" @@ -11,7 +12,6 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) const centosAnalyzerVersion = 1 @@ -46,7 +46,7 @@ func (a centOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) } func (a centOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, a.requiredFiles()) + return slices.Contains(a.requiredFiles(), filePath) } func (a centOSAnalyzer) requiredFiles() []string { diff --git a/pkg/fanal/analyzer/os/redhatbase/fedora.go b/pkg/fanal/analyzer/os/redhatbase/fedora.go index d5b2458e1c5b..1391544ccf75 100644 --- a/pkg/fanal/analyzer/os/redhatbase/fedora.go +++ b/pkg/fanal/analyzer/os/redhatbase/fedora.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "os" + "slices" "strings" "golang.org/x/xerrors" @@ -11,7 +12,6 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) const fedoraAnalyzerVersion = 1 @@ -45,7 +45,7 @@ func (a fedoraOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInpu } func (a fedoraOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, a.requiredFiles()) + return slices.Contains(a.requiredFiles(), filePath) } func (a fedoraOSAnalyzer) requiredFiles() []string { diff --git a/pkg/fanal/analyzer/os/redhatbase/oracle.go b/pkg/fanal/analyzer/os/redhatbase/oracle.go index 90864aefd848..d487b1bae9aa 100644 --- a/pkg/fanal/analyzer/os/redhatbase/oracle.go +++ b/pkg/fanal/analyzer/os/redhatbase/oracle.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "os" + "slices" "strings" "golang.org/x/xerrors" @@ -11,7 +12,6 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) const oracleAnalyzerVersion = 1 @@ -42,7 +42,7 @@ func (a oracleOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInpu } func (a oracleOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, a.requiredFiles()) + return slices.Contains(a.requiredFiles(), filePath) } func (a oracleOSAnalyzer) requiredFiles() []string { diff --git a/pkg/fanal/analyzer/os/redhatbase/redhatbase.go b/pkg/fanal/analyzer/os/redhatbase/redhatbase.go index 9fc69a8753ca..f3a9df357bab 100644 --- a/pkg/fanal/analyzer/os/redhatbase/redhatbase.go +++ b/pkg/fanal/analyzer/os/redhatbase/redhatbase.go @@ -6,6 +6,7 @@ import ( "io" "os" "regexp" + "slices" "strings" "golang.org/x/xerrors" @@ -13,7 +14,6 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) const redhatAnalyzerVersion = 1 @@ -83,7 +83,7 @@ func (a redhatOSAnalyzer) parseRelease(r io.Reader) (types.OS, error) { } func (a redhatOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, a.requiredFiles()) + return slices.Contains(a.requiredFiles(), filePath) } func (a redhatOSAnalyzer) requiredFiles() []string { diff --git a/pkg/fanal/analyzer/os/redhatbase/rocky.go b/pkg/fanal/analyzer/os/redhatbase/rocky.go index ac443d29ae83..95043ec2d3c3 100644 --- a/pkg/fanal/analyzer/os/redhatbase/rocky.go +++ b/pkg/fanal/analyzer/os/redhatbase/rocky.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "os" + "slices" "strings" "golang.org/x/xerrors" @@ -11,7 +12,6 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/analyzer" fos "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" ) const rockyAnalyzerVersion = 1 @@ -46,7 +46,7 @@ func (a rockyOSAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput } func (a rockyOSAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, a.requiredFiles()) + return slices.Contains(a.requiredFiles(), filePath) } func (a rockyOSAnalyzer) requiredFiles() []string { diff --git a/pkg/fanal/analyzer/pkg/rpm/rpm.go b/pkg/fanal/analyzer/pkg/rpm/rpm.go index 70d4de217418..54caec1994b2 100644 --- a/pkg/fanal/analyzer/pkg/rpm/rpm.go +++ b/pkg/fanal/analyzer/pkg/rpm/rpm.go @@ -17,7 +17,6 @@ import ( "github.com/aquasecurity/trivy/pkg/digest" "github.com/aquasecurity/trivy/pkg/fanal/analyzer" "github.com/aquasecurity/trivy/pkg/fanal/types" - "github.com/aquasecurity/trivy/pkg/fanal/utils" "github.com/aquasecurity/trivy/pkg/log" ) @@ -198,7 +197,7 @@ func (a rpmPkgAnalyzer) listPkgs(ctx context.Context, db RPMDB) (types.Packages, } func (a rpmPkgAnalyzer) Required(filePath string, _ os.FileInfo) bool { - return utils.StringInSlice(filePath, requiredFiles) + return slices.Contains(requiredFiles, filePath) } func (a rpmPkgAnalyzer) Type() analyzer.Type { diff --git a/pkg/fanal/utils/utils.go b/pkg/fanal/utils/utils.go index 4e82a9d01ab7..5f96990cd703 100644 --- a/pkg/fanal/utils/utils.go +++ b/pkg/fanal/utils/utils.go @@ -32,15 +32,6 @@ func CacheDir() string { return cacheDir } -func StringInSlice(a string, list []string) bool { - for _, b := range list { - if b == a { - return true - } - } - return false -} - func IsCommandAvailable(name string) bool { if _, err := exec.LookPath(name); err != nil { return false