Search in sources :

Example 1 with ConfigProvider

use of com.checkmarx.configprovider.ConfigProvider in project cx-flow by checkmarx-ltd.

the class GitHubService method initConfigProviderOnPushEvent.

public void initConfigProviderOnPushEvent(String uid, PushEvent event) {
    if (properties != null) {
        try {
            ConfigProvider configProvider = ConfigProvider.getInstance();
            Repository repository = event.getRepository();
            // According to GitHub the recommended way to extract the branch name
            // is by using the 'ref' parameter which is in the following format: 'refs/heads/<branch>'
            configProvider.init(uid, new RepoReader(properties.getApiUrl(), repository.getOwner().getName(), repository.getName(), ScanUtils.getBranchFromRef(event.getRef()), properties.getToken(), SourceProviderType.GITHUB));
        } catch (ConfigurationException e) {
            log.warn("Failed to init config provider with the following error: {}", e.getMessage());
        }
    }
}
Also used : Repository(com.checkmarx.flow.dto.github.Repository) RepoReader(com.checkmarx.configprovider.readers.RepoReader) ConfigProvider(com.checkmarx.configprovider.ConfigProvider) ConfigurationException(javax.naming.ConfigurationException)

Example 2 with ConfigProvider

use of com.checkmarx.configprovider.ConfigProvider in project cx-flow by checkmarx-ltd.

the class ConfigurationOverrider method overrideScanRequestProperties.

public ScanRequest overrideScanRequestProperties(CxConfig override, ScanRequest request) {
    if (request == null) {
        log.warn("Unable to override scan request properties. Scan request is null.");
        return null;
    }
    Map<String, String> overrideReport = new HashMap<>();
    applyCxGoDynamicConfig(overrideReport, request);
    scaConfigOverrider.initScaConfig(request);
    ConfigProvider configProvider = ConfigProvider.getInstance();
    boolean noOverridesArePresent = !configProviderResultsAreAvailable(configProvider) && !configAsCodeIsAvailable(override);
    if (noOverridesArePresent) {
        log.debug("No scan request property overrides were detected.");
        return request;
    }
    overrideMainProperties(Optional.ofNullable(override), request, overrideReport);
    try {
        overrideAdditionalProperties(override, request, overrideReport);
        String overriddenProperties = ScanUtils.convertMapToString(overrideReport);
        log.info("The following properties were overridden by config-as-code file: {}", overriddenProperties);
    } catch (IllegalArgumentException e) {
        log.warn("Error parsing cxFlow object from CxConfig.", e);
    }
    return request;
}
Also used : ConfigProvider(com.checkmarx.configprovider.ConfigProvider)

Example 3 with ConfigProvider

use of com.checkmarx.configprovider.ConfigProvider in project cx-flow by checkmarx-ltd.

the class ConfigurationOverrider method overrideUsingConfigProvider.

private void overrideUsingConfigProvider(Optional<CxConfig> fallback, Map<String, String> overrideReport, ScanRequest request) {
    ConfigProvider configProvider = ConfigProvider.getInstance();
    String uid = MDC.get(FlowConstants.MAIN_MDC_ENTRY);
    ScaConfig scaConfiguration = configProvider.getConfiguration(uid, ScaProperties.CONFIG_PREFIX, ScaConfig.class);
    if (scaConfiguration != null) {
        log.info("Overriding SCA properties from config provider configuration");
        scaConfigOverrider.overrideScanRequestProperties(scaConfiguration, request, overrideReport);
    } else {
        Sca scaPropertiesFromConfigAsCode = fallback.map(CxConfig::getSca).orElse(null);
        scaConfigOverrider.overrideScanRequestProperties(scaPropertiesFromConfigAsCode, request, overrideReport);
    }
    ASTConfig astConfiguration = configProvider.getConfiguration(uid, AstProperties.CONFIG_PREFIX, ASTConfig.class);
    if (astConfiguration != null) {
        log.info("Overriding AST properties from config provider configuration");
        overridePropertiesAst(astConfiguration, overrideReport, request);
    }
}
Also used : Sca(com.checkmarx.sdk.dto.sca.Sca) ConfigProvider(com.checkmarx.configprovider.ConfigProvider) ASTConfig(com.checkmarx.flow.config.external.ASTConfig)

Example 4 with ConfigProvider

use of com.checkmarx.configprovider.ConfigProvider in project cx-flow by checkmarx-ltd.

the class GitHubService method initConfigProviderOnPullEvent.

public void initConfigProviderOnPullEvent(String uid, PullEvent event) {
    if (properties != null) {
        try {
            ConfigProvider configProvider = ConfigProvider.getInstance();
            Repository repository = event.getRepository();
            String branch = event.getPullRequest().getHead().getRef();
            configProvider.init(uid, new RepoReader(properties.getApiUrl(), repository.getOwner().getLogin(), repository.getName(), branch, properties.getToken(), SourceProviderType.GITHUB));
        } catch (ConfigurationException e) {
            log.warn("Failed to init config provider with the following error: {}", e.getMessage());
        }
    }
}
Also used : Repository(com.checkmarx.flow.dto.github.Repository) RepoReader(com.checkmarx.configprovider.readers.RepoReader) ConfigProvider(com.checkmarx.configprovider.ConfigProvider) ConfigurationException(javax.naming.ConfigurationException)

Example 5 with ConfigProvider

use of com.checkmarx.configprovider.ConfigProvider in project cx-flow by checkmarx-ltd.

the class ConfigProviderRemoteRepoSteps method initConfigProvider.

@When("initializing config provider")
public void initConfigProvider() throws ConfigurationException {
    String nameSpace = "cxflowtestuser";
    String repoName = "configProviderTestRepo";
    String branchName = "main";
    ConfigProvider configProvider = ConfigProvider.getInstance();
    configProvider.init(uid, new RepoReader(gitHubProperties.getApiUrl(), nameSpace, repoName, branchName, gitHubProperties.getToken(), sourceProviderType));
}
Also used : RepoReader(com.checkmarx.configprovider.readers.RepoReader) ConfigProvider(com.checkmarx.configprovider.ConfigProvider) When(io.cucumber.java.en.When)

Aggregations

ConfigProvider (com.checkmarx.configprovider.ConfigProvider)5 RepoReader (com.checkmarx.configprovider.readers.RepoReader)3 Repository (com.checkmarx.flow.dto.github.Repository)2 ConfigurationException (javax.naming.ConfigurationException)2 ASTConfig (com.checkmarx.flow.config.external.ASTConfig)1 Sca (com.checkmarx.sdk.dto.sca.Sca)1 When (io.cucumber.java.en.When)1