Search in sources :

Example 6 with Access

use of com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access in project sechub by mercedes-benz.

the class CheckmarxProjectSupport method extractSastScanSettingsFromGet.

// https://swagger-open-api.herokuapp.com/v1/swagger#/SAST/ScanSettingsV1_1__GetByprojectId
CheckmarxSastScanSettings extractSastScanSettingsFromGet(String json, JSONAdapterSupport support) throws AdapterException {
    Access rootNode = support.fetchRootNode(json);
    CheckmarxSastScanSettings settings = new CheckmarxSastScanSettings();
    settings.setProjectId(rootNode.fetch("project").fetch("id").asLong());
    settings.setPresetId(rootNode.fetch("preset").fetch("id").asLong());
    settings.setEngineConfigurationId(rootNode.fetch("engineConfiguration").fetch("id").asLong());
    return settings;
}
Also used : Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access) CheckmarxSastScanSettings(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings)

Example 7 with Access

use of com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access in project sechub by mercedes-benz.

the class WaitForQueueStateSupport method fetchScanQueueDetails.

// https://checkmarx.atlassian.net/wiki/spaces/KC/pages/334332174/Get+Scan+Queue+Details+by+Scan+Id+-+GET+sast+scansQueue+id+8.7.0+and+up
private void fetchScanQueueDetails(CheckmarxContext context) throws AdapterException {
    oauthSupport.refreshBearerTokenWhenNecessary(context);
    QueueDetails details = context.getQueueDetails();
    long scanId = context.getSessionData().getScanId();
    try {
        LOG.debug("Fetching scan queue details for Checkmarx scan Id: {}.", scanId);
        RestOperations restTemplate = context.getRestOperations();
        ResponseEntity<String> queueData = restTemplate.getForEntity(context.getAPIURL("sast/scansQueue/" + scanId), String.class);
        String body = queueData.getBody();
        Access stage = context.json().fetch("stage", body);
        String value = stage.fetch("value").asText();
        details.stageValue = value;
        LOG.debug("Scan queue stage: {}. Checkmarx scan Id: {}.", details.stageValue, scanId);
        switch(details.stageValue) {
            case "New":
                if (!details.newQueueEntryFound) {
                    details.newQueueEntryFound = true;
                }
                break;
            case "Failed":
                if (!details.newQueueEntryFound) {
                    details.newQueueEntryFound = true;
                }
                details.failureText = context.json().fetch("stageDetails", body).asText();
                LOG.info("Scan queue stage failed. Failure text: {}", details.failureText);
                break;
            case "Finished":
                if (!details.newQueueEntryFound) {
                    details.newQueueEntryFound = true;
                }
                details.done = true;
                break;
            default:
                break;
        }
        details.checkCount++;
    } catch (HttpStatusCodeException e) {
        if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
            /* ok just no longer in queue / or never existed */
            details.done = true;
            return;
        }
        // rethrow
        throw e;
    }
}
Also used : Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) RestOperations(org.springframework.web.client.RestOperations)

Example 8 with Access

use of com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access in project sechub by mercedes-benz.

the class WaitForScanStateSupport method fetchScanDetails.

// https://checkmarx.atlassian.net/wiki/spaces/KC/pages/569442454/Get+SAST+Scan+Details+by+Scan+Id+-+GET+sast+scans+id+v8.8.0+and+up
private void fetchScanDetails(CheckmarxContext context) throws AdapterException {
    oauthSupport.refreshBearerTokenWhenNecessary(context);
    ScanDetails details = context.getScanDetails();
    long scanId = context.getSessionData().getScanId();
    try {
        LOG.debug("Downloading Checkmarx report for scan Id: {}.", scanId);
        RestOperations restTemplate = context.getRestOperations();
        ResponseEntity<String> queueData = restTemplate.getForEntity(context.getAPIURL("sast/scans/" + scanId), String.class);
        String body = queueData.getBody();
        Access status = context.json().fetch("status", body);
        String statusName = status.fetch("name").asText();
        details.statusName = statusName;
        LOG.debug("Scan status name: {}. Checkmarx scan Id: {}.", details.statusName, scanId);
    } catch (HttpStatusCodeException e) {
        if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
            /* ok just no longer in queue / or never existed */
            details.notFound = true;
            LOG.info("Unable to find Checkmarx scan Id: {}. Possible reasons: no longer in queue or never existed.", scanId);
            return;
        }
        // rethrow
        throw e;
    }
}
Also used : Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException) RestOperations(org.springframework.web.client.RestOperations)

Aggregations

Access (com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)8 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)3 RestOperations (org.springframework.web.client.RestOperations)3 CheckmarxSessionData (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CheckmarxEngineConfiguration (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration)1 CheckmarxSastScanSettings (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings)1 LinkedList (java.util.LinkedList)1