Search in sources :

Example 6 with MachinaException

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

the class GitLabIssueTracker method createIssue.

@Override
public Issue createIssue(ScanResults.XIssue resultIssue, ScanRequest request) throws MachinaException {
    log.debug("Executing createIssue GitLab API call");
    String endpoint = scmConfigOverrider.determineConfigApiUrl(properties, request).concat(NEW_ISSUE_PATH);
    ResponseEntity<com.checkmarx.flow.dto.gitlab.Issue> response;
    try {
        HttpEntity<String> httpEntity = new HttpEntity<>(getJSONCreateIssue(resultIssue, request).toString(), createAuthHeaders(request));
        response = restTemplate.exchange(endpoint, HttpMethod.POST, httpEntity, com.checkmarx.flow.dto.gitlab.Issue.class, request.getRepoProjectId());
    } catch (HttpClientErrorException e) {
        log.error("Error occurred while creating GitLab Issue", e);
        if (e.getStatusCode().equals(HttpStatus.GONE)) {
            throw new MachinaException("Issues are not enabled for this repository");
        } else {
            throw new MachinaException("Error occurred while creating GitLab Issue");
        }
    }
    return mapToIssue(response.getBody());
}
Also used : Issue(com.checkmarx.flow.dto.Issue) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaException(com.checkmarx.flow.exception.MachinaException)

Example 7 with MachinaException

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

the class ImmutableIssueTracker method fileInit.

/**
 * Common function for initializing file based bug trackers
 */
public void fileInit(ScanRequest request, ScanResults results, String filePath, FilenameFormatter filenameFormatter, Logger log) throws MachinaException {
    Path fullPath = Paths.get(filePath);
    Path parentDir = fullPath.getParent();
    Path filename = fullPath.getFileName();
    if (request == null || results == null) {
        throw new MachinaException("Request or Results object is missing");
    }
    String formattedPath = filenameFormatter.formatPath(request, filename.toString(), parentDir.toString());
    request.setFilename(formattedPath);
    log.info("Creating file {}", formattedPath);
    try {
        Files.deleteIfExists(Paths.get(formattedPath));
        Files.createFile(Paths.get(formattedPath));
    } catch (IOException e) {
        log.error("Issue deleting existing file or writing initial {}", filename, e);
    }
}
Also used : Path(java.nio.file.Path) MachinaException(com.checkmarx.flow.exception.MachinaException) IOException(java.io.IOException)

Example 8 with MachinaException

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

the class JsonIssueTracker method complete.

@Override
public void complete(ScanRequest request, ScanResults results) throws MachinaException {
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        if (request != null && results != null) {
            mapper.writeValue(new File(request.getFilename()).getCanonicalFile(), results);
        } else {
            log.error("No request or results provided");
            throw new MachinaException();
        }
    } 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 9 with MachinaException

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

the class SarifIssueTrackerTest method initWithNullPropertiesNullParameters.

@Test
public void initWithNullPropertiesNullParameters() {
    SarifProperties properties = new SarifProperties();
    properties.setFilePath("./cx.sarif");
    FilenameFormatter filenameFormatter = new SanitizingFilenameFormatter();
    SarifIssueTracker sarifIssueTracker = new SarifIssueTracker(properties, filenameFormatter);
    try {
        sarifIssueTracker.init(null, null);
        assert false;
    } catch (MachinaException e) {
        assert true;
    }
}
Also used : SarifProperties(com.checkmarx.flow.config.SarifProperties) MachinaException(com.checkmarx.flow.exception.MachinaException) SanitizingFilenameFormatter(com.checkmarx.flow.service.SanitizingFilenameFormatter) FilenameFormatter(com.checkmarx.flow.service.FilenameFormatter) SanitizingFilenameFormatter(com.checkmarx.flow.service.SanitizingFilenameFormatter) Test(org.junit.Test)

Example 10 with MachinaException

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

the class SCAScanner method cxParseResults.

@Override
protected void cxParseResults(ScanRequest scanRequest, File file) throws ExitThrowable {
    RestClientConfig restClientConfig;
    IScanClientHelper iScanClientHelper;
    try {
        ScanParams sdkScanParams = ScanParams.builder().projectName(scanRequest.getProject()).scaConfig(scanRequest.getScaConfig()).filterConfiguration(scanRequest.getFilter()).build();
        restClientConfig = scaScannerClient.getScanConfig(sdkScanParams);
        iScanClientHelper = new ScaClientHelper(restClientConfig, log, scaProperties);
        ScanResults results = iScanClientHelper.getReportContent(file, scanRequest.getFilter());
        resultsService.processResults(scanRequest, 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 : ScaClientHelper(com.checkmarx.sdk.utils.scanner.client.ScaClientHelper) ScanParams(com.checkmarx.sdk.dto.ast.ScanParams) ScanResults(com.checkmarx.sdk.dto.ScanResults) MachinaException(com.checkmarx.flow.exception.MachinaException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) IScanClientHelper(com.checkmarx.sdk.utils.scanner.client.IScanClientHelper) RestClientConfig(com.checkmarx.sdk.config.RestClientConfig)

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