use of com.checkmarx.sdk.dto.filtering.FilterConfiguration in project cx-flow by checkmarx-ltd.
the class ConfigurationOverrider method overrideFilters.
private void overrideFilters(FlowOverride flowOverride, ScanRequest request, Map<String, String> overrideReport) {
Optional.ofNullable(flowOverride.getFilters()).ifPresent(override -> {
FilterFactory filterFactory = new FilterFactory();
ControllerRequest controllerRequest = new ControllerRequest(override.getSeverity(), override.getCwe(), override.getCategory(), override.getStatus(), override.getState());
FilterConfiguration filterConfig = filterFactory.getFilter(controllerRequest, null);
request.setFilter(filterConfig);
String filterDescr;
List<Filter> simpleFilters = Optional.ofNullable(filterConfig).map(FilterConfiguration::getSastFilters).map(EngineFilterConfiguration::getSimpleFilters).orElse(null);
if (CollectionUtils.isNotEmpty(simpleFilters)) {
filterDescr = simpleFilters.stream().map(Object::toString).collect(Collectors.joining(","));
} else {
filterDescr = "EMPTY";
}
overrideReport.put("filters", filterDescr);
});
}
use of com.checkmarx.sdk.dto.filtering.FilterConfiguration in project cx-flow by checkmarx-ltd.
the class ConfigurationOverrider method overrideScanRequestProperties.
/**
* Override scan request details as per file/blob (MachinaOverride)
*/
public ScanRequest overrideScanRequestProperties(FlowOverride override, ScanRequest request) {
scaConfigOverrider.initScaConfig(request);
if (override == null) {
return request;
}
BugTracker bt = request.getBugTracker();
/*Override only applicable to Simple JIRA bug*/
if (request.getBugTracker().getType().equals(BugTracker.Type.JIRA) && override.getJira() != null) {
overrideJiraBugProperties(override, bt);
}
request.setBugTracker(bt);
if (!ScanUtils.empty(override.getApplication())) {
request.setApplication(override.getApplication());
}
if (!ScanUtils.empty(override.getBranches())) {
request.setActiveBranches(override.getBranches());
}
List<String> emails = override.getEmails();
if (emails != null) {
if (emails.isEmpty()) {
request.setEmail(null);
} else {
request.setEmail(emails);
}
}
FlowOverride.Filters filtersObj = override.getFilters();
if (filtersObj != null) {
FilterFactory filterFactory = new FilterFactory();
ControllerRequest controllerRequest = new ControllerRequest(filtersObj.getSeverity(), filtersObj.getCwe(), filtersObj.getCategory(), filtersObj.getStatus(), filtersObj.getState());
FilterConfiguration filter = filterFactory.getFilter(controllerRequest, null);
request.setFilter(filter);
}
return request;
}
use of com.checkmarx.sdk.dto.filtering.FilterConfiguration in project cx-flow by checkmarx-ltd.
the class BitbucketServerPushHandler method execute.
@Override
public ResponseEntity<EventResponse> execute(String uid) {
try {
// set the default bug tracker as per yml
webhookUtils.setBugTracker(configProvider.getFlowProperties(), controllerRequest);
BugTracker.Type bugType = ScanUtils.getBugTypeEnum(controllerRequest.getBug(), configProvider.getFlowProperties().getBugTrackerImpl());
Optional.ofNullable(controllerRequest.getAppOnly()).ifPresent(configProvider.getFlowProperties()::setTrackApplicationOnly);
ScanRequest.Product p = ScanRequest.Product.valueOf(product.toUpperCase(Locale.ROOT));
String currentBranch = ScanUtils.getBranchFromRef(branchFromRef);
List<String> branches = webhookUtils.getBranches(controllerRequest, configProvider.getFlowProperties());
String latestCommit = toHash;
BugTracker bt = ScanUtils.getBugTracker(controllerRequest.getAssignee(), bugType, configProvider.getJiraProperties(), controllerRequest.getBug());
FilterConfiguration filter = configProvider.getFilterFactory().getFilter(controllerRequest, configProvider.getFlowProperties());
String gitUrl = getGitUrl();
String gitAuthUrl = getGitAuthUrl(gitUrl);
ScanRequest request = ScanRequest.builder().application(application).product(p).project(controllerRequest.getProject()).team(controllerRequest.getTeam()).namespace(getNamespace()).repoName(repositoryName).repoUrl(gitUrl).repoUrlWithAuth(gitAuthUrl).repoType(ScanRequest.Repository.BITBUCKETSERVER).branch(currentBranch).refs(refId).email(emails).scanPreset(controllerRequest.getPreset()).incremental(controllerRequest.getIncremental()).excludeFolders(controllerRequest.getExcludeFolders()).excludeFiles(controllerRequest.getExcludeFiles()).bugTracker(bt).filter(filter).hash(latestCommit).build();
webhookUtils.setScmInstance(controllerRequest, request);
setBrowseUrl(request);
fillRequestWithCommonAdditionalData(request, toProjectKey, toSlug, webhookPayload);
checkForConfigAsCode(request);
request.setId(uid);
// only initiate scan/automation if target branch is applicable
if (configProvider.getHelperService().isBranch2Scan(request, branches)) {
configProvider.getFlowService().initiateAutomation(request);
}
} catch (IllegalArgumentException e) {
return webhookUtils.getBadRequestMessage(e, controllerRequest, product);
}
return webhookUtils.getSuccessMessage();
}
use of com.checkmarx.sdk.dto.filtering.FilterConfiguration in project cx-flow by checkmarx-ltd.
the class BitbucketCloudController method pushRequest.
/**
* Receive Push event submitted from Bitbucket
*/
@PostMapping(value = { "/{product}", "/" }, headers = PUSH)
public ResponseEntity<EventResponse> pushRequest(@RequestBody PushEvent body, @PathVariable(value = "product", required = false) String product, ControllerRequest controllerRequest, @RequestParam(value = "token") String token) {
log.debug("Push Request body contents are {}", body.toString());
String uid = helperService.getShortUid();
MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
validateBitBucketRequest(token);
controllerRequest = ensureNotNull(controllerRequest);
try {
Repository repository = body.getRepository();
String app = repository.getName();
if (!ScanUtils.empty(controllerRequest.getApplication())) {
app = controllerRequest.getApplication();
}
// set the default bug tracker as per yml
setBugTracker(flowProperties, controllerRequest);
BugTracker.Type bugType = ScanUtils.getBugTypeEnum(controllerRequest.getBug(), flowProperties.getBugTrackerImpl());
if (controllerRequest.getAppOnly() != null) {
flowProperties.setTrackApplicationOnly(controllerRequest.getAppOnly());
}
if (ScanUtils.empty(product)) {
product = ScanRequest.Product.CX.getProduct();
}
ScanRequest.Product p = ScanRequest.Product.valueOf(product.toUpperCase(Locale.ROOT));
List<Change> changeList = body.getPush().getChanges();
String currentBranch = null;
if (changeList != null) {
currentBranch = changeList.get(0).getNew().getName();
}
List<String> branches = getBranches(controllerRequest, flowProperties);
String hash = null;
if (changeList != null) {
hash = changeList.get(0).getNew().getTarget().getHash();
}
BugTracker bt = ScanUtils.getBugTracker(controllerRequest.getAssignee(), bugType, jiraProperties, controllerRequest.getBug());
FilterConfiguration filter = filterFactory.getFilter(controllerRequest, flowProperties);
/*Determine emails*/
List<String> emails = new ArrayList<>();
if (changeList != null) {
for (Change ch : changeList) {
for (Commit c : ch.getCommits()) {
String author = c.getAuthor().getRaw();
if (!ScanUtils.empty(author)) {
emails.add(author);
}
}
}
}
String gitUrl = repository.getLinks().getHtml().getHref().concat(".git");
String configToken = scmConfigOverrider.determineConfigToken(properties, controllerRequest.getScmInstance());
String gitAuthUrl = gitAuthUrlGenerator.addCredToUrl(ScanRequest.Repository.BITBUCKET, gitUrl, configToken);
ScanRequest request = ScanRequest.builder().application(app).product(p).project(controllerRequest.getProject()).team(controllerRequest.getTeam()).namespace(getProjectNamespace(repository)).repoName(repository.getName()).repoUrl(gitUrl).repoUrlWithAuth(gitAuthUrl).repoType(ScanRequest.Repository.BITBUCKET).branch(currentBranch).refs(Constants.CX_BRANCH_PREFIX.concat(currentBranch)).email(emails).scanPreset(controllerRequest.getPreset()).incremental(controllerRequest.getIncremental()).excludeFolders(controllerRequest.getExcludeFolders()).excludeFiles(controllerRequest.getExcludeFiles()).bugTracker(bt).filter(filter).hash(hash).organizationId(getOrganizationid(repository)).gitUrl(gitUrl).build();
setScmInstance(controllerRequest, request);
fillRequestWithAdditionalData(request, repository, body.toString());
checkForConfigAsCode(request);
request.setId(uid);
if (helperService.isBranch2Scan(request, branches)) {
flowService.initiateAutomation(request);
}
} catch (IllegalArgumentException e) {
return getBadRequestMessage(e, controllerRequest, product);
}
return getSuccessMessage();
}
use of com.checkmarx.sdk.dto.filtering.FilterConfiguration in project cx-flow by checkmarx-ltd.
the class BitbucketCloudController method handleMergeEvent.
public ResponseEntity<EventResponse> handleMergeEvent(MergeEvent body, String product, ControllerRequest controllerRequest, String token) {
log.debug("Merge Request body contents are {}", body.toString());
String uid = helperService.getShortUid();
MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
validateBitBucketRequest(token);
log.info("Processing BitBucket MERGE request");
controllerRequest = ensureNotNull(controllerRequest);
try {
Repository repository = body.getRepository();
String app = repository.getName();
if (!ScanUtils.empty(controllerRequest.getApplication())) {
app = controllerRequest.getApplication();
}
BugTracker.Type bugType = BugTracker.Type.BITBUCKETPULL;
if (!ScanUtils.empty(controllerRequest.getBug())) {
bugType = ScanUtils.getBugTypeEnum(controllerRequest.getBug(), flowProperties.getBugTrackerImpl());
}
if (controllerRequest.getAppOnly() != null) {
flowProperties.setTrackApplicationOnly(controllerRequest.getAppOnly());
}
if (ScanUtils.empty(product)) {
product = ScanRequest.Product.CX.getProduct();
}
ScanRequest.Product p = ScanRequest.Product.valueOf(product.toUpperCase(Locale.ROOT));
Pullrequest pullRequest = body.getPullrequest();
String currentBranch = pullRequest.getSource().getBranch().getName();
String targetBranch = pullRequest.getDestination().getBranch().getName();
List<String> branches = getBranches(controllerRequest, flowProperties);
String hash = pullRequest.getSource().getCommit().getHash();
BugTracker bt = ScanUtils.getBugTracker(controllerRequest.getAssignee(), bugType, jiraProperties, controllerRequest.getBug());
FilterConfiguration filter = filterFactory.getFilter(controllerRequest, flowProperties);
String gitUrl = repository.getLinks().getHtml().getHref().concat(".git");
String configToken = scmConfigOverrider.determineConfigToken(properties, controllerRequest.getScmInstance());
String gitAuthUrl = gitAuthUrlGenerator.addCredToUrl(ScanRequest.Repository.BITBUCKET, gitUrl, configToken);
String mergeEndpoint = pullRequest.getLinks().getComments().getHref();
ScanRequest request = ScanRequest.builder().application(app).product(p).project(controllerRequest.getProject()).team(controllerRequest.getTeam()).namespace(getProjectNamespace(repository)).repoName(repository.getName()).repoUrl(gitUrl).repoUrlWithAuth(gitAuthUrl).repoType(ScanRequest.Repository.BITBUCKET).branch(currentBranch).mergeTargetBranch(targetBranch).mergeNoteUri(mergeEndpoint).refs(Constants.CX_BRANCH_PREFIX.concat(currentBranch)).email(null).scanPreset(controllerRequest.getPreset()).incremental(controllerRequest.getIncremental()).excludeFolders(controllerRequest.getExcludeFolders()).excludeFiles(controllerRequest.getExcludeFiles()).bugTracker(bt).filter(filter).hash(hash).organizationId(getOrganizationid(repository)).gitUrl(gitUrl).build();
setScmInstance(controllerRequest, request);
fillRequestWithAdditionalData(request, repository, body.toString());
checkForConfigAsCode(request);
request.setId(uid);
if (helperService.isBranch2Scan(request, branches)) {
flowService.initiateAutomation(request);
}
} catch (IllegalArgumentException e) {
return getBadRequestMessage(e, controllerRequest, product);
}
return getSuccessMessage();
}
Aggregations