Search in sources :

Example 16 with MachinaException

use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.

the class AbstractVulnerabilityScanner method getLatestScanResultsAsync.

public CompletableFuture<ScanResults> getLatestScanResultsAsync(ScanRequest request, CxProject cxProject) {
    try {
        CxProject project;
        if (cxProject == null) {
            Integer projectId = getProjectId(request);
            if (projectId.equals(UNKNOWN_INT)) {
                log.warn("No project found for {}", request.getProject());
                return CompletableFuture.completedFuture(null);
            }
            project = getScannerClient().getProject(projectId);
        } else {
            project = cxProject;
        }
        Integer scanId = getScannerClient().getLastScanId(project.getId());
        if (scanId.equals(UNKNOWN_INT)) {
            log.warn("No Scan Results to process for project {}", project.getName());
            CompletableFuture<ScanResults> x = new CompletableFuture<>();
            x.complete(null);
            return x;
        }
        setCxFields(project, request);
        // null is passed for osaScanId as it is not applicable here and will be ignored
        return resultsService.processScanResultsAsync(request, project.getId(), scanId, null, request.getFilter());
    } catch (MachinaException | CheckmarxException e) {
        log.error("Error occurred while processing results for {}{}", request.getTeam(), request.getProject(), e);
        CompletableFuture<ScanResults> x = new CompletableFuture<>();
        x.completeExceptionally(e);
        return x;
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ScanResults(com.checkmarx.sdk.dto.ScanResults) MachinaException(com.checkmarx.flow.exception.MachinaException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) CxProject(com.checkmarx.sdk.dto.cx.CxProject)

Example 17 with MachinaException

use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.

the class AbstractVulnerabilityScanner method scanLocalPath.

private ScanResults scanLocalPath(ScanRequest request, String path) throws ExitThrowable {
    ScanResults results = null;
    try {
        String effectiveProjectName = projectNameGenerator.determineProjectName(request);
        request.setProject(effectiveProjectName);
        overrideScanPreset(request);
        File zipFile = ZipUtils.zipToTempFile(path, flowProperties.getZipExclude());
        ScanDetails details = executeCxScan(request, zipFile);
        results = getScanResults(request, details.getProjectId(), details.getScanId());
        log.debug("Deleting temp file {}", zipFile.getPath());
        Files.deleteIfExists(zipFile.toPath());
    } catch (IOException e) {
        log.error("Error occurred while attempting to zip path {}", path, e);
        exit(3);
    } catch (MachinaException | CheckmarxException e) {
        log.error("Error occurred", e);
        exit(3);
    }
    return results;
}
Also used : ScanResults(com.checkmarx.sdk.dto.ScanResults) MachinaException(com.checkmarx.flow.exception.MachinaException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) IOException(java.io.IOException) File(java.io.File)

Example 18 with MachinaException

use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.

the class AbstractVulnerabilityScanner method scanRemoteRepo.

private ScanResults scanRemoteRepo(ScanRequest request) throws ExitThrowable {
    ScanResults results = null;
    try {
        String effectiveProjectName = projectNameGenerator.determineProjectName(request);
        request.setProject(effectiveProjectName);
        ScanDetails details = executeCxScan(request, null);
        results = getScanResults(request, details.getProjectId(), details.getScanId());
    } catch (MachinaException | CheckmarxException e) {
        log.error("Error occurred", e);
        exit(3);
    }
    return results;
}
Also used : ScanResults(com.checkmarx.sdk.dto.ScanResults) MachinaException(com.checkmarx.flow.exception.MachinaException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException)

Example 19 with MachinaException

use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.

the class ImmutableIssueTracker method writeJsonOutput.

/**
 * Common function for writing POJO to Json file output using mapper
 */
public void writeJsonOutput(ScanRequest request, Object report, Logger log) throws MachinaException {
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        mapper.writeValue(new File(request.getFilename()).getCanonicalFile(), report);
    } catch (IOException e) {
        log.error("Issue occurred while writing file {}", request.getFilename(), e);
        throw new MachinaException();
    }
}
Also used : MachinaException(com.checkmarx.flow.exception.MachinaException) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with MachinaException

use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.

the class SastScanner method cxParseResults.

public void cxParseResults(ScanRequest request, File file) throws ExitThrowable {
    try {
        ScanResults results = cxService.getReportContent(file, request.getFilter());
        resultsService.processResults(request, results, scanDetails);
        if (flowProperties.isBreakBuild() && results != null && results.getXIssues() != null && !results.getXIssues().isEmpty()) {
            log.error(ERROR_BREAK_MSG);
            exit(ExitCode.BUILD_INTERRUPTED);
        }
    } catch (MachinaException | CheckmarxException e) {
        log.error("Error occurred while processing results file", e);
        exit(3);
    }
}
Also used : ScanResults(com.checkmarx.sdk.dto.ScanResults) MachinaException(com.checkmarx.flow.exception.MachinaException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException)

Aggregations

MachinaException (com.checkmarx.flow.exception.MachinaException)30 ScanResults (com.checkmarx.sdk.dto.ScanResults)18 ScanRequest (com.checkmarx.flow.dto.ScanRequest)11 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)8 Issue (com.checkmarx.flow.dto.Issue)7 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)6 IOException (java.io.IOException)5 ExecutionException (java.util.concurrent.ExecutionException)5 TimeoutException (java.util.concurrent.TimeoutException)5 MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)4 File (java.io.File)4 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 When (io.cucumber.java.en.When)3 URI (java.net.URI)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Incident (com.checkmarx.flow.dto.servicenow.Incident)2 InvalidCredentialsException (com.checkmarx.flow.exception.InvalidCredentialsException)2 CxProject (com.checkmarx.sdk.dto.cx.CxProject)2