com.danielsomerfield.cvecheck.gradle.handlers.buildRules.CVSSOverallThresholdBuildRule.groovy Maven / Gradle / Ivy
package com.danielsomerfield.cvecheck.gradle.handlers.buildRules
import com.danielsomerfield.cvecheck.ScanResult
import com.danielsomerfield.cvecheck.Vulnerability
import static com.danielsomerfield.cvecheck.gradle.handlers.buildRules.RuleOutcome.Failed
import static com.danielsomerfield.cvecheck.gradle.handlers.buildRules.RuleOutcome.Passed
class CVSSOverallThresholdBuildRule implements BuildRule {
private float threshold;
CVSSOverallThresholdBuildRule(BuildRuleConfiguration configuration) {
//TODO: replace with default mechanism
this.threshold = configuration.threshold.value
}
@Override
RuleOutcome execute(final ScanResult result) {
float cvss = result.vulnerabilities.inject(0f) { float sum, Vulnerability vuln -> new Float(sum + vuln.cvssScore()) }
cvss > threshold ? Failed : Passed
}
@Override
String getName() {
"CVSS Overall Threshold"
}
}