Skip to content

Commit

Permalink
Code changes and cleanups as requested by @arminc
Browse files Browse the repository at this point in the history
  • Loading branch information
plasticine committed Jan 7, 2018
1 parent 50c5e71 commit ec50ae3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 38 deletions.
13 changes: 2 additions & 11 deletions reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,6 @@ type vulnerabilityReport struct {
Vulnerabilities []vulnerabilityInfo `json:"vulnerabilities"`
}

type ReportTableRow struct {
Severity string
Feature string
Details string
Description string
}

type ReportTableData [][]ReportTableRow

func sortBySeverity(vulnerabilities []vulnerabilityInfo) {
sort.Slice(vulnerabilities, func(i, j int) bool {
return SeverityMap[vulnerabilities[i].Severity] < SeverityMap[vulnerabilities[j].Severity]
Expand Down Expand Up @@ -96,13 +87,13 @@ func reportToConsole(imageName string, vulnerabilities []vulnerabilityInfo, unap
logger.Errorf("Image [%s] contains %d unapproved vulnerabilities", imageName, len(unapproved))
printTable(vulnerabilities, unapproved)
} else {
logger.Infof("Image [%s] contains %d unapproved vulnerabilities", imageName, len(unapproved))
logger.Infof("Image [%s] contains NO unapproved vulnerabilities", imageName)
if reportAll {
printTable(vulnerabilities, unapproved)
}
}
} else {
logger.Infof("Image [%s] contains %d total vulnerabilities", imageName, len(vulnerabilities))
logger.Infof("Image [%s] contains NO unapproved vulnerabilities", imageName)
}
}

Expand Down
12 changes: 0 additions & 12 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ type scannerConfig struct {
reportAll bool
}

var SeverityMap = map[string]int{
"Defcon1": 1,
"Critical": 2,
"High": 3,
"Medium": 4,
"Low": 5,
"Negligible": 6,
"Unknown": 7,
}

// scan orchestrates the scanning process of an image
func scan(config scannerConfig) []string {
//Create a temporary folder where the docker image layers are going to be stored
Expand Down Expand Up @@ -69,8 +59,6 @@ func checkForUnapprovedVulnerabilities(imageName string, vulnerabilities []vulne
severity := vulnerabilities[i].Severity
vulnerable := true

// logger.Infof("%s %s %s %s", severity, SeverityMap[severity], whitelistThreshold, SeverityMap[whitelistThreshold])

//Check if the vulnerability has a severity less than our threshold severity
if SeverityMap[severity] > SeverityMap[whitelistThreshold] {
vulnerable = false
Expand Down
28 changes: 13 additions & 15 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ const (
DebugColor = "\033[0;36m%s\033[0m"
)

// Exported var used as mapping on CVE severity name to implied ranking
var SeverityMap = map[string]int{
"Defcon1": 1,
"Critical": 2,
"High": 3,
"Medium": 4,
"Low": 5,
"Negligible": 6,
"Unknown": 7,
}

// listenForSignal listens for interactions and executes the desired code when it happens
func listenForSignal(fn func(os.Signal)) {
signalChannel := make(chan os.Signal, 0)
Expand Down Expand Up @@ -89,23 +100,10 @@ func parseWhitelistFile(whitelistFile string) vulnerabilitiesWhitelist {

// Validate that the given CVE severity threshold is a valid severity
func validateThreshold(threshold string) {
valid := false
for severity := range SeverityMap {
if threshold == severity {
valid = true
}
}
if !valid {
logger.Fatalf("Invalid CVE severity threshold %s given", threshold)
}
}

func Filter(vs []string, f func(string) bool) []string {
vsf := make([]string, 0)
for _, v := range vs {
if f(v) {
vsf = append(vsf, v)
return
}
}
return vsf
logger.Fatalf("Invalid CVE severity threshold %s given", threshold)
}

0 comments on commit ec50ae3

Please sign in to comment.