Search in sources :

Example 16 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class RallyIssueTracker method mapHashManToIssue.

/**
 * Converts a Rally defect represented as a HashMap to a CxFlow issue.
 *
 * @param rallyDefect contains the Rally defect object
 * @return CxFlow issue with rally defect data encoded into it
 */
private Issue mapHashManToIssue(Map<String, Object> rallyDefect) {
    if (rallyDefect == null) {
        return null;
    }
    Issue i = new Issue();
    i.setBody((String) rallyDefect.get("Description"));
    i.setTitle((String) rallyDefect.get("_refObjectName"));
    i.setId((String) rallyDefect.get("_refObjectUUID"));
    i.setUrl((String) rallyDefect.get("_ref"));
    i.setState((String) rallyDefect.get(RALLY_DEFECT_STATE_FIELD));
    List<String> labels = new ArrayList<>();
    i.setLabels(labels);
    return i;
}
Also used : Issue(com.checkmarx.flow.dto.Issue) ArrayList(java.util.ArrayList)

Example 17 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class RallyIssueTracker method mapToIssue.

/**
 * Converts a Rally defect result to a CxFlow issue.
 *
 * @param rallyDefect contains the Rally defect object
 * @return CxFlow issue with rally defect data encoded into it
 */
private Issue mapToIssue(Result rallyDefect) {
    if (rallyDefect == null) {
        return null;
    }
    Issue i = new Issue();
    i.setBody(rallyDefect.getDescription());
    i.setTitle(rallyDefect.getRefObjectName());
    i.setId(String.valueOf(rallyDefect.getRefObjectUUID()));
    i.setUrl(rallyDefect.getRef());
    i.setState(rallyDefect.getState());
    List<String> labels = new ArrayList<>();
    i.setLabels(labels);
    return i;
}
Also used : Issue(com.checkmarx.flow.dto.Issue) ArrayList(java.util.ArrayList)

Example 18 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class IssueService method getIssueMap.

/**
 * Create a map of custom issues
 */
private Map<String, Issue> getIssueMap(IssueTracker tracker, List<Issue> issues, ScanRequest request) {
    Map<String, Issue> issueMap = new HashMap<>();
    for (Issue issue : issues) {
        String key = tracker.getIssueKey(issue, request);
        issueMap.put(key, issue);
    }
    return issueMap;
}
Also used : Issue(com.checkmarx.flow.dto.Issue)

Example 19 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class IastService method createIssue.

private void createIssue(ScanVulnerabilities scanVulnerabilities, ScanRequest request, ResultInfo scansResultQuery, VulnerabilityInfo vulnerability, Scan scan) {
    try {
        Issue issue;
        IssueTracker issueTracker;
        boolean htmlDescription = false;
        switch(request.getBugTracker().getType()) {
            case JIRA:
                String jiraIssue = postIssueToJira(scanVulnerabilities, request, scansResultQuery, vulnerability, scan);
                if (jiraService.getJiraProperties() != null) {
                    log.info("Create jira issue: " + jiraService.getJiraProperties().getUrl() + "/browse/" + jiraIssue);
                }
                // jiraService is not an instance of IssueTracker, because of that the "return" here is a shortcut to stop the execution
                return;
            case GITHUBCOMMIT:
                issueTracker = gitHubIssueTracker;
                break;
            case GITLABCOMMIT:
                issueTracker = gitLabIssueTracker;
                break;
            case adopull:
            case ADOPULL:
                issueTracker = azureIssueTracker;
                htmlDescription = true;
                request.putAdditionalMetadata(Constants.ADO_ISSUE_BODY_KEY, "Description");
                request.putAdditionalMetadata(Constants.ADO_ISSUE_KEY, adoProperties.getIssueType());
                break;
            default:
                throw new NotImplementedException(request.getBugTracker().getType().getType() + ". That bug tracker not implemented.");
        }
        issue = postIssueToTracker(scanVulnerabilities, request, scansResultQuery, vulnerability, scan, issueTracker, htmlDescription);
        log.info("Create {} issue: {}", request.getBugTracker().getType().getType(), issue.getUrl());
    } catch (MachinaException e) {
        log.error("Problem with creating issue.", e);
    } catch (RuntimeException e) {
        throw new IastBugTrackerClientException("Can't create issue", e);
    }
}
Also used : Issue(com.checkmarx.flow.dto.Issue) IssueTracker(com.checkmarx.flow.custom.IssueTracker) GitHubIssueTracker(com.checkmarx.flow.custom.GitHubIssueTracker) GitLabIssueTracker(com.checkmarx.flow.custom.GitLabIssueTracker) ADOIssueTracker(com.checkmarx.flow.custom.ADOIssueTracker) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 20 with Issue

use of com.checkmarx.flow.dto.Issue in project cx-flow by checkmarx-ltd.

the class AzureDevopsClient method getProjectIssueIds.

private List<String> getProjectIssueIds() throws IOException {
    log.info("Getting project issue IDs.");
    ObjectNode requestBody = objectMapper.createObjectNode();
    // WIQL language is read-only, so potential parameter injection shouldn't do any harm.
    String wiqlQuery = String.format("Select System.Id From WorkItems Where System.TeamProject = '%s'", projectName);
    requestBody.put("query", wiqlQuery);
    HttpEntity<ObjectNode> request = getRequestEntity(requestBody);
    String url = getResourceUrl("wit/wiql", null);
    ResponseEntity<ObjectNode> response = restClient.exchange(url, HttpMethod.POST, request, ObjectNode.class);
    ObjectNode responseBody = extractBody(response);
    List<String> result = StreamSupport.stream(responseBody.get("workItems").spliterator(), false).map(issue -> issue.get(ID_KEY).asText()).collect(Collectors.toList());
    log.info("Issues found: {}", result.size());
    return result;
}
Also used : ADOProperties(com.checkmarx.flow.config.ADOProperties) Issue(com.checkmarx.flow.dto.Issue) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) org.springframework.http(org.springframework.http) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Duration(java.time.Duration) JsonNode(com.fasterxml.jackson.databind.JsonNode) StreamSupport(java.util.stream.StreamSupport) RestTemplate(org.springframework.web.client.RestTemplate) Nullable(javax.annotation.Nullable) Predicate(java.util.function.Predicate) TestComponent(org.springframework.boot.test.context.TestComponent) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) CreateWorkItemAttr(com.checkmarx.flow.dto.azure.CreateWorkItemAttr) Awaitility(org.awaitility.Awaitility) Spliterator(java.util.Spliterator) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Aggregations

Issue (com.checkmarx.flow.dto.Issue)27 MachinaException (com.checkmarx.flow.exception.MachinaException)8 ArrayList (java.util.ArrayList)8 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)6 ScanRequest (com.checkmarx.flow.dto.ScanRequest)5 MachinaRuntimeException (com.checkmarx.flow.exception.MachinaRuntimeException)5 ScanResults (com.checkmarx.sdk.dto.ScanResults)5 URI (java.net.URI)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 FlowProperties (com.checkmarx.flow.config.FlowProperties)2 ServiceNowProperties (com.checkmarx.flow.config.ServiceNowProperties)2 IssueTracker (com.checkmarx.flow.custom.IssueTracker)2 Incident (com.checkmarx.flow.dto.servicenow.Incident)2 Result (com.checkmarx.flow.dto.servicenow.Result)2 HTMLHelper (com.checkmarx.flow.utils.HTMLHelper)2 ScanUtils (com.checkmarx.flow.utils.ScanUtils)2 Lists (com.google.common.collect.Lists)2