use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class GitLabIssueTracker method createIssue.
@Override
public Issue createIssue(ScanResults.XIssue resultIssue, ScanRequest request) throws MachinaException {
log.debug("Executing createIssue GitLab API call");
String endpoint = scmConfigOverrider.determineConfigApiUrl(properties, request).concat(NEW_ISSUE_PATH);
ResponseEntity<com.checkmarx.flow.dto.gitlab.Issue> response;
try {
HttpEntity<String> httpEntity = new HttpEntity<>(getJSONCreateIssue(resultIssue, request).toString(), createAuthHeaders(request));
response = restTemplate.exchange(endpoint, HttpMethod.POST, httpEntity, com.checkmarx.flow.dto.gitlab.Issue.class, request.getRepoProjectId());
} catch (HttpClientErrorException e) {
log.error("Error occurred while creating GitLab Issue", e);
if (e.getStatusCode().equals(HttpStatus.GONE)) {
throw new MachinaException("Issues are not enabled for this repository");
} else {
throw new MachinaException("Error occurred while creating GitLab Issue");
}
}
return mapToIssue(response.getBody());
}
use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class ImmutableIssueTracker method fileInit.
/**
* Common function for initializing file based bug trackers
*/
public void fileInit(ScanRequest request, ScanResults results, String filePath, FilenameFormatter filenameFormatter, Logger log) throws MachinaException {
Path fullPath = Paths.get(filePath);
Path parentDir = fullPath.getParent();
Path filename = fullPath.getFileName();
if (request == null || results == null) {
throw new MachinaException("Request or Results object is missing");
}
String formattedPath = filenameFormatter.formatPath(request, filename.toString(), parentDir.toString());
request.setFilename(formattedPath);
log.info("Creating file {}", formattedPath);
try {
Files.deleteIfExists(Paths.get(formattedPath));
Files.createFile(Paths.get(formattedPath));
} catch (IOException e) {
log.error("Issue deleting existing file or writing initial {}", filename, e);
}
}
use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class JsonIssueTracker 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);
} 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();
}
}
use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class SarifIssueTrackerTest method initWithNullPropertiesNullParameters.
@Test
public void initWithNullPropertiesNullParameters() {
SarifProperties properties = new SarifProperties();
properties.setFilePath("./cx.sarif");
FilenameFormatter filenameFormatter = new SanitizingFilenameFormatter();
SarifIssueTracker sarifIssueTracker = new SarifIssueTracker(properties, filenameFormatter);
try {
sarifIssueTracker.init(null, null);
assert false;
} catch (MachinaException e) {
assert true;
}
}
use of com.checkmarx.flow.exception.MachinaException in project cx-flow by checkmarx-ltd.
the class SCAScanner method cxParseResults.
@Override
protected void cxParseResults(ScanRequest scanRequest, File file) throws ExitThrowable {
RestClientConfig restClientConfig;
IScanClientHelper iScanClientHelper;
try {
ScanParams sdkScanParams = ScanParams.builder().projectName(scanRequest.getProject()).scaConfig(scanRequest.getScaConfig()).filterConfiguration(scanRequest.getFilter()).build();
restClientConfig = scaScannerClient.getScanConfig(sdkScanParams);
iScanClientHelper = new ScaClientHelper(restClientConfig, log, scaProperties);
ScanResults results = iScanClientHelper.getReportContent(file, scanRequest.getFilter());
resultsService.processResults(scanRequest, results, scanDetails);
if (flowProperties.isBreakBuild() && results != null && results.getXIssues() != null && !results.getXIssues().isEmpty()) {
log.error(ERROR_BREAK_MSG);
exit(ExitCode.BUILD_INTERRUPTED);
}
} catch (MachinaException | CheckmarxException e) {
log.error("Error occurred while processing results file", e);
exit(3);
}
}
Aggregations