Skip to content

Commit 6711533

Browse files
authored
Merge pull request #371 from checkmarx-ltd/develop
Added API to get SCA tags
2 parents e130583 + 46636cf commit 6711533

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.github.checkmarx-ltd</groupId>
1212
<artifactId>cx-spring-boot-sdk</artifactId>
13-
<version>0.5.68</version>
13+
<version>0.5.69</version>
1414
<name>cx-spring-boot-sdk</name>
1515
<description>Checkmarx Java Spring Boot SDK</description>
1616
<properties>

src/main/java/com/checkmarx/sdk/dto/ScanResults.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ public IssueDetails comment(final String comment) {
656656
@Builder
657657
public static class ScaDetails {
658658
private String vulnerabilityLink;
659+
660+
private Map scanTags;
659661
private Finding finding;
660662
private Package vulnerabilityPackage;
661663
}

src/main/java/com/checkmarx/sdk/dto/sca/SCAResults.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.io.Serializable;
99
import java.util.List;
10+
import java.util.Map;
1011

1112
@Builder
1213
@Getter
@@ -25,6 +26,8 @@ public class SCAResults extends ResultsBase implements Serializable {
2526
private boolean isPolicyViolated;
2627
private List<String> violatedPolicies;
2728
private String output;
29+
30+
private Map scanTags;
2831

2932
public void calculateVulnerableAndOutdatedPackages() {
3033
int sum;

src/main/java/com/checkmarx/sdk/utils/scanner/client/ScaClientHelper.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.checkmarx.sdk.utils.zip.CxZipUtils;
2525
import com.checkmarx.sdk.utils.zip.NewCxZipFile;
2626
import com.checkmarx.sdk.utils.zip.Zipper;
27+
import com.fasterxml.jackson.core.TreeNode;
2728
import com.fasterxml.jackson.databind.DeserializationFeature;
2829
import com.fasterxml.jackson.databind.JsonNode;
2930
import com.fasterxml.jackson.databind.MapperFeature;
@@ -78,6 +79,7 @@ public class ScaClientHelper extends ScanClientHelper implements IScanClientHelp
7879
private static final String PROJECTS_BY_ID = PROJECTS + "/%s";
7980
private static final String SUMMARY_REPORT = RISK_MANAGEMENT_API + "riskReports/%s/summary";
8081
private static final String FINDINGS = RISK_MANAGEMENT_API + "riskReports/%s/vulnerabilities";
82+
private static final String TAGS = "/scan-runner/scans/%s";
8183
private static final String PACKAGES = RISK_MANAGEMENT_API + "riskReports/%s/packages";
8284
private static final String LATEST_SCAN = RISK_MANAGEMENT_API + "riskReports?size=1&projectId=%s";
8385
private static final String WEB_REPORT = "/#/projects/%s/reports/%s";
@@ -1462,6 +1464,10 @@ private SCAResults getScanResults() {
14621464
result.setPolicyViolated(!scanViolatedPolicies.isEmpty());
14631465
result.setViolatedPolicies(scanViolatedPolicies);
14641466

1467+
Map<String,String>tags = getScaScanTags();
1468+
result.setScanTags(tags);
1469+
1470+
14651471
if(scaProperties.isPreserveXml()){
14661472
String path = String.format(REPORT_IN_XML_WITH_SCANID, URLEncoder.encode(scanId, ENCODING));
14671473
String xml = httpClient.getRequest(path,
@@ -1482,6 +1488,23 @@ private SCAResults getScanResults() {
14821488
return result;
14831489
}
14841490

1491+
private Map<String, String> getScaScanTags() throws IOException {
1492+
log.debug("Getting SCA scan tags.");
1493+
1494+
String path = String.format(TAGS, URLEncoder.encode(scanId, ENCODING));
1495+
1496+
String response = httpClient.getRequest(path,
1497+
ContentType.CONTENT_TYPE_APPLICATION_JSON,
1498+
String.class,
1499+
HttpStatus.SC_OK,
1500+
"CxSCA Tags",
1501+
false);
1502+
JSONObject obj = new JSONObject(response);
1503+
JSONObject tags = obj.getJSONObject("tags");
1504+
Map<String, String> result = caseInsensitiveObjectMapper.convertValue(tags.toMap(), Map.class);
1505+
return result;
1506+
}
1507+
14851508
protected Map<Filter.Severity, Integer> getFindingCountMap(ScaSummaryBaseFormat summary) {
14861509
EnumMap<Filter.Severity, Integer> result = new EnumMap<>(Filter.Severity.class);
14871510
result.put(Filter.Severity.HIGH, summary.getHighVulnerabilityCount());

0 commit comments

Comments
 (0)