Search in sources :

Example 1 with MultiformatMessageString

use of com.contrastsecurity.sarif.MultiformatMessageString in project bsl-language-server by 1c-syntax.

the class SarifReporter method createReportingDescriptor.

private static ReportingDescriptor createReportingDescriptor(DiagnosticInfo diagnosticInfo) {
    var id = diagnosticInfo.getCode().getStringValue();
    var name = diagnosticInfo.getName();
    var fullDescription = new MultiformatMessageString().withText(diagnosticInfo.getDescription()).withMarkdown(diagnosticInfo.getDescription());
    var helpUri = URI.create(diagnosticInfo.getDiagnosticCodeDescriptionHref());
    var parameters = new PropertyBag();
    diagnosticInfo.getParameters().forEach(parameterInfo -> parameters.withAdditionalProperty(parameterInfo.getName(), parameterInfo.getDefaultValue()));
    var defaultConfiguration = new ReportingConfiguration().withEnabled(diagnosticInfo.isActivatedByDefault()).withLevel(severityToReportLevel.get(diagnosticInfo.getLSPSeverity())).withParameters(parameters);
    var tags = diagnosticInfo.getTags().stream().map(Enum::name).collect(Collectors.toSet());
    var properties = new PropertyBag().withTags(tags);
    return new ReportingDescriptor().withId(id).withName(name).withFullDescription(fullDescription).withHelpUri(helpUri).withDefaultConfiguration(defaultConfiguration).withProperties(properties);
}
Also used : PropertyBag(com.contrastsecurity.sarif.PropertyBag) MultiformatMessageString(com.contrastsecurity.sarif.MultiformatMessageString) ReportingConfiguration(com.contrastsecurity.sarif.ReportingConfiguration) ReportingDescriptor(com.contrastsecurity.sarif.ReportingDescriptor)

Example 2 with MultiformatMessageString

use of com.contrastsecurity.sarif.MultiformatMessageString in project aws-codeguru-cli by aws.

the class ResultsAdapter method createSarifRuleDescriptions.

private static Map<String, ReportingDescriptor> createSarifRuleDescriptions(final List<RecommendationSummary> recommendations) {
    val rulesMap = new HashMap<String, ReportingDescriptor>();
    for (val recommendation : recommendations) {
        val metaData = recommendation.ruleMetadata();
        if (metaData != null && !rulesMap.containsKey(metaData.ruleId())) {
            val properties = new PropertyBag().withTags(new HashSet<>(metaData.ruleTags()));
            MultiformatMessageString foo;
            val descriptor = new ReportingDescriptor().withName(metaData.ruleName()).withId(metaData.ruleId()).withShortDescription(new MultiformatMessageString().withText(metaData.ruleName())).withFullDescription(new MultiformatMessageString().withText(metaData.shortDescription())).withHelp(new MultiformatMessageString().withText(metaData.longDescription())).withProperties(properties);
            if (recommendation.severityAsString() != null) {
                val level = ReportingConfiguration.Level.fromValue(getSarifSeverity(recommendation));
                descriptor.setDefaultConfiguration(new ReportingConfiguration().withLevel(level));
            }
            rulesMap.put(metaData.ruleId(), descriptor);
        }
    }
    return rulesMap;
}
Also used : lombok.val(lombok.val) HashMap(java.util.HashMap) PropertyBag(com.contrastsecurity.sarif.PropertyBag) MultiformatMessageString(com.contrastsecurity.sarif.MultiformatMessageString) ReportingDescriptor(com.contrastsecurity.sarif.ReportingDescriptor) ReportingConfiguration(com.contrastsecurity.sarif.ReportingConfiguration)

Aggregations

MultiformatMessageString (com.contrastsecurity.sarif.MultiformatMessageString)2 PropertyBag (com.contrastsecurity.sarif.PropertyBag)2 ReportingConfiguration (com.contrastsecurity.sarif.ReportingConfiguration)2 ReportingDescriptor (com.contrastsecurity.sarif.ReportingDescriptor)2 HashMap (java.util.HashMap)1 lombok.val (lombok.val)1