use of com.checkmarx.flow.config.FlowProperties in project cx-flow by checkmarx-ltd.
the class TfsController method pullPushRequest.
@PostMapping(value = { "/{product}/tfs/pull", "/tfs/pull", "/{product}/tfs/push", "/tfs/push" })
public ResponseEntity<EventResponse> pullPushRequest(HttpServletRequest httpRequest, @RequestBody PullEvent body, @RequestHeader(value = AUTHORIZATION) String auth, @PathVariable(value = "product", required = false) String product, ControllerRequest controllerRequest, AdoDetailsRequest adoDetailsRequest) {
String action = getAction(httpRequest);
String uid = helperService.getShortUid();
MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
if (log.isInfoEnabled()) {
log.info(String.format("Processing TFS %s request", action));
}
validateBasicAuth(auth);
Resource resource = body.getResource();
controllerRequest = ensureNotNull(controllerRequest);
adoDetailsRequest = ensureDetailsNotNull(adoDetailsRequest);
if (ACTION_PULL.equals(action) && !body.getEventType().equals(PULL_EVENT)) {
log.info("Pull requested not processed. Event was not 'opened' ({})", body.getEventType());
return ResponseEntity.accepted().body(EventResponse.builder().message("No processing occurred for updates to Pull Request").success(true).build());
}
FlowOverride o = ScanUtils.getMachinaOverride(Optional.ofNullable(controllerRequest.getOverride()).orElse(null));
Repository repository = resource.getRepository();
String app = repository.getName();
if (app.startsWith(properties.getTestRepository())) {
log.info("Handling TFS Test Event");
return ResponseEntity.ok(EventResponse.builder().message("Test Event").success(true).build());
}
Optional.ofNullable(controllerRequest.getAppOnly()).ifPresent(flowProperties::setTrackApplicationOnly);
FilterConfiguration filter = filterFactory.getFilter(controllerRequest, flowProperties);
ScanRequestBuilder requestBuilder = ScanRequest.builder().application(Optional.ofNullable(controllerRequest.getApplication()).orElse(app)).product(getProductForName(product)).project(Optional.ofNullable(controllerRequest.getProject()).orElse(null)).team(Optional.ofNullable(controllerRequest.getTeam()).orElse(null)).namespace(repository.getProject().getName().replace(" ", "_")).repoName(repository.getName()).repoType(ScanRequest.Repository.ADO).scanPreset(controllerRequest.getPreset()).incremental(controllerRequest.getIncremental()).excludeFolders(controllerRequest.getExcludeFolders()).excludeFiles(controllerRequest.getExcludeFiles()).filter(filter);
if (ACTION_PULL.equals(action)) {
BugTracker.Type bugType = Optional.ofNullable(controllerRequest.getBug()).map(theBug -> ScanUtils.getBugTypeEnum(theBug, flowProperties.getBugTrackerImpl())).orElse(BugTracker.Type.ADOPULL);
Optional.ofNullable(controllerRequest.getAppOnly()).ifPresent(flowProperties::setTrackApplicationOnly);
BugTracker bugTracker = ScanUtils.getBugTracker(Optional.ofNullable(controllerRequest.getAssignee()).orElse(null), bugType, jiraProperties, Optional.ofNullable(controllerRequest.getBug()).orElse(null));
requestBuilder.refs(resource.getSourceRefName()).repoUrl(repository.getWebUrl()).repoUrlWithAuth(addTokenToUrl(repository.getWebUrl(), properties.getToken())).mergeNoteUri(resource.getUrl().concat("/threads")).branch(ScanUtils.getBranchFromRef(resource.getSourceRefName())).mergeTargetBranch(ScanUtils.getBranchFromRef(resource.getTargetRefName())).email(null).bugTracker(bugTracker);
} else if (ACTION_PUSH.equals(action)) {
String bug = Optional.ofNullable(controllerRequest.getBug()).orElse(flowProperties.getBugTracker());
BugTracker.Type bugType = ScanUtils.getBugTypeEnum(bug, flowProperties.getBugTrackerImpl());
BugTracker bugTracker = ScanUtils.getBugTracker(Optional.ofNullable(controllerRequest.getAssignee()).orElse(null), bugType, jiraProperties, Optional.ofNullable(controllerRequest.getBug()).orElse(null));
requestBuilder.refs(resource.getRefUpdates().get(0).getName()).repoUrl(repository.getRemoteUrl()).repoUrlWithAuth(addTokenToUrl(repository.getRemoteUrl(), properties.getToken())).branch(ScanUtils.getBranchFromRef(resource.getRefUpdates().get(0).getName())).defaultBranch(repository.getDefaultBranch()).email(determineEmails(resource)).bugTracker(bugTracker);
}
ScanRequest request = requestBuilder.build();
request = configOverrider.overrideScanRequestProperties(o, request);
if (ACTION_PULL.equals(action)) {
request.putAdditionalMetadata("statuses_url", resource.getUrl().concat("/statuses"));
}
addMetadataToScanRequest(adoDetailsRequest, request);
request.putAdditionalMetadata(HTMLHelper.WEB_HOOK_PAYLOAD, body.toString());
request.setId(uid);
// only initiate scan/automation if target branch is applicable
List<String> branches = new ArrayList<>();
Optional<List<String>> branch = Optional.ofNullable(controllerRequest.getBranch());
if (branch.isPresent()) {
branches.addAll(branch.get());
} else if (CollectionUtils.isNotEmpty(flowProperties.getBranches())) {
branches.addAll(flowProperties.getBranches());
}
if (helperService.isBranch2Scan(request, branches)) {
flowService.initiateAutomation(request);
}
return ResponseEntity.accepted().body(EventResponse.builder().message("Scan Request Successfully Submitted").success(true).build());
}
use of com.checkmarx.flow.config.FlowProperties in project cx-flow by checkmarx-ltd.
the class HelperServiceTest method testGetPresetFromSources.
@Test
public void testGetPresetFromSources() {
FlowProperties properties = new FlowProperties();
CxProperties cxProperties = new CxProperties();
JiraProperties jiraProperties = new JiraProperties();
cxProperties.setScanPreset(Constants.CX_DEFAULT_PRESET);
CxScannerService cxScannerService = new CxScannerService(cxProperties, null, null, null, null);
HelperService helperService = new HelperService(properties, cxScannerService, jiraProperties, null);
Sources sources = new Sources();
Sources.Source src1 = new Sources.Source();
src1.setFile("abc.java");
src1.setPath("abc.java");
Sources.Source src2 = new Sources.Source();
src2.setFile("abc.html");
src2.setPath("abc.html");
Sources.Source src3 = new Sources.Source();
src3.setFile("abc.css");
src3.setPath("abc.css");
Sources.Source src4 = new Sources.Source();
src4.setFile("buildspec.yml");
src4.setPath("buildspec.yml");
Map<String, Integer> sourceWeight = new HashMap<>();
sourceWeight.put("Java", 65);
sourceWeight.put("CSS", 15);
sourceWeight.put("HTML", 20);
sources.setLanguageStats(sourceWeight);
sources.setSources(Arrays.asList(src1, src2, src3, src4));
ObjectMapper mapper = new ObjectMapper();
System.out.println(HelperService.class.getResource(".").getPath());
File file = new File(getClass().getClassLoader().getResource("CxProfile.json").getFile());
try {
CxProfile[] cxProfiles = mapper.readValue(file, CxProfile[].class);
helperService.setProfiles(Arrays.asList(cxProfiles));
String preset = helperService.getPresetFromSources(sources);
assertEquals(preset, "Checkmarx Express");
} catch (IOException e) {
fail("Unexpected IO Exception");
}
}
use of com.checkmarx.flow.config.FlowProperties in project cx-flow by checkmarx-ltd.
the class ScanUtilsTest method setup.
@Before
public void setup() {
flowProperties = new FlowProperties();
flowProperties.setBugTrackerImpl(Arrays.asList("JIRA", "GitHub", "GitLab"));
configOverrider = new ConfigurationOverrider(flowProperties, cxIntegrationsProperties, scaScanner, sastScanner, cxgoScanner, scaConfigOverrider, reposManagerService, gitAuthUrlGenerator);
}
Aggregations