1515 dockerfilePath string
1616 outputFormat string
1717 outputPath string
18+ failOnSeverity string
1819)
1920
2021var scanCmd = & cobra.Command {
@@ -66,15 +67,36 @@ Supports multiple output formats:
6667 return fmt .Errorf ("failed to generate report: %w" , err )
6768 }
6869
69- // Exit with error code if high severity issues found (for CI/CD)
70- if hasHighSeverity (findings ) {
71- return fmt .Errorf ("found high severity issues" )
70+ // Exit with error code based on severity threshold (for CI/CD)
71+ if shouldFail (findings , failOnSeverity ) {
72+ return fmt .Errorf ("found issues at or above '%s' severity" , failOnSeverity )
7273 }
7374
7475 return nil
7576 },
7677}
7778
79+ func shouldFail (findings []models.Finding , threshold string ) bool {
80+ if len (findings ) == 0 {
81+ return false
82+ }
83+
84+ severityLevels := map [string ]int {
85+ "low" : 1 ,
86+ "medium" : 2 ,
87+ "high" : 3 ,
88+ }
89+
90+ thresholdLevel := severityLevels [threshold ]
91+
92+ for _ , f := range findings {
93+ if severityLevels [f .Severity ] >= thresholdLevel {
94+ return true
95+ }
96+ }
97+ return false
98+ }
99+
78100func hasHighSeverity (findings []models.Finding ) bool {
79101 for _ , f := range findings {
80102 if f .Severity == "high" {
@@ -88,5 +110,6 @@ func init() {
88110 scanCmd .Flags ().StringVar (& dockerfilePath , "dockerfile" , "Dockerfile" , "Path to Dockerfile" )
89111 scanCmd .Flags ().StringVarP (& outputFormat , "format" , "f" , "text" , "Output format (text, json, sarif, html)" )
90112 scanCmd .Flags ().StringVarP (& outputPath , "output" , "o" , "" , "Output file path (default: stdout)" )
113+ scanCmd .Flags ().StringVar (& failOnSeverity , "fail-on-severity" , "medium" , "Fail if issues at or above this severity are found (low, medium, high)" )
91114 scanCmd .MarkFlagRequired ("dockerfile" )
92115}
0 commit comments