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