Search in sources :

Example 16 with MachinaRuntimeException

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();
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) Incident(com.checkmarx.flow.dto.servicenow.Incident) URI(java.net.URI)

Example 17 with 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());
}
Also used : Issue(com.checkmarx.flow.dto.Issue) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException)

Example 18 with MachinaRuntimeException

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;
}
Also used : Issue(com.checkmarx.flow.dto.Issue) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException)

Example 19 with MachinaRuntimeException

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();
    }
}
Also used : CreateResultAction(com.checkmarx.flow.dto.rally.CreateResultAction) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) JSONObject(org.json.JSONObject) Map(java.util.Map)

Example 20 with 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;
}
Also used : MachinaRuntimeException(com.checkmarx.flow.exception.MachinaRuntimeException) BugTracker(com.checkmarx.flow.dto.BugTracker)

Aggregations

MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)23 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 IOException (java.io.IOException)8 Issue (com.checkmarx.flow.dto.Issue)5 ScanRequest (com.checkmarx.flow.dto.ScanRequest)5 Incident (com.checkmarx.flow.dto.servicenow.Incident)5 BitbucketServerEventHandler (com.checkmarx.flow.handlers.bitbucket.server.BitbucketServerEventHandler)5 BugTracker (com.checkmarx.flow.dto.BugTracker)4 MachinaException (com.checkmarx.flow.exception.MachinaException)4 ScanResults (com.checkmarx.sdk.dto.ScanResults)3 CxConfig (com.checkmarx.sdk.dto.sast.CxConfig)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 List (java.util.List)3 FlowProperties (com.checkmarx.flow.config.FlowProperties)2 ServiceNowProperties (com.checkmarx.flow.config.ServiceNowProperties)2 Result (com.checkmarx.flow.dto.servicenow.Result)2 HTMLHelper (com.checkmarx.flow.utils.HTMLHelper)2 ScanUtils (com.checkmarx.flow.utils.ScanUtils)2