Search in sources :

Example 1 with ReportingConfiguration

use of com.contrastsecurity.sarif.ReportingConfiguration 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 ReportingConfiguration

use of com.contrastsecurity.sarif.ReportingConfiguration 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)

Example 3 with ReportingConfiguration

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

the class SarifReporter method createInvocation.

private Invocation createInvocation() {
    Set<ConfigurationOverride> ruleConfigurationOverrides = new HashSet<>();
    var diagnosticsOptions = configuration.getDiagnosticsOptions();
    diagnosticsOptions.getParameters().forEach((String key, Either<Boolean, Map<String, Object>> option) -> {
        var descriptor = new ReportingDescriptorReference().withId(key);
        var configurationOverride = new ConfigurationOverride().withDescriptor(descriptor);
        var reportingConfiguration = new ReportingConfiguration();
        if (option.isLeft()) {
            reportingConfiguration.setEnabled(option.getLeft());
        } else {
            var parameters = new PropertyBag();
            var diagnosticParameters = option.getRight();
            diagnosticParameters.forEach(parameters::setAdditionalProperty);
            reportingConfiguration.setParameters(parameters);
        }
        configurationOverride.withConfiguration(reportingConfiguration);
        ruleConfigurationOverrides.add(configurationOverride);
    });
    ArtifactLocation workingDirectory = new ArtifactLocation().withUri(Absolute.uri(new File(".").toURI()).toString());
    return new Invocation().withExecutionSuccessful(true).withRuleConfigurationOverrides(ruleConfigurationOverrides).withWorkingDirectory(workingDirectory).withProcessId((int) ProcessHandle.current().pid());
}
Also used : Invocation(com.contrastsecurity.sarif.Invocation) PropertyBag(com.contrastsecurity.sarif.PropertyBag) MultiformatMessageString(com.contrastsecurity.sarif.MultiformatMessageString) ReportingDescriptorReference(com.contrastsecurity.sarif.ReportingDescriptorReference) ConfigurationOverride(com.contrastsecurity.sarif.ConfigurationOverride) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) ArtifactLocation(com.contrastsecurity.sarif.ArtifactLocation) File(java.io.File) ReportingConfiguration(com.contrastsecurity.sarif.ReportingConfiguration) HashSet(java.util.HashSet)

Aggregations

MultiformatMessageString (com.contrastsecurity.sarif.MultiformatMessageString)3 PropertyBag (com.contrastsecurity.sarif.PropertyBag)3 ReportingConfiguration (com.contrastsecurity.sarif.ReportingConfiguration)3 ReportingDescriptor (com.contrastsecurity.sarif.ReportingDescriptor)2 ArtifactLocation (com.contrastsecurity.sarif.ArtifactLocation)1 ConfigurationOverride (com.contrastsecurity.sarif.ConfigurationOverride)1 Invocation (com.contrastsecurity.sarif.Invocation)1 ReportingDescriptorReference (com.contrastsecurity.sarif.ReportingDescriptorReference)1 File (java.io.File)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 lombok.val (lombok.val)1 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)1