-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtrivyRunner.go
More file actions
39 lines (31 loc) · 1000 Bytes
/
trivyRunner.go
File metadata and controls
39 lines (31 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package tools
import (
"codacy/cli-v2/config"
"os"
"os/exec"
"path/filepath"
)
// RunTrivy executes Trivy vulnerability scanner with the specified options
func RunTrivy(repositoryToAnalyseDirectory string, trivyBinary string, pathsToCheck []string, outputFile string, outputFormat string) error {
cmd := exec.Command(trivyBinary, "fs")
// Add config file from tools-configs directory
configFile := filepath.Join(config.Config.ToolsConfigDirectory(), "trivy.yaml")
cmd.Args = append(cmd.Args, "--config", configFile)
// Add format options
if outputFile != "" {
cmd.Args = append(cmd.Args, "--output", outputFile)
}
if outputFormat == "sarif" {
cmd.Args = append(cmd.Args, "--format", "sarif")
}
// Add specific targets or use current directory
if len(pathsToCheck) > 0 {
cmd.Args = append(cmd.Args, pathsToCheck...)
} else {
cmd.Args = append(cmd.Args, ".")
}
cmd.Dir = repositoryToAnalyseDirectory
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
return cmd.Run()
}