Search in sources :

Example 1 with CheckmarxEngineConfiguration

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));
}
Also used : CheckmarxEngineConfiguration(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with CheckmarxEngineConfiguration

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;
}
Also used : CheckmarxAdapterConfig(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig) CheckmarxSastScanSettings(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings) CheckmarxEngineConfiguration(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration)

Example 3 with CheckmarxEngineConfiguration

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);
}
Also used : CheckmarxEngineConfiguration(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration)

Example 4 with CheckmarxEngineConfiguration

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

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;
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) RestOperations(org.springframework.web.client.RestOperations) CheckmarxEngineConfiguration(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration)

Aggregations

CheckmarxEngineConfiguration (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxEngineConfiguration)8 LinkedList (java.util.LinkedList)4 Test (org.junit.Test)4 CheckmarxSastScanSettings (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxSastScanSettings)3 CheckmarxConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxConfig)2 CheckmarxConfigBuilder (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxConfig.CheckmarxConfigBuilder)2 InternalUpdateContext (com.mercedesbenz.sechub.adapter.checkmarx.support.CheckmarxProjectSupport.InternalUpdateContext)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CheckmarxAdapterConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig)1 Access (com.mercedesbenz.sechub.adapter.support.JSONAdapterSupport.Access)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 RestOperations (org.springframework.web.client.RestOperations)1