use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class ResultsService method processScanResultsAsync.
@Async("scanRequest")
public CompletableFuture<ScanResults> processScanResultsAsync(ScanRequest request, Integer projectId, Integer scanId, String osaScanId, FilterConfiguration filterConfiguration) throws MachinaException {
try {
CompletableFuture<ScanResults> future = new CompletableFuture<>();
// TODO async these, and join and merge after
ScanResults results = cxScannerService.getScannerClient().getReportContentByScanId(scanId, filterConfiguration);
logGetResultsJsonLogger(request, scanId, results);
results = getOSAScan(request, projectId, osaScanId, filterConfiguration, results);
sendEmailNotification(request, results);
processResults(request, results, new ScanDetails(projectId, scanId, osaScanId));
logScanDetails(request, projectId, results);
future.complete(results);
return future;
} catch (Exception e) {
log.error("Error occurred while processing results.", e);
CompletableFuture<ScanResults> x = new CompletableFuture<>();
x.completeExceptionally(e);
return x;
}
}
use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class ResultsService method getCxFields.
private void getCxFields(ScanRequest request, ScanResults results) throws MachinaException {
try {
/*Are cx fields required?*/
if (!requiresCxCustomFields(request.getBugTracker().getFields())) {
return;
}
/*if so, then get them and add them to the request object*/
if (!ScanUtils.empty(results.getProjectId()) && !results.getProjectId().equals(Constants.UNKNOWN)) {
CxProject project = cxScannerService.getScannerClient().getProject(Integer.parseInt(results.getProjectId()));
Map<String, String> fields = new HashMap<>();
for (CxProject.CustomField field : project.getCustomFields()) {
if (!ScanUtils.empty(field.getName()) && !ScanUtils.empty(field.getValue())) {
fields.put(field.getName(), field.getValue());
}
}
if (!fields.isEmpty()) {
request.setCxFields(fields);
if (!ScanUtils.empty(cxScannerService.getProperties().getJiraProjectField())) {
String jiraProject = fields.get(cxScannerService.getProperties().getJiraProjectField());
if (!ScanUtils.empty(jiraProject)) {
request.getBugTracker().setProjectKey(jiraProject);
}
}
if (!ScanUtils.empty(cxScannerService.getProperties().getJiraIssuetypeField())) {
String jiraIssuetype = fields.get(cxScannerService.getProperties().getJiraIssuetypeField());
if (!ScanUtils.empty(jiraIssuetype)) {
request.getBugTracker().setIssueType(jiraIssuetype);
}
}
}
}
} catch (InvalidCredentialsException e) {
log.warn("Error retrieving Checkmarx Project details for {}, no custom fields will be available", results.getProjectId(), e);
throw new MachinaException("Error logging into Checkmarx");
}
}
use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class ThresholdsSteps method processScanResultsInCxFlow.
private void processScanResultsInCxFlow(boolean isGitHub) {
try {
ScanRequest scanRequest = createScanRequest(isGitHub);
CompletableFuture<ScanResults> task = resultsService.processScanResultsAsync(scanRequest, 0, 0, null, null);
task.get(1, TimeUnit.MINUTES);
} catch (MachinaException | InterruptedException | ExecutionException | TimeoutException e) {
String message = "Error processing scan results.";
log.error(message, e);
Assert.fail(message);
Thread.currentThread().interrupt();
}
}
use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class ServiceNowTracker method init.
@Override
public void init(ScanRequest request, ScanResults results) throws MachinaException {
log.info("Initializing Service Now Tracker");
if (ScanUtils.empty(request.getNamespace()) || ScanUtils.empty(request.getRepoName()) || ScanUtils.empty(request.getBranch())) {
throw new MachinaException("Namespace / RepoName / Branch are required");
}
if (ScanUtils.empty(properties.getApiUrl())) {
throw new MachinaException("Service Now API Url must be provided in property config");
}
if (ScanUtils.empty(properties.getUsername()) || ScanUtils.empty(properties.getPassword())) {
throw new MachinaException("Service Now API Rest Call requires username and password");
}
restOperations = new RestTemplateBuilder().basicAuthentication(properties.getUsername(), properties.getPassword()).build();
createSeviceNowTags(request);
}
use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class WebPostIssueTracker method complete.
@Override
public void complete(ScanRequest request, ScanResults results) throws MachinaException {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
if (request != null && results != null) {
mapper.writeValue(new File(request.getFilename()).getCanonicalFile(), results);
String resultUrl = request.getAdditionalMetadata("result_url");
String filename = request.getFilename();
if (ScanUtils.anyEmpty(resultUrl, filename)) {
log.error("result_url | temporary file was massing from the ScanRequest metadata");
throw new MachinaException();
}
File resultFile = new File(filename);
log.info("Saving file {} to signed web url", filename);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<byte[]> entity = new HttpEntity<>(Files.readAllBytes(Paths.get(resultFile.getCanonicalPath())), headers);
URI uri = new URI(resultUrl);
restTemplate.put(uri, entity);
log.info("Save successful");
} else {
log.error("No request or results provided");
throw new MachinaException();
}
} catch (IOException e) {
log.error("Issue occurred while writing file {}", request.getFilename(), e);
throw new MachinaException();
} catch (URISyntaxException e) {
log.error("Error occurred: {}", ExceptionUtils.getMessage(e), e);
throw new MachinaException();
} catch (HttpClientErrorException e) {
log.error("HttpClientErrorException occurred: {}", ExceptionUtils.getMessage(e), e);
throw new MachinaException();
}
}
Aggregations