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;
}
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;
}
}
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;
}
}
Aggregations