use of com.checkmarx.sdk.dto.cx.CxScanParams in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class GoScanner method searchTreeChildren.
private String searchTreeChildren(String teamPath, String[] buTokens, int i, ArrayList<Object> children) {
String token = buTokens[i++];
for (Object item : children) {
LinkedHashMap<String, Object> node = (LinkedHashMap<String, Object>) item;
Object o = node.get("id");
Integer id = (Integer) o;
o = node.get("title");
String title = (String) o;
title = title.trim();
o = node.get("children");
ArrayList<Object> nodeChildren = (ArrayList<Object>) o;
if (title.equals(token)) {
if (i == buTokens.length) {
CxScanParams csp = getScanProbeByTeam(id.toString());
csp.setTeamName(teamPath);
return id.toString();
} else {
return searchTreeChildren(teamPath, buTokens, i, nodeChildren);
}
}
}
return UNKNOWN;
}
use of com.checkmarx.sdk.dto.cx.CxScanParams in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class GoScanner method getScanProbeByTeam.
/**
* Examines the current scan scanProbeMap and returns the record matching the teamID
* 'if' it exsits.
*
* @return the CxScanParams record
*/
private CxScanParams getScanProbeByTeam(String teamID) {
// First check it if it exists
for (CxScanParams csp : scanProbeMap) {
if (csp.getTeamId().equals(teamID)) {
return csp;
}
}
// If it doesn't exist then create it
CxScanParams csp = new CxScanParams();
csp.setTeamId(teamID);
scanProbeMap.add(csp);
return csp;
}
use of com.checkmarx.sdk.dto.cx.CxScanParams in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.
the class CxRepoFileHelper method prepareScanParamsToCloneRepo.
private CxScanParams prepareScanParamsToCloneRepo(String repoUrlWithAuth, List<String> excludeFiles, String branch) {
CxScanParams cxScanParams = new CxScanParams();
cxScanParams.withGitUrl(repoUrlWithAuth);
cxScanParams.withFileExclude(excludeFiles);
if (StringUtils.isNotEmpty(branch)) {
cxScanParams.withBranch(Constants.CX_BRANCH_PREFIX.concat(branch));
}
return cxScanParams;
}
use of com.checkmarx.sdk.dto.cx.CxScanParams in project cx-flow by checkmarx-ltd.
the class AbstractVulnerabilityScanner method scan.
@Override
public ScanResults scan(ScanRequest scanRequest) {
log.info("--------------------- Initiating new {} scan ---------------------", SCAN_TYPE);
setRequestParamsByProperties(scanRequest);
checkScanSubmitEmailDelivery(scanRequest);
try {
Integer scanId;
CxScanParams cxScanParams = getScanRequestConverter().toScanParams(scanRequest);
Integer projectId = cxScanParams.getProjectId();
log.info("Checking if there is any existing scan for Project: {}", projectId);
Integer existingScanId = getScannerClient().getScanIdOfExistingScanIfExists(projectId);
String scanComment = getScanComment(scanRequest);
if (existingScanId != UNKNOWN_INT) {
if (!getCxPropertiesBase().getScanQueuing()) {
Boolean scanResubmit = false;
if (scanRequest.getScanResubmit() != null) {
scanResubmit = Boolean.parseBoolean(scanRequest.getScanResubmit());
} else if (flowProperties.getScanResubmit()) {
scanResubmit = flowProperties.getScanResubmit();
}
if (scanResubmit) {
log.info("Existing ongoing scan with id {} found for Project : {}", existingScanId, projectId);
log.info("Aborting the ongoing scan with id {} for Project: {}", existingScanId, projectId);
getScannerClient().cancelScan(existingScanId);
log.info("Resubmitting the scan for Project: {}", projectId);
scanId = getScannerClient().createScan(cxScanParams, scanComment);
} else {
log.warn("Property scan-resubmit set to {} : New scan not submitted, due to existing ongoing scan for the same Project id {}", flowProperties.getScanResubmit(), projectId);
bugTrackers.getBugTrackerEventTrigger().triggerScanNotSubmittedBugTrackerEvent(scanRequest, getEmptyScanResults());
throw new CheckmarxException(String.format("Active Scan with Id %d already exists for Project: %d", existingScanId, projectId));
}
} else {
scanId = getScannerClient().createScan(cxScanParams, scanComment);
}
} else {
scanId = getScannerClient().createScan(cxScanParams, scanComment);
}
return getScanResults(scanRequest, projectId, scanId);
} catch (GitHubRepoUnavailableException e) {
// an error stack trace in the log
return getEmptyScanResults();
} catch (Exception e) {
log.error("SAST scan failed", e);
OperationResult scanCreationFailure = new OperationResult(OperationStatus.FAILURE, e.getMessage());
ScanReport report = new ScanReport(-1, scanRequest, scanRequest.getRepoUrl(), scanCreationFailure);
report.log();
return getEmptyScanResults();
}
}
use of com.checkmarx.sdk.dto.cx.CxScanParams in project cx-flow by checkmarx-ltd.
the class ScanRequestConverter method prepareScanParamsObject.
public CxScanParams prepareScanParamsObject(ScanRequest request, File cxFile, String ownerId, Integer projectId) {
CxScanParams params = new CxScanParams().teamId(ownerId).withTeamName(request.getTeam()).projectId(projectId).withProjectName(request.getProject()).withScanPreset(request.getScanPreset()).withGitUrl(request.getRepoUrlWithAuth()).withIncremental(request.isIncremental()).withForceScan(request.isForceScan()).withFileExclude(request.getExcludeFiles()).withFolderExclude(request.getExcludeFolders()).withScanConfiguration(request.getScanConfiguration()).withSshKeyIdentifier(request.getSshKeyIdentifier()).withClientSecret(request.getScannerApiSec()).withCustomFields(request.getCxFields()).withScanCustomFields(request.getScanFields());
if (StringUtils.isNotEmpty(request.getBranch())) {
params.withBranch(Constants.CX_BRANCH_PREFIX.concat(request.getBranch()));
}
if (StringUtils.isEmpty(request.getBranch())) {
params.withBranch(Constants.CX_BRANCH_PREFIX.concat(""));
}
if (StringUtils.isNotEmpty(request.getDefaultBranch())) {
params.withDefaultBranch(Constants.CX_BRANCH_PREFIX.concat(request.getDefaultBranch()));
}
if (StringUtils.isEmpty(request.getDefaultBranch()) && StringUtils.isNotEmpty(request.getMergeTargetBranch())) {
params.withDefaultBranch(Constants.CX_BRANCH_PREFIX.concat(request.getMergeTargetBranch()));
}
if (StringUtils.isEmpty(request.getDefaultBranch()) && StringUtils.isEmpty(request.getMergeTargetBranch())) {
params.withDefaultBranch(Constants.CX_BRANCH_PREFIX.concat(""));
}
if (cxFile != null) {
params.setSourceType(CxScanParams.Type.FILE);
params.setFilePath(cxFile.getAbsolutePath());
}
return params;
}
Aggregations