Skip to content

Commit 54a3c12

Browse files
committed
use existing property and allow flexible severity failures
1 parent 9124904 commit 54a3c12

File tree

8 files changed

+71
-36
lines changed

8 files changed

+71
-36
lines changed

src/main/java/com/blackduck/integration/detect/configuration/DetectConfigurationFactory.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ public DetectToolFilter createToolFilter(RunDecision runDecision, BlackDuckDecis
237237
public RapidScanOptions createRapidScanOptions() {
238238
RapidCompareMode rapidCompareMode = detectConfiguration.getValue(DetectProperties.DETECT_BLACKDUCK_RAPID_COMPARE_MODE);
239239
BlackduckScanMode scanMode= detectConfiguration.getValue(DetectProperties.DETECT_BLACKDUCK_SCAN_MODE);
240+
List<PolicyRuleSeverityType> severitiesToFailPolicyCheck = detectConfiguration.getValue(DetectProperties.DETECT_POLICY_CHECK_FAIL_ON_SEVERITIES).representedValues();
240241
long detectTimeout = findTimeoutInSeconds();
241-
return new RapidScanOptions(rapidCompareMode, scanMode, detectTimeout);
242+
return new RapidScanOptions(rapidCompareMode, scanMode, detectTimeout, severitiesToFailPolicyCheck);
242243
}
243244

244245
public BlackduckScanMode createScanMode() {

src/main/java/com/blackduck/integration/detect/lifecycle/run/operation/OperationRunner.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.regex.Matcher;
2828
import java.util.regex.Pattern;
2929

30-
import com.blackduck.integration.blackduck.api.generated.enumeration.BomStatusScanStatusType;
3130
import org.apache.commons.codec.digest.DigestUtils;
3231
import org.apache.commons.lang3.StringUtils;
3332
import org.apache.http.entity.ContentType;
@@ -38,6 +37,7 @@
3837
import com.blackduck.integration.bdio.graph.ProjectDependencyGraph;
3938
import com.blackduck.integration.bdio.model.externalid.ExternalId;
4039
import com.blackduck.integration.blackduck.api.generated.discovery.ApiDiscovery;
40+
import com.blackduck.integration.blackduck.api.generated.enumeration.BomStatusScanStatusType;
4141
import com.blackduck.integration.blackduck.api.generated.enumeration.PolicyRuleSeverityType;
4242
import com.blackduck.integration.blackduck.api.generated.view.BomStatusScanView;
4343
import com.blackduck.integration.blackduck.api.generated.view.DeveloperScansScanView;
@@ -700,7 +700,9 @@ public List<DeveloperScansScanView> waitForRapidResults(BlackDuckRunData blackDu
700700
}
701701

702702
public final RapidScanResultSummary logRapidReport(List<DeveloperScansScanView> scanResults, BlackduckScanMode mode) throws OperationException {
703-
return auditLog.namedInternal("Print Rapid Mode Results", () -> new RapidModeLogReportOperation(exitCodePublisher, rapidScanResultAggregator, mode).perform(scanResults));
703+
List<PolicyRuleSeverityType> severitiesToFailPolicyCheck = detectConfigurationFactory.createRapidScanOptions().getSeveritiesToFailPolicyCheck();
704+
return auditLog.namedInternal("Print Rapid Mode Results", () ->
705+
new RapidModeLogReportOperation(exitCodePublisher, rapidScanResultAggregator, mode).perform(scanResults, severitiesToFailPolicyCheck));
704706
}
705707

706708
public final File generateRapidJsonFile(NameVersion projectNameVersion, List<DeveloperScansScanView> scanResults) throws OperationException {

src/main/java/com/blackduck/integration/detect/workflow/blackduck/developer/RapidModeLogReportOperation.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
88

9+
import com.blackduck.integration.blackduck.api.generated.enumeration.PolicyRuleSeverityType;
910
import com.blackduck.integration.blackduck.api.generated.view.DeveloperScansScanView;
1011
import com.blackduck.integration.detect.configuration.DetectUserFriendlyException;
1112
import com.blackduck.integration.detect.configuration.enumeration.BlackduckScanMode;
@@ -28,8 +29,8 @@ public RapidModeLogReportOperation(ExitCodePublisher exitCodePublisher, RapidSca
2829
this.scanMode = mode.displayName();
2930
}
3031

31-
public RapidScanResultSummary perform(List<DeveloperScansScanView> results) throws DetectUserFriendlyException {
32-
RapidScanAggregateResult aggregateResult = rapidScanResultAggregator.aggregateData(results);
32+
public RapidScanResultSummary perform(List<DeveloperScansScanView> results, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) throws DetectUserFriendlyException {
33+
RapidScanAggregateResult aggregateResult = rapidScanResultAggregator.aggregateData(results, severitiesToFailPolicyCheck);
3334
logger.info(String.format("%s:", scanMode + RapidScanDetectResult.NONPERSISTENT_SCAN_RESULT_DETAILS_HEADING));
3435
aggregateResult.logResult(new Slf4jIntLogger(logger));
3536
RapidScanResultSummary summary = aggregateResult.getSummary();

src/main/java/com/blackduck/integration/detect/workflow/blackduck/developer/RapidScanOptions.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package com.blackduck.integration.detect.workflow.blackduck.developer;
22

3+
import java.util.List;
4+
5+
import com.blackduck.integration.blackduck.api.generated.enumeration.PolicyRuleSeverityType;
36
import com.blackduck.integration.detect.configuration.enumeration.BlackduckScanMode;
47
import com.blackduck.integration.detect.configuration.enumeration.RapidCompareMode;
58

69
public class RapidScanOptions {
710
private final RapidCompareMode compareMode;
811
private final BlackduckScanMode scanMode;
912
private final long detectTimeout;
13+
private final List<PolicyRuleSeverityType> severitiesToFailPolicyCheck;
1014

11-
public RapidScanOptions(RapidCompareMode compareMode, BlackduckScanMode scanMode, long detectTimeout) {
15+
public RapidScanOptions(RapidCompareMode compareMode, BlackduckScanMode scanMode, long detectTimeout, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
1216
this.compareMode = compareMode;
1317
this.scanMode = scanMode;
1418
this.detectTimeout = detectTimeout;
19+
this.severitiesToFailPolicyCheck = severitiesToFailPolicyCheck;
1520
}
1621

1722
public RapidCompareMode getCompareMode() {
@@ -25,4 +30,8 @@ public BlackduckScanMode getScanMode() {
2530
public long getDetectTimeout() {
2631
return detectTimeout;
2732
}
33+
34+
public List<PolicyRuleSeverityType> getSeveritiesToFailPolicyCheck() {
35+
return severitiesToFailPolicyCheck;
36+
}
2837
}

src/main/java/com/blackduck/integration/detect/workflow/blackduck/developer/aggregate/RapidScanComponentGroupDetail.java

+19-11
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import java.util.Set;
66

77
import com.blackduck.integration.blackduck.api.generated.component.*;
8+
import com.blackduck.integration.blackduck.api.generated.enumeration.PolicyRuleSeverityType;
9+
810
import org.apache.commons.lang3.StringUtils;
911

1012
import com.blackduck.integration.blackduck.api.generated.view.DeveloperScansScanView;
1113

1214
public class RapidScanComponentGroupDetail {
1315

1416
private static final String POLICY_SEPARATOR = "/";
15-
private static final String POLICY_SEVERITY_BLOCKER = "BLOCKER";
16-
private static final String POLICY_SEVERITY_CRITICAL = "CRITICAL";
1717

1818
private final RapidScanDetailGroup group;
1919
private final Set<String> errorMessages = new LinkedHashSet<>();
@@ -86,12 +86,14 @@ public void addMessages(String errorMessage, String warningMessage) {
8686
// While it may be possible to reduce the overall message generation code in this class by pushing
8787
// some common pieces into a parent class or interface, it is likely not worth altering the libraries
8888
// as this may be temporary code.
89-
public void addComponentMessages(DeveloperScansScanView resultView, DeveloperScansScanItemsComponentViolatingPoliciesView componentPolicyViolation) {
89+
public void addComponentMessages(DeveloperScansScanView resultView, DeveloperScansScanItemsComponentViolatingPoliciesView componentPolicyViolation, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
9090
String baseMessage = getBaseMessage(resultView);
9191

9292
String errorMessage = "", warningMessage = "";
9393

94-
if (componentPolicyViolation.getPolicySeverity().equals(POLICY_SEVERITY_CRITICAL) || componentPolicyViolation.getPolicySeverity().equals(POLICY_SEVERITY_BLOCKER)) {
94+
if (severitiesToFailPolicyCheck.stream()
95+
.map(PolicyRuleSeverityType::name)
96+
.anyMatch(severity -> severity.equals(componentPolicyViolation.getPolicySeverity()))) {
9597
if (errorMessage.equals("")) {
9698
errorMessage = baseMessage;
9799
} else {
@@ -117,7 +119,7 @@ public void addComponentMessages(DeveloperScansScanView resultView, DeveloperSca
117119
// While it may be possible to reduce the overall message generation code in this class by pushing
118120
// some common pieces into a parent class or interface, it is likely not worth altering the libraries
119121
// as this may be temporary code.
120-
public void addLicenseMessages(DeveloperScansScanView resultView, DeveloperScansScanItemsPolicyViolationLicensesView licensePolicyViolation) {
122+
public void addLicenseMessages(DeveloperScansScanView resultView, DeveloperScansScanItemsPolicyViolationLicensesView licensePolicyViolation, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
121123
String baseMessage = getBaseMessage(resultView);
122124

123125
List<DeveloperScansScanItemsPolicyViolationLicensesViolatingPoliciesView> violatingPolicies = licensePolicyViolation.getViolatingPolicies();
@@ -126,8 +128,10 @@ public void addLicenseMessages(DeveloperScansScanView resultView, DeveloperScans
126128

127129
for (int i = 0; i < violatingPolicies.size(); i++) {
128130
DeveloperScansScanItemsPolicyViolationLicensesViolatingPoliciesView violation = violatingPolicies.get(i);
129-
130-
if (violation.getPolicySeverity().equals(POLICY_SEVERITY_CRITICAL) || violation.getPolicySeverity().equals(POLICY_SEVERITY_BLOCKER)) {
131+
132+
if (severitiesToFailPolicyCheck.stream()
133+
.map(PolicyRuleSeverityType::name)
134+
.anyMatch(severity -> severity.equals(violation.getPolicySeverity()))) {
131135
if (errorMessage.equals("")) {
132136
errorMessage = baseMessage;
133137
} else {
@@ -164,7 +168,7 @@ public void addLicenseMessages(DeveloperScansScanView resultView, DeveloperScans
164168
// some common pieces into a parent class or interface, it is likely not worth altering the libraries
165169
// as this may be temporary code.
166170
public void addVulnerabilityMessages(DeveloperScansScanView resultView,
167-
DeveloperScansScanItemsPolicyViolationVulnerabilitiesView vulnerabilityPolicyViolation) {
171+
DeveloperScansScanItemsPolicyViolationVulnerabilitiesView vulnerabilityPolicyViolation, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
168172
String baseMessage = getBaseMessage(resultView);
169173

170174
List<DeveloperScansScanItemsPolicyViolationVulnerabilitiesViolatingPoliciesView> violatingPolicies = vulnerabilityPolicyViolation.getViolatingPolicies();
@@ -174,7 +178,9 @@ public void addVulnerabilityMessages(DeveloperScansScanView resultView,
174178
for (int i = 0; i < violatingPolicies.size(); i++) {
175179
DeveloperScansScanItemsPolicyViolationVulnerabilitiesViolatingPoliciesView violation = violatingPolicies.get(i);
176180

177-
if (violation.getPolicySeverity().equals(POLICY_SEVERITY_CRITICAL) || violation.getPolicySeverity().equals(POLICY_SEVERITY_BLOCKER)) {
181+
if (severitiesToFailPolicyCheck.stream()
182+
.map(PolicyRuleSeverityType::name)
183+
.anyMatch(severity -> severity.equals(violation.getPolicySeverity()))) {
178184
errorMessage = constructVulnerabilityMessageSegment(baseMessage, errorMessage, violation);
179185
} else {
180186
warningMessage = constructVulnerabilityMessageSegment(baseMessage, warningMessage, violation);
@@ -212,15 +218,17 @@ public void addVulnerabilityMessages(DeveloperScansScanView resultView,
212218
// While it may be possible to reduce the overall message generation code in this class by pushing
213219
// some common pieces into a parent class or interface, it is likely not worth altering the libraries
214220
// as this may be temporary code.
215-
public void addViolatingPoliciesMessages(DeveloperScansScanView resultView, List<DeveloperScansScanItemsViolatingPoliciesView> violatingPolicies) {
221+
public void addViolatingPoliciesMessages(DeveloperScansScanView resultView, List<DeveloperScansScanItemsViolatingPoliciesView> violatingPolicies, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
216222
String baseMessage = getBaseMessage(resultView);
217223

218224
String errorMessage = "", warningMessage = "";
219225

220226
for (int i = 0; i < violatingPolicies.size(); i++) {
221227
DeveloperScansScanItemsViolatingPoliciesView violation = violatingPolicies.get(i);
222228

223-
if (violation.getPolicySeverity().equals(POLICY_SEVERITY_CRITICAL) || violation.getPolicySeverity().equals(POLICY_SEVERITY_BLOCKER)) {
229+
if (severitiesToFailPolicyCheck.stream()
230+
.map(PolicyRuleSeverityType::name)
231+
.anyMatch(severity -> severity.equals(violation.getPolicySeverity()))) {
224232
if (errorMessage.equals("")) {
225233
errorMessage = baseMessage;
226234
} else {

src/main/java/com/blackduck/integration/detect/workflow/blackduck/developer/aggregate/RapidScanResultAggregator.java

+18-15
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313
import java.util.stream.Collectors;
1414

1515
import com.blackduck.integration.blackduck.api.generated.component.*;
16+
import com.blackduck.integration.blackduck.api.generated.enumeration.PolicyRuleSeverityType;
17+
1618
import org.apache.commons.lang3.StringUtils;
1719

1820
import com.blackduck.integration.blackduck.api.generated.view.DeveloperScansScanView;
21+
import com.blackduck.integration.detect.workflow.blackduck.developer.RapidScanOptions;
1922

2023
public class RapidScanResultAggregator {
2124

2225
private final Map<String, Set<String>> directToTransitiveChildren = new HashMap<>();
2326
private final Map<String, String[]> directUpgradeGuidanceVersions = new HashMap<>();
2427

25-
public RapidScanAggregateResult aggregateData(List<DeveloperScansScanView> results) {
26-
Collection<RapidScanComponentDetail> componentDetails = aggregateComponentData(results);
28+
public RapidScanAggregateResult aggregateData(List<DeveloperScansScanView> results, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
29+
Collection<RapidScanComponentDetail> componentDetails = aggregateComponentData(results, severitiesToFailPolicyCheck);
2730
List<RapidScanComponentDetail> sortedByComponent = componentDetails.stream()
2831
.sorted(Comparator.comparing(RapidScanComponentDetail::getComponentIdentifier))
2932
.collect(Collectors.toList());
@@ -62,7 +65,7 @@ public RapidScanAggregateResult aggregateData(List<DeveloperScansScanView> resul
6265
transitiveGuidance);
6366
}
6467

65-
private List<RapidScanComponentDetail> aggregateComponentData(List<DeveloperScansScanView> results) {
68+
private List<RapidScanComponentDetail> aggregateComponentData(List<DeveloperScansScanView> results, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
6669
// the key is the component identifier
6770
List<RapidScanComponentDetail> componentDetails = new LinkedList<>();
6871

@@ -110,10 +113,10 @@ private List<RapidScanComponentDetail> aggregateComponentData(List<DeveloperScan
110113
licenseGroupDetail.addPolicies(licensePolicyNames);
111114
violatingPoliciesDetail.addPolicies(allViolatedPolicyNames);
112115

113-
addComponentData(resultView, componentViolations, componentGroupDetail);
114-
addVulnerabilityData(resultView, vulnerabilityViolations, securityGroupDetail);
115-
addLicenseData(resultView, licenseViolations, licenseGroupDetail);
116-
addViolatingPoliciesData(resultView, policyViolationsSuperset, violatingPoliciesDetail);
116+
addComponentData(resultView, componentViolations, componentGroupDetail, severitiesToFailPolicyCheck);
117+
addVulnerabilityData(resultView, vulnerabilityViolations, securityGroupDetail, severitiesToFailPolicyCheck);
118+
addLicenseData(resultView, licenseViolations, licenseGroupDetail, severitiesToFailPolicyCheck);
119+
addViolatingPoliciesData(resultView, policyViolationsSuperset, violatingPoliciesDetail, severitiesToFailPolicyCheck);
117120
}
118121

119122
return componentDetails;
@@ -190,26 +193,26 @@ private RapidScanComponentDetail createDetail(DeveloperScansScanView resultView)
190193
securityGroupDetail, licenseGroupDetail, violatingPoliciesDetail);
191194
}
192195

193-
private void addVulnerabilityData(DeveloperScansScanView resultView, List<DeveloperScansScanItemsPolicyViolationVulnerabilitiesView> vulnerabilities, RapidScanComponentGroupDetail securityDetail) {
196+
private void addVulnerabilityData(DeveloperScansScanView resultView, List<DeveloperScansScanItemsPolicyViolationVulnerabilitiesView> vulnerabilities, RapidScanComponentGroupDetail securityDetail, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
194197
for (DeveloperScansScanItemsPolicyViolationVulnerabilitiesView vulnerabilityPolicyViolation : vulnerabilities) {
195-
securityDetail.addVulnerabilityMessages(resultView, vulnerabilityPolicyViolation);
198+
securityDetail.addVulnerabilityMessages(resultView, vulnerabilityPolicyViolation, severitiesToFailPolicyCheck);
196199
}
197200
}
198201

199-
private void addLicenseData(DeveloperScansScanView resultView, List<DeveloperScansScanItemsPolicyViolationLicensesView> licenseViolations, RapidScanComponentGroupDetail licenseDetail) {
202+
private void addLicenseData(DeveloperScansScanView resultView, List<DeveloperScansScanItemsPolicyViolationLicensesView> licenseViolations, RapidScanComponentGroupDetail licenseDetail, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
200203
for (DeveloperScansScanItemsPolicyViolationLicensesView licensePolicyViolation : licenseViolations) {
201-
licenseDetail.addLicenseMessages(resultView, licensePolicyViolation);
204+
licenseDetail.addLicenseMessages(resultView, licensePolicyViolation, severitiesToFailPolicyCheck);
202205
}
203206
}
204207

205-
private void addComponentData(DeveloperScansScanView resultView, List<DeveloperScansScanItemsComponentViolatingPoliciesView> componentViolations, RapidScanComponentGroupDetail componentGroupDetail) {
208+
private void addComponentData(DeveloperScansScanView resultView, List<DeveloperScansScanItemsComponentViolatingPoliciesView> componentViolations, RapidScanComponentGroupDetail componentGroupDetail, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
206209
for (DeveloperScansScanItemsComponentViolatingPoliciesView componentPolicyViolation: componentViolations) {
207-
componentGroupDetail.addComponentMessages(resultView, componentPolicyViolation);
210+
componentGroupDetail.addComponentMessages(resultView, componentPolicyViolation, severitiesToFailPolicyCheck);
208211
}
209212
}
210213

211-
private void addViolatingPoliciesData(DeveloperScansScanView resultView, List<DeveloperScansScanItemsViolatingPoliciesView> allPolicyViolations, RapidScanComponentGroupDetail violatingPoliciesDetail) {
212-
violatingPoliciesDetail.addViolatingPoliciesMessages(resultView, allPolicyViolations);
214+
private void addViolatingPoliciesData(DeveloperScansScanView resultView, List<DeveloperScansScanItemsViolatingPoliciesView> allPolicyViolations, RapidScanComponentGroupDetail violatingPoliciesDetail, List<PolicyRuleSeverityType> severitiesToFailPolicyCheck) {
215+
violatingPoliciesDetail.addViolatingPoliciesMessages(resultView, allPolicyViolations, severitiesToFailPolicyCheck);
213216
}
214217

215218
/**

0 commit comments

Comments
 (0)