use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration in project sechub by mercedes-benz.
the class CheckmarxProjectSupportTest method findEngineConfigurationByName.
@Test
public void findEngineConfigurationByName() {
/* prepare */
List<CheckmarxEngineConfiguration> engineConfigurations = new LinkedList<>();
CheckmarxEngineConfiguration defaultConfiguration = new CheckmarxEngineConfiguration();
defaultConfiguration.setId(1L);
defaultConfiguration.setName("Default Configuration");
CheckmarxEngineConfiguration testConfiguration = new CheckmarxEngineConfiguration();
testConfiguration.setId(3L);
testConfiguration.setName("test");
CheckmarxEngineConfiguration multiLanguageScanConfiguration = new CheckmarxEngineConfiguration();
multiLanguageScanConfiguration.setId(5L);
multiLanguageScanConfiguration.setName(CheckmarxConstants.DEFAULT_CHECKMARX_ENGINECONFIGURATION_MULTILANGANGE_SCAN_NAME);
engineConfigurations.add(testConfiguration);
engineConfigurations.add(defaultConfiguration);
engineConfigurations.add(multiLanguageScanConfiguration);
/* execute */
CheckmarxEngineConfiguration actualEngineConfiguration = supportToTest.findEngineConfigurationByName(CheckmarxConstants.DEFAULT_CHECKMARX_ENGINECONFIGURATION_MULTILANGANGE_SCAN_NAME, engineConfigurations);
/* test */
assertThat(actualEngineConfiguration, notNullValue());
assertThat(actualEngineConfiguration, is(multiLanguageScanConfiguration));
}
use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration in project sechub by mercedes-benz.
the class CheckmarxProjectSupport method updatePresetIdAndEngineConfigurationIfNecessary.
protected boolean updatePresetIdAndEngineConfigurationIfNecessary(CheckmarxContext context, CheckmarxSessionData sessionData) throws AdapterException {
boolean updated = false;
InternalUpdateContext updateContext = new InternalUpdateContext();
CheckmarxAdapterConfig config = context.getConfig();
CheckmarxSastScanSettings checkmarxSastScanSettings = fetchCurrentSastScanSettings(context, sessionData);
List<CheckmarxEngineConfiguration> engineConfigurations = fetchEngineConfigurations(context, sessionData);
updatePresetIdWhenSetInAdapterConfig(config, checkmarxSastScanSettings, updateContext);
updateEngineCondfigurationIdWhenSecHubAndCheckmarxDiffer(config, engineConfigurations, checkmarxSastScanSettings, updateContext);
/* check if the engine configuration needs to be updated */
if (updateContext.isUpdateNecessary()) {
LOG.debug("Update scan settings.");
updateSastScanSettings(context, updateContext.getPresetId(), updateContext.getEngineConfigurationId(), checkmarxSastScanSettings);
if (updateContext.isUpdateOfPresetIdNecessary()) {
LOG.debug("Updated preset id {}", updateContext.getPresetId());
}
if (updateContext.isUpdateOfEngineConfigurationNecessary()) {
LOG.debug("Updated engine configuration id {}", updateContext.getEngineConfigurationId());
}
updated = true;
} else {
LOG.debug("No update necessary.");
}
return updated;
}
use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration in project sechub by mercedes-benz.
the class CheckmarxProjectSupport method updateEngineCondfigurationIdWhenSecHubAndCheckmarxDiffer.
protected void updateEngineCondfigurationIdWhenSecHubAndCheckmarxDiffer(CheckmarxAdapterConfig config, List<CheckmarxEngineConfiguration> engineConfigurations, CheckmarxSastScanSettings checkmarxScanSettings, InternalUpdateContext updateContext) {
boolean updateEngineConfiguration = false;
String sechubEngineConfigurationName = config.getEngineConfigurationName();
String projectId = config.getProjectId();
long engineConfigurationId = checkmarxScanSettings.getEngineConfigurationId();
LOG.debug("SecHub engine configuration name {}", sechubEngineConfigurationName);
CheckmarxEngineConfiguration sechubEngineConfiguration = findEngineConfigurationByName(sechubEngineConfigurationName, engineConfigurations);
if (sechubEngineConfiguration == null) {
LOG.warn("[ALERT] ILLEGAL_STATE CHECKMARX_ADAPTER no engine configuration available!");
} else {
LOG.debug("Found SecHub engine configuration {}", sechubEngineConfiguration.toString());
if (sechubEngineConfiguration.getId() != engineConfigurationId) {
LOG.debug("SecHub engine configuration id {} and Checkmarx engine configuration id {} are different.", sechubEngineConfiguration.getId(), engineConfigurationId);
LOG.debug("Wanted engine configuration id {} for project {}", sechubEngineConfiguration.getId(), projectId);
engineConfigurationId = sechubEngineConfiguration.getId();
updateEngineConfiguration = true;
} else {
LOG.debug("Engine configuration id is already set to {} for project", sechubEngineConfigurationName, projectId);
}
}
updateContext.setUpdateEngineConfiguration(updateEngineConfiguration);
updateContext.setEngineConfigurationId(engineConfigurationId);
}
use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration 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;
}
use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration in project sechub by mercedes-benz.
the class CheckmarxProjectSupport method fetchEngineConfigurations.
private List<CheckmarxEngineConfiguration> fetchEngineConfigurations(CheckmarxContext context, CheckmarxSessionData sessionData) throws AdapterException {
List<CheckmarxEngineConfiguration> engineConfigurations;
// https://checkmarx.atlassian.net/wiki/spaces/KC/pages/223543515/Get+All+Engine+Configurations+-+GET+sast+engineConfigurations+v8.6.0+and+up
MultiValueMap<String, String> headers2 = new LinkedMultiValueMap<>();
headers2.set("Content-Type", "application/json;v=1.1");
RestOperations restTemplate2 = context.getRestOperations();
/* read engine configurations */
String fetchEngineConfigurationsURL = context.getAPIURL("sast/engineConfigurations");
ResponseEntity<String> engineConfigurationsResponse = restTemplate2.getForEntity(fetchEngineConfigurationsURL, String.class);
engineConfigurations = extractEngineConfigurationsFromGet(engineConfigurationsResponse.getBody(), context.json());
return engineConfigurations;
}
Aggregations