Skip to content

Commit 5996608

Browse files
committed
Revert "feature: Only consider specific files for Trivy CF-1742"
This reverts commit 3ff97a7. This was not working properly due timings of configs
1 parent 3aa49ba commit 5996608

File tree

7 files changed

+39
-119
lines changed

7 files changed

+39
-119
lines changed

plugins/runtime-utils_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ func TestProcessRuntimes(t *testing.T) {
6969
// Assert the download URL is correctly formatted
7070
expectedDownloadURL := "https://nodejs.org/dist/v18.17.1/" + expectedFileName + "." + expectedExtension
7171
assert.Equal(t, expectedDownloadURL, nodeInfo.DownloadURL)
72-
72+
7373
// Assert binary paths are correctly set
7474
assert.NotNil(t, nodeInfo.Binaries)
7575
assert.Greater(t, len(nodeInfo.Binaries), 0)
76-
76+
7777
// Check if node and npm binaries are present
7878
nodeBinary := nodeInfo.InstallDir + "/bin/node"
7979
npmBinary := nodeInfo.InstallDir + "/bin/npm"
80-
80+
8181
// Add .exe extension for Windows
8282
if runtime.GOOS == "windows" {
8383
nodeBinary += ".exe"
8484
npmBinary += ".exe"
8585
}
86-
86+
8787
assert.Equal(t, nodeBinary, nodeInfo.Binaries["node"])
8888
assert.Equal(t, npmBinary, nodeInfo.Binaries["npm"])
8989
}

plugins/tool-utils.go

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,18 @@ type RuntimeBinaries struct {
5555

5656
// ToolPluginConfig holds the structure of the tool plugin.yaml file
5757
type ToolPluginConfig struct {
58-
Name string `yaml:"name"`
59-
Description string `yaml:"description"`
60-
DefaultVersion string `yaml:"default_version"`
61-
SupportsSpecificFiles bool `yaml:"support_specific_files"`
62-
Runtime string `yaml:"runtime"`
63-
RuntimeBinaries RuntimeBinaries `yaml:"runtime_binaries"`
64-
Installation InstallationConfig `yaml:"installation"`
65-
Download DownloadConfig `yaml:"download"`
66-
Environment map[string]string `yaml:"environment"`
67-
Binaries []ToolBinary `yaml:"binaries"`
68-
Formatters []Formatter `yaml:"formatters"`
69-
OutputOptions OutputOptions `yaml:"output_options"`
70-
AnalysisOptions AnalysisOptions `yaml:"analysis_options"`
58+
Name string `yaml:"name"`
59+
Description string `yaml:"description"`
60+
DefaultVersion string `yaml:"default_version"`
61+
Runtime string `yaml:"runtime"`
62+
RuntimeBinaries RuntimeBinaries `yaml:"runtime_binaries"`
63+
Installation InstallationConfig `yaml:"installation"`
64+
Download DownloadConfig `yaml:"download"`
65+
Environment map[string]string `yaml:"environment"`
66+
Binaries []ToolBinary `yaml:"binaries"`
67+
Formatters []Formatter `yaml:"formatters"`
68+
OutputOptions OutputOptions `yaml:"output_options"`
69+
AnalysisOptions AnalysisOptions `yaml:"analysis_options"`
7170
}
7271

7372
// ToolConfig represents configuration for a tool
@@ -79,16 +78,15 @@ type ToolConfig struct {
7978

8079
// ToolInfo contains all processed information about a tool
8180
type ToolInfo struct {
82-
Name string
83-
Version string
84-
Runtime string
85-
InstallDir string
86-
Binaries map[string]string // Map of binary name to full path
87-
Formatters map[string]string // Map of formatter name to flag
88-
OutputFlag string
89-
AutofixFlag string
90-
DefaultPath string
91-
SupportsSpecificFiles bool // Whether tool supports specific file analysis
81+
Name string
82+
Version string
83+
Runtime string
84+
InstallDir string
85+
Binaries map[string]string // Map of binary name to full path
86+
Formatters map[string]string // Map of formatter name to flag
87+
OutputFlag string
88+
AutofixFlag string
89+
DefaultPath string
9290
// Runtime binaries
9391
PackageManager string
9492
ExecutionBinary string
@@ -137,16 +135,15 @@ func ProcessTools(configs []ToolConfig, toolDir string, runtimes map[string]*Run
137135
}
138136
// Create ToolInfo with basic information
139137
info := &ToolInfo{
140-
Name: config.Name,
141-
Version: config.Version,
142-
Runtime: toolRuntime,
143-
InstallDir: installDir,
144-
Binaries: make(map[string]string),
145-
Formatters: make(map[string]string),
146-
OutputFlag: pluginConfig.OutputOptions.FileFlag,
147-
AutofixFlag: pluginConfig.AnalysisOptions.AutofixFlag,
148-
DefaultPath: pluginConfig.AnalysisOptions.DefaultPath,
149-
SupportsSpecificFiles: pluginConfig.SupportsSpecificFiles,
138+
Name: config.Name,
139+
Version: config.Version,
140+
Runtime: toolRuntime,
141+
InstallDir: installDir,
142+
Binaries: make(map[string]string),
143+
Formatters: make(map[string]string),
144+
OutputFlag: pluginConfig.OutputOptions.FileFlag,
145+
AutofixFlag: pluginConfig.AnalysisOptions.AutofixFlag,
146+
DefaultPath: pluginConfig.AnalysisOptions.DefaultPath,
150147
// Store runtime binary information
151148
PackageManager: pluginConfig.RuntimeBinaries.PackageManager,
152149
ExecutionBinary: pluginConfig.RuntimeBinaries.Execution,

plugins/tool-utils_test.go

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ func TestProcessTools(t *testing.T) {
6666
// Assert installation command templates are correctly set
6767
assert.Equal(t, "install --prefix {{.InstallDir}} {{.PackageName}}@{{.Version}} @microsoft/eslint-formatter-sarif", eslintInfo.InstallCommand)
6868
assert.Equal(t, "config set registry {{.Registry}}", eslintInfo.RegistryCommand)
69-
70-
// Assert that eslint does not support specific files (default false)
71-
assert.False(t, eslintInfo.SupportsSpecificFiles, "eslint should not support specific files")
7269
}
7370

7471
func TestProcessToolsWithDownload(t *testing.T) {
@@ -123,9 +120,6 @@ func TestProcessToolsWithDownload(t *testing.T) {
123120
trivyBinary := filepath.Join(expectedInstallDir, "trivy")
124121
assert.Equal(t, trivyBinary, trivyInfo.Binaries["trivy"])
125122

126-
// Assert that trivy supports specific files (from plugin.yaml)
127-
assert.True(t, trivyInfo.SupportsSpecificFiles, "trivy should support specific files")
128-
129123
// Verify URL components
130124
assert.Contains(t, trivyInfo.DownloadURL, "aquasecurity/trivy/releases/download")
131125
assert.Contains(t, trivyInfo.DownloadURL, trivyInfo.Version)
@@ -205,47 +199,3 @@ func TestGetSupportedTools(t *testing.T) {
205199
})
206200
}
207201
}
208-
209-
func TestGetToolConfig(t *testing.T) {
210-
pluginManager := GetPluginManager()
211-
212-
tests := []struct {
213-
name string
214-
toolName string
215-
expectedSupportsSpecificFiles bool
216-
expectedError bool
217-
}{
218-
{
219-
name: "trivy should support specific files",
220-
toolName: "trivy",
221-
expectedSupportsSpecificFiles: true,
222-
expectedError: false,
223-
},
224-
{
225-
name: "eslint should not support specific files",
226-
toolName: "eslint",
227-
expectedSupportsSpecificFiles: false,
228-
expectedError: false,
229-
},
230-
{
231-
name: "non-existent tool should return error",
232-
toolName: "non-existent-tool",
233-
expectedError: true,
234-
},
235-
}
236-
237-
for _, tt := range tests {
238-
t.Run(tt.name, func(t *testing.T) {
239-
config, err := pluginManager.GetToolConfig(tt.toolName)
240-
241-
if tt.expectedError {
242-
assert.Error(t, err)
243-
return
244-
}
245-
246-
assert.NoError(t, err)
247-
assert.Equal(t, tt.expectedSupportsSpecificFiles, config.SupportsSpecificFiles,
248-
"SupportsSpecificFiles should match expected value for %s", tt.toolName)
249-
})
250-
}
251-
}

plugins/tools/trivy/plugin.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: trivy
22
description: Trivy is a comprehensive security scanner for containers and other artifacts.
33
default_version: 0.59.1
4-
support_specific_files: true
54
download:
65
url_template: "https://github.com/aquasecurity/trivy/releases/download/v{{.Version}}/trivy_{{.Version}}_{{.OS}}-{{.Arch}}.{{.Extension}}"
76
file_name_template: "trivy_{{.Version}}_{{.OS}}_{{.Arch}}"

plugins/tools/trivy/test/src/.codacy/tools-configs/languages-config.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

plugins/tools/trivy/test/src/.codacy/tools-configs/trivy.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

tools/language_config.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,16 @@ func buildToolLanguageInfoFromAPI() (map[string]domain.ToolLanguageInfo, error)
8383
extensionsSet := make(map[string]struct{})
8484
filesSet := make(map[string]struct{})
8585

86-
// Check if this tool supports specific files
87-
toolInfo := config.Config.Tools()[toolName]
88-
supportsSpecificFiles := toolInfo != nil && toolInfo.SupportsSpecificFiles
89-
9086
for _, apiLang := range tool.Languages {
9187
lowerLang := strings.ToLower(apiLang)
9288
if extensions, exists := languageExtensionsMap[lowerLang]; exists {
9389
for _, ext := range extensions {
9490
extensionsSet[ext] = struct{}{}
9591
}
9692
}
97-
// Only populate files if the tool supports specific files
98-
if supportsSpecificFiles {
99-
if files, exists := languageFilesMap[lowerLang]; exists {
100-
for _, file := range files {
101-
filesSet[file] = struct{}{}
102-
}
93+
if files, exists := languageFilesMap[lowerLang]; exists {
94+
for _, file := range files {
95+
filesSet[file] = struct{}{}
10396
}
10497
}
10598
}
@@ -252,16 +245,12 @@ func buildRemoteModeLanguagesConfig(apiTools []domain.Tool, toolIDMap map[string
252245
extensionsSet := make(map[string]struct{})
253246
filesSet := make(map[string]struct{})
254247

255-
// Check if this tool supports specific files
256-
toolInfo := config.Config.Tools()[shortName]
257-
supportsSpecificFiles := toolInfo != nil && toolInfo.SupportsSpecificFiles
258-
259248
for _, lang := range tool.Languages {
260249
lowerLang := strings.ToLower(lang)
261250
if repoLang, exists := repositoryLanguages[lowerLang]; exists {
262251
// Check if this language has either extensions or files
263252
hasExtensions := len(repoLang.Extensions) > 0
264-
hasFiles := len(repoLang.Files) > 0 && supportsSpecificFiles
253+
hasFiles := len(repoLang.Files) > 0
265254

266255
if hasExtensions || hasFiles {
267256
configTool.Languages = append(configTool.Languages, lang)
@@ -273,7 +262,7 @@ func buildRemoteModeLanguagesConfig(apiTools []domain.Tool, toolIDMap map[string
273262
}
274263
}
275264

276-
// Add repository-specific files if they exist (only if tool supports it)
265+
// Add repository-specific files if they exist
277266
if hasFiles {
278267
for _, file := range repoLang.Files {
279268
filesSet[file] = struct{}{}

0 commit comments

Comments
 (0)