Search in sources :

Example 1 with Access

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

the class WaitForScanReportSupport method fetchScanDetails.

// https://checkmarx.atlassian.net/wiki/spaces/KC/pages/563806382/Get+Report+Status+by+Id+-+GET+reports+sastScan+id+status+v8.8.0+and+up
// https://checkmarx.atlassian.net/wiki/spaces/KC/pages/814121878/Swagger+Examples+v8.8.0+-+v1
private void fetchScanDetails(CheckmarxAdapterContext context) throws AdapterException {
    oauthSupport.refreshBearerTokenWhenNecessary(context);
    ReportDetails details = context.getReportDetails();
    long reportId = context.getReportId();
    try {
        LOG.debug("Fetching scan report status for Checkmarx report Id: {}.", reportId);
        RestOperations restTemplate = context.getRestOperations();
        ResponseEntity<String> queueData = restTemplate.getForEntity(context.getAPIURL("reports/sastScan/" + reportId + "/status"), String.class);
        String body = queueData.getBody();
        Access status = context.json().fetch("status", body);
        String value = status.fetch("value").asText();
        details.status = value;
        LOG.debug("Report status: {}. Checkmarx report Id: {}.", details.status, reportId);
        if (details.status.equalsIgnoreCase("failed")) {
            LOG.warn("Scan report status is: failed. Checkmarx report Id: {}.", reportId);
        }
    } 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 report Id: {}. Possible reasons: no longer in queue or never existed.", reportId);
            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 2 with Access

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

the class CheckmarxOAuthSupport method extractFromJson.

CheckmarxOAuthData extractFromJson(JSONAdapterSupport support, String json) throws AdapterException {
    CheckmarxOAuthData data = new CheckmarxOAuthData();
    Access rootNode = support.fetchRootNode(json);
    data.accessToken = rootNode.fetch("access_token").asText();
    data.tokenType = rootNode.fetch("token_type").asText();
    data.expiresInSeconds = rootNode.fetch("expires_in").asLong();
    return data;
}
Also used : Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)

Example 3 with Access

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

the class CheckmarxProjectSupport method extractFirstProjectFromJsonWithProjectArray.

CheckmarxSessionData extractFirstProjectFromJsonWithProjectArray(JSONAdapterSupport support, String json) throws AdapterException {
    CheckmarxSessionData data = new CheckmarxSessionData();
    Access rootNode = support.fetchRootNode(json);
    Access first = support.fetchArray(0, rootNode.asArray());
    data.setProjectId(first.fetch("id").asLong());
    data.setProjectName(first.fetch("name").asText());
    return data;
}
Also used : CheckmarxSessionData(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData) Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)

Example 4 with Access

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

the class CheckmarxProjectSupport method extractEngineConfigurationsFromGet.

protected List<CheckmarxEngineConfiguration> extractEngineConfigurationsFromGet(String json, JSONAdapterSupport support) throws AdapterException {
    Access rootNode = support.fetchRootNode(json);
    List<CheckmarxEngineConfiguration> engineConfigurations = new LinkedList<>();
    for (JsonNode node : rootNode.asArray()) {
        CheckmarxEngineConfiguration engineConfiguration = new CheckmarxEngineConfiguration();
        engineConfiguration.setId(node.get("id").asLong());
        engineConfiguration.setName(node.get("name").asText());
        engineConfigurations.add(engineConfiguration);
    }
    return engineConfigurations;
}
Also used : Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access) JsonNode(com.fasterxml.jackson.databind.JsonNode) CheckmarxEngineConfiguration(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration) LinkedList(java.util.LinkedList)

Example 5 with Access

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

the class CheckmarxProjectSupport method extractProjectFromJsonWithProjectCreationData.

CheckmarxSessionData extractProjectFromJsonWithProjectCreationData(String projectName, JSONAdapterSupport support, String json) throws AdapterException {
    CheckmarxSessionData data = new CheckmarxSessionData();
    Access rootNode = support.fetchRootNode(json);
    data.setProjectId(rootNode.fetch("id").asLong());
    data.setProjectName(projectName);
    return data;
}
Also used : CheckmarxSessionData(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSessionData) Access(com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)

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