Search in sources :

Example 1 with TrafficLight

use of com.mercedesbenz.sechub.commons.model.TrafficLight in project sechub by mercedes-benz.

the class HTMLScanResultReportModelBuilder method build.

public Map<String, Object> build(ScanSecHubReport report) {
    TrafficLight trafficLight = report.getTrafficLight();
    String styleRed = HIDE_LIGHT;
    String styleYellow = HIDE_LIGHT;
    String styleGreen = HIDE_LIGHT;
    if (trafficLight == null) {
        throw new IllegalStateException("No traffic light defined");
    }
    switch(trafficLight) {
        case RED:
            styleRed = SHOW_LIGHT;
            break;
        case YELLOW:
            styleYellow = SHOW_LIGHT;
            break;
        case GREEN:
            styleGreen = SHOW_LIGHT;
            break;
        default:
    }
    HtmlCodeScanDescriptionSupport codeScanSupport = new HtmlCodeScanDescriptionSupport();
    SecHubResult result = report.getResult();
    Map<Integer, List<HTMLScanResultCodeScanEntry>> codeScanEntries = new HashMap<>();
    for (SecHubFinding finding : result.getFindings()) {
        codeScanEntries.put(finding.getId(), codeScanSupport.buildEntries(finding));
    }
    Map<String, Object> model = new HashMap<>();
    model.put("result", report.getResult());
    model.put("redList", trafficLightCalculator.filterFindingsFor(result, TrafficLight.RED));
    model.put("yellowList", trafficLightCalculator.filterFindingsFor(result, TrafficLight.YELLOW));
    model.put("greenList", trafficLightCalculator.filterFindingsFor(result, TrafficLight.GREEN));
    model.put("trafficlight", trafficLight.name());
    model.put("styleRed", styleRed);
    model.put("styleYellow", styleYellow);
    model.put("styleGreen", styleGreen);
    model.put("isWebDesignMode", webDesignMode);
    model.put("codeScanEntries", codeScanEntries);
    model.put("codeScanSupport", codeScanSupport);
    model.put("reportHelper", HTMLReportHelper.DEFAULT);
    if (webDesignMode) {
        File file;
        try {
            if (cssResource == null) {
                LOG.error("CSS resource not set:{}", cssResource);
            } else {
                file = cssResource.getFile();
                String absolutePathToCSSFile = file.getAbsolutePath();
                LOG.info("Web design mode activate, using not embedded css but ref to:{}", absolutePathToCSSFile);
                model.put("includedCSSRef", absolutePathToCSSFile);
            }
        } catch (Exception e) {
            LOG.error("Was not able get file from resource:{}", cssResource, e);
        }
    }
    UUID jobUUID = report.getJobUUID();
    if (jobUUID != null) {
        model.put("jobuuid", jobUUID.toString());
    } else {
        model.put("jobuuid", "none");
    }
    return model;
}
Also used : HashMap(java.util.HashMap) SecHubFinding(com.mercedesbenz.sechub.commons.model.SecHubFinding) TrafficLight(com.mercedesbenz.sechub.commons.model.TrafficLight) SecHubResult(com.mercedesbenz.sechub.commons.model.SecHubResult) List(java.util.List) UUID(java.util.UUID) File(java.io.File)

Example 2 with TrafficLight

use of com.mercedesbenz.sechub.commons.model.TrafficLight in project sechub by mercedes-benz.

the class CreateScanReportService method createReport.

/**
 * Creates a report based on product results. There is no security check because
 * its only called internally from system.
 *
 * @param context
 * @return report, never <code>null</code>
 * @throws ScanReportException
 */
public ScanReport createReport(SecHubExecutionContext context) throws ScanReportException {
    notNull(context, "Context may not be null!");
    UUID sechubJobUUID = context.getSechubJobUUID();
    if (sechubJobUUID == null) {
        throw new ScanReportException("Cannot create a report for Job UUID:null");
    }
    LOG.info("Creating report for {}, will delete former reports if existing", traceLogID(sechubJobUUID));
    /* we allow only one report for one job */
    scanReportTransactionService.deleteAllReportsForSecHubJobUUIDinOwnTransaction(sechubJobUUID);
    /*
         * create report - project id in configuration was set on job creation time and
         * is always correct/valid and will differ between api parameter and config..!
         */
    ScanReport scanReport = new ScanReport(sechubJobUUID, context.getConfiguration().getProjectId());
    scanReport.setStarted(LocalDateTime.now());
    /* execute report products */
    try {
        reportProductExecutionService.executeProductsAndStoreResults(context);
    } catch (SecHubExecutionException e) {
        throw new ScanReportException("Report product execution failed", e);
    }
    /* transform */
    ReportTransformationResult reportTransformerResult;
    try {
        reportTransformerResult = reportTransformerService.createResult(context);
        scanReport.setResultType(ScanReportResultType.MODEL);
        scanReport.setResult(reportTransformerResult.toJSON());
    } catch (Exception e) {
        throw new ScanReportException("Was not able to build sechub result", e);
    }
    /* create and set the traffic light */
    TrafficLight trafficLight = trafficLightCalculator.calculateTrafficLight(reportTransformerResult);
    scanReport.setTrafficLight(trafficLight);
    /* update time stamp */
    scanReport.setEnded(LocalDateTime.now());
    /* persist */
    return reportRepository.save(scanReport);
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) ReportTransformationResult(com.mercedesbenz.sechub.domain.scan.ReportTransformationResult) TrafficLight(com.mercedesbenz.sechub.commons.model.TrafficLight) UUID(java.util.UUID) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)

Example 3 with TrafficLight

use of com.mercedesbenz.sechub.commons.model.TrafficLight in project sechub by mercedes-benz.

the class AssertReportUnordered method hasTrafficLight.

public AssertReportUnordered hasTrafficLight(TrafficLight trafficLight) {
    JsonNode trafficLightNode = jsonObj.get("trafficLight");
    if (trafficLightNode == null) {
        dump();
        LOG.info("Last ouptput line was:" + lastOutputLIne);
        fail("No trafficlight found inside report!\nPlease look inside log for details");
    }
    String trText = trafficLightNode.asText();
    TrafficLight foundTrafficLight = TrafficLight.fromString(trText);
    if (!trafficLight.equals(foundTrafficLight)) {
        /*
             * in this case we log the complete JSON content - interesting for debugging
             */
        dump();
        LOG.info("Last ouptput line was:" + lastOutputLIne);
    }
    assertEquals("Returned traffic light:" + foundTrafficLight + " is not as expected:" + trafficLight + ". See JSON dump in log file for details.", trafficLight, foundTrafficLight);
    return this;
}
Also used : TrafficLight(com.mercedesbenz.sechub.commons.model.TrafficLight) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 4 with TrafficLight

use of com.mercedesbenz.sechub.commons.model.TrafficLight in project sechub by mercedes-benz.

the class AssertCalculation method isCalculatedTo.

public AssertCalculation isCalculatedTo(TrafficLight light) {
    TrafficLight calcLight = calculator.calculateTrafficLight(currentResult);
    // never null!
    assertNotNull(calcLight);
    assertEquals("calculated light not as expected!", light, calcLight);
    return this;
}
Also used : TrafficLight(com.mercedesbenz.sechub.commons.model.TrafficLight)

Example 5 with TrafficLight

use of com.mercedesbenz.sechub.commons.model.TrafficLight in project sechub by mercedes-benz.

the class AssertSecHubReport method hasTrafficLight.

public AssertSecHubReport hasTrafficLight(TrafficLight trafficLight) {
    JsonNode trafficLightNode = jsonObj.get("trafficLight");
    if (trafficLightNode == null) {
        dump();
        LOG.info("Last ouptput line was:" + lastOutputLIne);
        fail("No trafficlight found inside report!\nPlease look inside log for details");
    }
    String trText = trafficLightNode.asText();
    TrafficLight foundTrafficLight = TrafficLight.fromString(trText);
    if (!trafficLight.equals(foundTrafficLight)) {
        /*
             * in this case we log the complete JSON content - interesting for debugging
             */
        dump();
        LOG.info("Last ouptput line was:" + lastOutputLIne);
    }
    assertEquals("Returned traffic light:" + foundTrafficLight + " is not as expected:" + trafficLight + ". See JSON dump in log file for details.", trafficLight, foundTrafficLight);
    return this;
}
Also used : TrafficLight(com.mercedesbenz.sechub.commons.model.TrafficLight) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

TrafficLight (com.mercedesbenz.sechub.commons.model.TrafficLight)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 UUID (java.util.UUID)2 SecHubFinding (com.mercedesbenz.sechub.commons.model.SecHubFinding)1 SecHubResult (com.mercedesbenz.sechub.commons.model.SecHubResult)1 ReportTransformationResult (com.mercedesbenz.sechub.domain.scan.ReportTransformationResult)1 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)1 File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1