mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 01:13:03 +01:00
55 lines
1.3 KiB
Python
Executable File
55 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Create SQLite schema for SARIF importer."""
|
|
import sqlite3, sys
|
|
|
|
schemas = {
|
|
"runs": """CREATE TABLE IF NOT EXISTS runs(
|
|
run_id TEXT PRIMARY KEY,
|
|
timestamp TIMESTAMP,
|
|
tool TEXT,
|
|
version TEXT,
|
|
exit_code INTEGER);""",
|
|
"results": """CREATE TABLE IF NOT EXISTS results(
|
|
run_id TEXT,
|
|
rule_id TEXT,
|
|
severity TEXT,
|
|
message TEXT,
|
|
file_path TEXT,
|
|
line_start INTEGER,
|
|
line_end INTEGER,
|
|
column_start INTEGER,
|
|
column_end INTEGER,
|
|
PRIMARY KEY(run_id,rule_id,file_path,line_start));""",
|
|
"alerts": """CREATE TABLE IF NOT EXISTS alerts(
|
|
alert_id TEXT PRIMARY KEY,
|
|
run_id TEXT,
|
|
rule_id TEXT,
|
|
kind TEXT,
|
|
file_path TEXT,
|
|
message TEXT,
|
|
severity TEXT);""",
|
|
"referenced_source_regions": """CREATE TABLE IF NOT EXISTS referenced_source_regions(
|
|
region_id TEXT PRIMARY KEY,
|
|
result_id TEXT,
|
|
file_path TEXT,
|
|
start_line INTEGER,
|
|
end_line INTEGER,
|
|
start_column INTEGER,
|
|
end_column INTEGER,
|
|
snippet TEXT,
|
|
source_hash TEXT);"""
|
|
}
|
|
|
|
def main():
|
|
if len(sys.argv)<2:
|
|
print("Usage: sarif-make-schema dbfile")
|
|
sys.exit(1)
|
|
db=sys.argv[1]
|
|
con=sqlite3.connect(db)
|
|
cur=con.cursor()
|
|
for sql in schemas.values(): cur.executescript(sql)
|
|
con.commit(); con.close()
|
|
print(f"Schema ready in {db}")
|
|
|
|
if __name__=="__main__": main()
|