Search in sources :

Example 21 with MachinaRuntimeException

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

the class ConfigurationOverrider method applyCxGoDynamicConfig.

private void applyCxGoDynamicConfig(Map<String, String> overrideReport, ScanRequest request) {
    if (cxIntegrationsProperties.isReadMultiTenantConfiguration()) {
        String orgId = Optional.ofNullable(request.getOrganizationId()).orElseThrow(() -> new MachinaRuntimeException("Organization id is missing for SCM: " + request.getRepoType().getRepository()));
        CxGoConfigFromWebService cxgoConfig = reposManagerService.getCxGoDynamicConfig(request.getGitUrl(), orgId);
        if (cxgoConfig == null) {
            log.error("Multi Tenant mode: missing CxGo configuration in Repos Manager Service. Working with Multi Tenant = false ");
            return;
        }
        String className = CxGoConfigFromWebService.class.getSimpleName();
        log.info("Applying {} configuration.", className);
        Optional.ofNullable(cxgoConfig.getTeam()).filter(StringUtils::isNotEmpty).ifPresent(team -> {
            request.setTeam(team);
            log.info("Using team from {}", className);
            overrideReport.put(TEAM_REPORT_KEY, team);
        });
        Optional.ofNullable(cxgoConfig.getCxgoToken()).filter(StringUtils::isNotEmpty).ifPresent(secret -> {
            request.setScannerApiSec(secret);
            log.info("Using scanner API secret from {}", className);
            overrideReport.put("scannerApiSec", "<actually it's a secret>");
        });
        Optional.ofNullable(cxgoConfig.getScmAccessToken()).filter(StringUtils::isNotEmpty).ifPresent(token -> {
            String authUrl = gitAuthUrlGenerator.addCredToUrl(request.getRepoType(), request.getGitUrl(), cxgoConfig.getScmAccessToken());
            request.setRepoUrlWithAuth(authUrl);
            log.info("Using SCM token from {}", className);
            overrideReport.put("SCM token", "********");
        });
    }
}
Also used : MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) CxGoConfigFromWebService(com.checkmarx.flow.config.external.CxGoConfigFromWebService)

Example 22 with MachinaRuntimeException

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

the class SCAScanner method setScannerSpecificProperties.

@Override
protected void setScannerSpecificProperties(ScanRequest scanRequest, ScanParams scanParams) {
    try {
        // report in xml format
        if (!ScanUtils.empty(scanRequest.getBugTracker().getCustomBean()) && scanRequest.getBugTracker().getCustomBean().equalsIgnoreCase("CxXml")) {
            scaProperties.setPreserveXml(true);
        }
        if (scaProperties.isEnabledZipScan()) {
            log.info("CxAST-SCA zip scan is enabled");
            String scaClonedFolderPath = cxRepoFileHelper.getScaClonedRepoFolderPath(scanRequest.getRepoUrlWithAuth(), scanRequest.getExcludeFiles(), scanRequest.getBranch());
            scanParams.setSourceDir(scaClonedFolderPath);
        }
        if (scanRequest.getExcludeFiles() != null) {
            scanParams.getScaConfig().setExcludeFiles(scanRequest.getExcludeFiles());
        } else if (scaProperties.getExcludeFiles() != null) {
            List<String> excludeFiles = new ArrayList<String>(Arrays.asList(scaProperties.getExcludeFiles().split(",")));
            log.debug("Exclude Files list contains : {}", excludeFiles);
            scanParams.getScaConfig().setExcludeFiles(excludeFiles);
        }
    } catch (CheckmarxException e) {
        log.error("Error occurred while setting scanner properties", e);
        throw new MachinaRuntimeException(e.getMessage());
    }
}
Also used : MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 23 with MachinaRuntimeException

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

the class ScanUtils method getMachinaOverride.

public static FlowOverride getMachinaOverride(@RequestParam(value = "override", required = false) String override) {
    FlowOverride o = null;
    try {
        ObjectMapper mapper = new ObjectMapper();
        // if override is provided, check if chars are more than 20 in length, implying base64 encoded json
        if (!ScanUtils.empty(override)) {
            if (override.length() > 20) {
                String oJson = new String(Base64.getDecoder().decode(override));
                o = mapper.readValue(oJson, FlowOverride.class);
                log.info("Overriding attributes with Base64 encoded String");
            } else {
            // TODO download file
            }
        }
    } catch (IOException e) {
        log.error("Error occurred", e);
        throw new MachinaRuntimeException();
    }
    return o;
}
Also used : MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) IOException(java.io.IOException) FlowOverride(com.checkmarx.flow.dto.FlowOverride) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)23 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 IOException (java.io.IOException)8 Issue (com.checkmarx.flow.dto.Issue)5 ScanRequest (com.checkmarx.flow.dto.ScanRequest)5 Incident (com.checkmarx.flow.dto.servicenow.Incident)5 BitbucketServerEventHandler (com.checkmarx.flow.handlers.bitbucket.server.BitbucketServerEventHandler)5 BugTracker (com.checkmarx.flow.dto.BugTracker)4 MachinaException (com.checkmarx.flow.exception.MachinaException)4 ScanResults (com.checkmarx.sdk.dto.ScanResults)3 CxConfig (com.checkmarx.sdk.dto.sast.CxConfig)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 List (java.util.List)3 FlowProperties (com.checkmarx.flow.config.FlowProperties)2 ServiceNowProperties (com.checkmarx.flow.config.ServiceNowProperties)2 Result (com.checkmarx.flow.dto.servicenow.Result)2 HTMLHelper (com.checkmarx.flow.utils.HTMLHelper)2 ScanUtils (com.checkmarx.flow.utils.ScanUtils)2