-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
sarif.clj
38 lines (33 loc) · 1.52 KB
/
sarif.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(ns clj-holmes.logic.sarif
(:require [clj-holmes.config :as config]))
(def ^:private rules
(mapv :definition config/rules))
(def ^:private sarif-boilerplate
{:$schema "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json"
:version "2.1.0"
:runs [{:tool
{:driver {:name "clj-holmes"
:informationUri "https://github.com/mthbernardes/clj-holmes"
:rules rules}}}]})
(defn ^:private result-by-rule [{:keys [id definition findings]} filename]
(mapv (fn [{:keys [row col end-row end-col]}]
{:ruleId id
:message {:text definition}
:locations [{:physicalLocation
{:artifactLocation {:uri (format "file://%s" filename)}
:region {:startLine row
:endLine end-row
:startColumn col
:endColumn end-col}}}]})
findings))
(defn ^:private scan-result->sarif-result [{:keys [rules filename]}]
(reduce (fn [results rule]
(concat results (result-by-rule rule filename)))
[] rules))
(defn scans->sarif [scans]
(let [results (reduce
(fn [results rules]
(concat results (scan-result->sarif-result rules)))
[] scans)]
(when (seq results)
(assoc-in sarif-boilerplate [:runs 0 :results] (vec results)))))