|
1 | 1 | package tools |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/json" |
5 | 4 | "fmt" |
6 | 5 | "os" |
7 | 6 | "os/exec" |
@@ -56,55 +55,3 @@ func RunTrivy(repositoryToAnalyseDirectory string, trivyBinary string, pathsToCh |
56 | 55 | // If outputting to file, just run the command |
57 | 56 | return cmd.Run() |
58 | 57 | } |
59 | | - |
60 | | -// TrivyJsonToSarif converts Trivy JSON output to SARIF format |
61 | | -// Note: This function is not needed when using Trivy's built-in SARIF output |
62 | | -// but is included for completeness if you need custom conversions |
63 | | -func TrivyJsonToSarif(trivyJsonFile string, sarifOutputFile string) error { |
64 | | - // Read Trivy JSON output |
65 | | - data, err := os.ReadFile(trivyJsonFile) |
66 | | - if err != nil { |
67 | | - return fmt.Errorf("failed to read Trivy JSON file: %w", err) |
68 | | - } |
69 | | - |
70 | | - // Parse Trivy JSON |
71 | | - var trivyResults map[string]interface{} |
72 | | - if err := json.Unmarshal(data, &trivyResults); err != nil { |
73 | | - return fmt.Errorf("failed to parse Trivy JSON: %w", err) |
74 | | - } |
75 | | - |
76 | | - // Build SARIF structure |
77 | | - sarif := map[string]interface{}{ |
78 | | - "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", |
79 | | - "version": "2.1.0", |
80 | | - "runs": []map[string]interface{}{ |
81 | | - { |
82 | | - "tool": map[string]interface{}{ |
83 | | - "driver": map[string]interface{}{ |
84 | | - "name": "Trivy", |
85 | | - "informationUri": "https://github.com/aquasecurity/trivy", |
86 | | - "semanticVersion": "1.0.0", |
87 | | - "rules": []interface{}{}, |
88 | | - }, |
89 | | - }, |
90 | | - "results": []interface{}{}, |
91 | | - }, |
92 | | - }, |
93 | | - } |
94 | | - |
95 | | - // Convert results and rules (simplified implementation) |
96 | | - // In a real implementation, you would iterate through Trivy results |
97 | | - // and convert each one to SARIF format |
98 | | - |
99 | | - // Write SARIF output |
100 | | - sarifData, err := json.MarshalIndent(sarif, "", " ") |
101 | | - if err != nil { |
102 | | - return fmt.Errorf("failed to marshal SARIF data: %w", err) |
103 | | - } |
104 | | - |
105 | | - if err := os.WriteFile(sarifOutputFile, sarifData, 0644); err != nil { |
106 | | - return fmt.Errorf("failed to write SARIF file: %w", err) |
107 | | - } |
108 | | - |
109 | | - return nil |
110 | | -} |
0 commit comments