Search in sources :

Example 1 with ScanDetails

use of com.checkmarx.flow.dto.ScanDetails in project cx-flow by checkmarx-ltd.

the class BugTrackerEventTrigger method triggerScanNotSubmittedBugTrackerEvent.

public void triggerScanNotSubmittedBugTrackerEvent(ScanRequest scanRequest, ScanResults scanResults) {
    boolean eventsWereTriggered = true;
    String description = "Existing scan in progress. Please try again after sometime.";
    BugTracker.Type bugTrackerType = scanRequest.getBugTracker().getType();
    switch(bugTrackerType) {
        case GITLABMERGE:
            gitLabService.sendMergeComment(scanRequest, SCAN_NOT_SUBMITTED_MESSAGE);
            gitLabService.endBlockMerge(scanRequest);
            break;
        case GITLABCOMMIT:
            gitLabService.sendCommitComment(scanRequest, SCAN_NOT_SUBMITTED_MESSAGE);
            break;
        case GITHUBPULL:
            gitService.sendMergeComment(scanRequest, SCAN_NOT_SUBMITTED_MESSAGE);
            String targetURL = cxProperties.getBaseUrl().concat(GitHubService.CX_USER_SCAN_QUEUE);
            gitService.errorBlockMerge(scanRequest, targetURL, description);
            break;
        case BITBUCKETPULL:
            bbService.sendMergeComment(scanRequest, SCAN_NOT_SUBMITTED_MESSAGE);
            break;
        case BITBUCKETSERVERPULL:
            bbService.sendServerMergeComment(scanRequest, SCAN_NOT_SUBMITTED_MESSAGE);
            String buildName = "Existing Checkmarx Scan in progress.";
            String buildUrl = cxProperties.getBaseUrl().concat(BitBucketService.CX_USER_SCAN_QUEUE);
            bbService.setBuildFailedStatus(scanRequest, buildName, buildUrl, description);
            break;
        case ADOPULL:
            adoService.sendMergeComment(scanRequest, SCAN_NOT_SUBMITTED_MESSAGE);
            adoService.startBlockMerge(scanRequest);
            adoService.endBlockMerge(scanRequest, scanResults, new ScanDetails());
            break;
        case JIRA:
        case CUSTOM:
            eventsWereTriggered = false;
            // No action is needed
            break;
        case NONE:
            log.warn("Bug tracker events were not triggered, because bug tracker type is '{}'.", bugTrackerType);
            break;
        default:
            eventsWereTriggered = false;
            log.warn("Bug-Tracker type: {} is not supported", bugTrackerType);
    }
    if (eventsWereTriggered) {
        log.debug("Completed triggering events for the '{}' bug tracker.", bugTrackerType);
    } else {
        log.debug("Bug tracker events were not triggered, because bug tracker type is '{}'.", bugTrackerType);
    }
}
Also used : ScanDetails(com.checkmarx.flow.dto.ScanDetails) BugTracker(com.checkmarx.flow.dto.BugTracker)

Example 2 with ScanDetails

use of com.checkmarx.flow.dto.ScanDetails in project cx-flow by checkmarx-ltd.

the class ResultsService method processScanResultsAsync.

@Async("scanRequest")
public CompletableFuture<ScanResults> processScanResultsAsync(ScanRequest request, Integer projectId, Integer scanId, String osaScanId, FilterConfiguration filterConfiguration) throws MachinaException {
    try {
        CompletableFuture<ScanResults> future = new CompletableFuture<>();
        // TODO async these, and join and merge after
        ScanResults results = cxScannerService.getScannerClient().getReportContentByScanId(scanId, filterConfiguration);
        logGetResultsJsonLogger(request, scanId, results);
        results = getOSAScan(request, projectId, osaScanId, filterConfiguration, results);
        sendEmailNotification(request, results);
        processResults(request, results, new ScanDetails(projectId, scanId, osaScanId));
        logScanDetails(request, projectId, results);
        future.complete(results);
        return future;
    } catch (Exception e) {
        log.error("Error occurred while processing results.", e);
        CompletableFuture<ScanResults> x = new CompletableFuture<>();
        x.completeExceptionally(e);
        return x;
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ScanResults(com.checkmarx.sdk.dto.ScanResults) ScanDetails(com.checkmarx.flow.dto.ScanDetails) InvalidCredentialsException(com.checkmarx.flow.exception.InvalidCredentialsException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) JiraClientException(com.checkmarx.flow.exception.JiraClientException) JiraClientRunTimeException(com.checkmarx.flow.exception.JiraClientRunTimeException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) MachinaException(com.checkmarx.flow.exception.MachinaException) Async(org.springframework.scheduling.annotation.Async)

Example 3 with ScanDetails

use of com.checkmarx.flow.dto.ScanDetails in project cx-flow by checkmarx-ltd.

the class ResultsService method publishCombinedResults.

@Async("scanRequest")
public CompletableFuture<ScanResults> publishCombinedResults(ScanRequest scanRequest, ScanResults scanResults) {
    try {
        CompletableFuture<ScanResults> future = new CompletableFuture<>();
        if (scanResults.getProjectId() != null) {
            Integer projectId = Integer.parseInt(scanResults.getProjectId());
            if (projectId != UNKNOWN_INT) {
                logGetResultsJsonLogger(scanRequest, scanResults.getSastScanId(), scanResults);
                sendEmailNotification(scanRequest, scanResults);
                processResults(scanRequest, scanResults, new ScanDetails(projectId, scanResults.getSastScanId(), null));
                logScanDetails(scanRequest, projectId, scanResults);
            } else {
                processResults(scanRequest, scanResults, new ScanDetails(null, scanResults.getSastScanId(), null));
            }
        } else {
            processResults(scanRequest, scanResults, new ScanDetails(null, scanResults.getSastScanId(), null));
        }
        future.complete(scanResults);
        log.info("Finished processing the request");
        return future;
    } catch (Exception e) {
        log.error("Error occurred while processing results.", e);
        CompletableFuture<ScanResults> x = new CompletableFuture<>();
        x.completeExceptionally(e);
        return x;
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ScanResults(com.checkmarx.sdk.dto.ScanResults) ScanDetails(com.checkmarx.flow.dto.ScanDetails) InvalidCredentialsException(com.checkmarx.flow.exception.InvalidCredentialsException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) JiraClientException(com.checkmarx.flow.exception.JiraClientException) JiraClientRunTimeException(com.checkmarx.flow.exception.JiraClientRunTimeException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) MachinaException(com.checkmarx.flow.exception.MachinaException) Async(org.springframework.scheduling.annotation.Async)

Aggregations

ScanDetails (com.checkmarx.flow.dto.ScanDetails)3 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)2 InvalidCredentialsException (com.checkmarx.flow.exception.InvalidCredentialsException)2 JiraClientException (com.checkmarx.flow.exception.JiraClientException)2 JiraClientRunTimeException (com.checkmarx.flow.exception.JiraClientRunTimeException)2 MachinaException (com.checkmarx.flow.exception.MachinaException)2 MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)2 ScanResults (com.checkmarx.sdk.dto.ScanResults)2 CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Async (org.springframework.scheduling.annotation.Async)2 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)2 BugTracker (com.checkmarx.flow.dto.BugTracker)1