use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class ServiceNowTracker method createIssue.
@Override
public Issue createIssue(ScanResults.XIssue resultIssue, ScanRequest request) throws MachinaException {
log.debug("Executing createIssue ServiceNow API call");
String errorMessage = "Error occurred while creating ServiceNow Issue";
try {
Incident incident = getCreateIncident(resultIssue, request);
String query = String.format("%s%s", properties.getApiUrl(), INCIDENTS);
URI uri = Optional.ofNullable(restOperations.postForLocation(query, incident)).orElseThrow(() -> new MachinaRuntimeException(errorMessage + " - URI returned NULL"));
String sysId = getSysID(uri.getPath());
return getIncidentByIDConvertToIssue(sysId).orElseThrow(() -> new MachinaRuntimeException(errorMessage + " - could not convert to issue"));
} catch (HttpClientErrorException e) {
log.error("Error occurred while creating ServiceNow Issue");
log.error(ExceptionUtils.getStackTrace(e));
throw new MachinaRuntimeException();
}
}
use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class GitHubIssueTracker method createIssue.
@Override
public Issue createIssue(ScanResults.XIssue resultIssue, ScanRequest request) {
log.debug("Executing createIssue GitHub API call");
String apiUrl = scmConfigOverrider.determineConfigApiUrl(properties, request).concat("/").concat(request.getNamespace().concat("/").concat(request.getRepoName())).concat("/issues");
ResponseEntity<com.checkmarx.flow.dto.github.Issue> response;
try {
HttpEntity<String> httpEntity = new HttpEntity<>(getJSONCreateIssue(resultIssue, request).toString(), gitHubService.createAuthHeaders(request));
response = restTemplate.exchange(apiUrl, HttpMethod.POST, httpEntity, com.checkmarx.flow.dto.github.Issue.class);
} catch (HttpClientErrorException e) {
log.error("Error occurred while creating GitHub Issue", e);
if (e.getStatusCode().equals(HttpStatus.GONE)) {
log.error("Issues are not enabled for this repository");
}
throw new MachinaRuntimeException(e);
}
return mapToIssue(response.getBody());
}
use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class RallyIssueTracker method updateIssue.
/**
* @param issue
* @param resultIssue
* @param request
* @return
* @throws MachinaException
*/
@Override
public Issue updateIssue(Issue issue, ScanResults.XIssue resultIssue, ScanRequest request) throws MachinaException {
log.info("Executing updateIssue Rally API call");
String json = getJSONCreateIssue(resultIssue, request);
HttpEntity httpEntity = new HttpEntity<>(json, createAuthHeaders());
ResponseEntity<com.checkmarx.flow.dto.rally.Issue> response;
try {
restTemplate.exchange(issue.getUrl(), HttpMethod.POST, httpEntity, com.checkmarx.flow.dto.rally.Issue.class);
this.addComment(issue.getUrl(), "Issue still exists. ");
} catch (HttpClientErrorException e) {
log.error("Error updating issue. This is likely due to the fact that another user has closed this issue. Adding comment");
if (e.getStatusCode().equals(HttpStatus.GONE)) {
throw new MachinaRuntimeException();
}
this.addComment(issue.getUrl(), "This issue still exists. Please add label 'false-positive' to remove from scope of SAST results");
}
return issue;
}
use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class RallyIssueTracker method createIssue.
/**
* Creates new Rally defect.
*
* @param resultIssue
* @param request
* @return
* @throws MachinaException
*/
@Override
public Issue createIssue(ScanResults.XIssue resultIssue, ScanRequest request) throws MachinaException {
log.debug("Executing createIssue Rally API call");
try {
String json = getJSONCreateIssue(resultIssue, request);
HttpEntity httpEntity = new HttpEntity(json, createAuthHeaders());
CreateResultAction cra;
ResponseEntity<CreateResultAction> response;
response = restTemplate.exchange(properties.getApiUrl().concat(CREATE_ISSUE), HttpMethod.POST, httpEntity, CreateResultAction.class);
cra = response.getBody();
Map<String, Object> m = (Map<String, Object>) cra.getAdditionalProperties().get("CreateResult");
m = (Map<String, Object>) m.get("Object");
return mapHashManToIssue(m);
} catch (HttpClientErrorException e) {
log.error("Error occurred while creating Rally Issue");
log.error(ExceptionUtils.getStackTrace(e));
throw new MachinaRuntimeException();
}
}
use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class JiraService method getIssues.
private List<Issue> getIssues(ScanRequest request, String scannerFilter) {
log.info("Executing getIssues API call");
List<Issue> issues = new ArrayList<>();
String jql;
BugTracker bugTracker = request.getBugTracker();
/*Namespace/Repo/Branch provided*/
if (!flowProperties.isTrackApplicationOnly() && !flowProperties.isApplicationRepoOnly() && !ScanUtils.empty(request.getNamespace()) && !ScanUtils.empty(request.getRepoName()) && !ScanUtils.empty(request.getBranch())) {
jql = String.format("project = %s and issueType = \"%s\" and (\"%s\" = \"%s\" and \"%s\" = \"%s:%s\" and \"%s\" = \"%s:%s\" and \"%s\" = \"%s:%s\")", bugTracker.getProjectKey(), bugTracker.getIssueType(), jiraProperties.getLabelTracker(), request.getProduct().getProduct(), jiraProperties.getLabelTracker(), jiraProperties.getOwnerLabelPrefix(), request.getNamespace(), jiraProperties.getLabelTracker(), jiraProperties.getRepoLabelPrefix(), request.getRepoName(), jiraProperties.getLabelTracker(), jiraProperties.getBranchLabelPrefix(), request.getBranch());
} else /*Only application and repo provided */
if (!ScanUtils.empty(request.getApplication()) && !ScanUtils.empty(request.getRepoName())) {
jql = String.format("project = %s and issueType = \"%s\" and (\"%s\" = \"%s\" and \"%s\" = \"%s:%s\" and \"%s\" = \"%s:%s\")", bugTracker.getProjectKey(), bugTracker.getIssueType(), jiraProperties.getLabelTracker(), request.getProduct().getProduct(), jiraProperties.getLabelTracker(), jiraProperties.getAppLabelPrefix(), request.getApplication(), jiraProperties.getLabelTracker(), jiraProperties.getRepoLabelPrefix(), request.getRepoName());
} else /*Only application provided*/
if (!ScanUtils.empty(request.getApplication())) {
jql = String.format("project = %s and issueType = \"%s\" and (\"%s\" = \"%s\" and \"%s\" = \"%s:%s\")", bugTracker.getProjectKey(), bugTracker.getIssueType(), jiraProperties.getLabelTracker(), request.getProduct().getProduct(), jiraProperties.getLabelTracker(), jiraProperties.getAppLabelPrefix(), request.getApplication());
} else {
log.error("Namespace/Repo/Branch or App must be provided in order to properly track ");
throw new MachinaRuntimeException();
}
if (!StringUtils.isEmpty(scannerFilter)) {
jql = jql.concat(String.format(" and \"%s\" in (%s)", jiraProperties.getLabelTracker(), scannerFilter));
}
log.debug("jql query: {}", jql);
HashSet<String> fields = new HashSet<>();
Collections.addAll(fields, "key", "project", "issuetype", "summary", LABEL_FIELD_TYPE, "created", "updated", "status");
SearchResult searchResults;
int totalResultsCount = MAX_RESULTS_ALLOWED;
SearchRestClient searchClient = this.client.getSearchClient();
// Retrieve JQL results through pagination (jira.max-jql-results per page -> default 50), don't allow less than 10.
int maxJqlResultsPerPage = Integer.max(10, jiraProperties.getMaxJqlResults());
for (int startAt = 0; startAt < totalResultsCount; startAt += maxJqlResultsPerPage) {
searchResults = searchClient.searchJql(jql, maxJqlResultsPerPage, startAt, fields).claim();
searchResults.getIssues().forEach(issues::add);
totalResultsCount = Integer.min(searchResults.getTotal(), MAX_RESULTS_ALLOWED);
}
return issues;
}
Aggregations