com.danielsomerfield.cvecheck.gradle.handlers.VulnerabilityCountResultHandler.groovy Maven / Gradle / Ivy
package com.danielsomerfield.cvecheck.gradle.handlers
import com.danielsomerfield.cvecheck.ScanResult
import com.danielsomerfield.cvecheck.ScanResultHandler
import org.gradle.api.GradleException
import org.slf4j.Logger
import org.slf4j.LoggerFactory
public class VulnerabilityCountResultHandler implements ScanResultHandler {
private final Logger logger = LoggerFactory.getLogger(this.getClass())
private final int allowedVulnerabilities;
VulnerabilityCountResultHandler(int allowedVulnerabilities = 0) {
this.allowedVulnerabilities = allowedVulnerabilities
}
@Override
def void handleScanResult(ScanResult scanResult) {
if (scanResult.vulnCount > allowedVulnerabilities) {
logger.info("Detected vulns!")
throw new GradleException("${scanResult.vulnCount} vulnerabilities were detected")
} else {
logger.info("No vulnerabilities detected.")
}
}
}