Skip to content

Commit c15e065

Browse files
Added version for scanWithSetting API
1 parent 278da87 commit c15e065

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

src/main/java/com/checkmarx/sdk/service/CxService.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,22 +1883,36 @@ public void uploadProjectSource(Integer projectId, File file) throws CheckmarxEx
18831883
public Integer uploadProjectSource(CxScanParams params,Integer projectId, File file,String comment) throws CheckmarxException {
18841884
HttpHeaders headers = authClient.createAuthHeaders();
18851885
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
1886-
18871886
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
1888-
FileSystemResource value = new FileSystemResource(file);
1889-
map.add("projectId", projectId);
1890-
map.add("customFields", params.getCustomFields());
1891-
map.add("overrideProjectSetting", cxProperties.getOverrideProjectSetting());
1892-
map.add("isIncremental", params.isIncremental());
1893-
map.add("isPublic", params.isPublic());
1894-
map.add("forceScan", params.isForceScan());
1895-
map.add("comment", comment);
1896-
map.add("presetId", getPresetId(params.getScanPreset()));
1897-
map.add("engineConfigurationId",getScanConfiguration(params.getScanConfiguration()));
1898-
map.add("zippedSource", value);
1899-
1887+
if(cxProperties.getVersion()>9.4){
1888+
headers.add("version", "1.2");
1889+
FileSystemResource value = new FileSystemResource(file);
1890+
map.add("projectId", projectId);
1891+
map.add("customFields", params.getCustomFields());
1892+
map.add("overrideProjectSetting", cxProperties.getOverrideProjectSetting());
1893+
map.add("isIncremental", params.isIncremental());
1894+
map.add("isPublic", params.isPublic());
1895+
map.add("forceScan", params.isForceScan());
1896+
map.add("comment", comment);
1897+
map.add("presetId", getPresetId(params.getScanPreset()));
1898+
map.add("engineConfigurationId",getScanConfiguration(params.getScanConfiguration()));
1899+
map.add("zippedSource", value);
1900+
}else {
1901+
headers.add("version", "1.0");
1902+
FileSystemResource value = new FileSystemResource(file);
1903+
map.add("projectId", projectId);
1904+
map.add("overrideProjectSetting", cxProperties.getOverrideProjectSetting());
1905+
map.add("isIncremental", params.isIncremental());
1906+
map.add("isPublic", params.isPublic());
1907+
map.add("forceScan", params.isForceScan());
1908+
map.add("comment", comment);
1909+
map.add("presetId", getPresetId(params.getScanPreset()));
1910+
map.add("engineConfigurationId",getScanConfiguration(params.getScanConfiguration()));
1911+
map.add("zippedSource", value);
1912+
1913+
log.debug("Using scanWithSettings version 1.0 CustomFields not available");
1914+
}
19001915
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
1901-
19021916
try {
19031917
log.info("Updating Source details for project Id {}", projectId);
19041918
String response = restTemplate.exchange(cxProperties.getUrl().concat(PROJECT_SOURCE_FILE_WITH_SETTINGS), HttpMethod.POST, requestEntity, String.class).getBody();
@@ -2720,7 +2734,6 @@ private SASTScanReport prepareSources(CxScanParams params, Integer projectId, St
27202734
return new SASTScanReport(UNKNOWN_INT,true);
27212735
}else if(cxProperties.getEnabledZipScan() && !cxProperties.getOverrideProjectSetting()){
27222736
String clonedRepoPath = cxRepoFileHelper.prepareRepoFile(params);
2723-
uploadProjectSource(params,projectId, new File(clonedRepoPath),comment);
27242737
params.setFilePath(clonedRepoPath);
27252738
return new SASTScanReport(uploadProjectSource(params,projectId, new File(clonedRepoPath),comment),false);
27262739
}

0 commit comments

Comments
 (0)