MCPcopy Index your code
hub / github.com/SourceCode-AI/aura / add_detection

Function add_detection

files/dataset_scripts/convert2sqlite.py:104–128  ·  view source on GitHub ↗
(scan_id, detection, package, cursor)

Source from the content-addressed store, hash-verified

102
103
104def add_detection(scan_id, detection, package, cursor):
105 # TODO: add severity to table cols
106 type_id = get_detection_type_id(detection["type"], cursor)
107 signature = xxhash.xxh64(f"{package}#{detection['signature']}").hexdigest()
108
109 extra = zlib.compress(rapidjson.dumps(detection.get("extra", {})).encode())
110
111 try:
112 cursor.execute("""
113 INSERT INTO detections (scan, type, signature, message, score, extra) VALUES (?, ?, ?, ?, ?, ?)
114 """, (scan_id, type_id, signature, detection["message"], detection.get("score", 0), extra))
115 except sqlite3.IntegrityError:
116 print(f"Warning detection already exists: {detection}")
117 return
118
119 detection_id = cursor.lastrowid
120
121 for tag in detection.get("tags", []):
122 tag_id = get_tag_id(tag, cursor)
123 try:
124 cursor.execute("""
125 INSERT INTO tags (detection, tag) VALUES (?, ?)
126 """, (detection_id, tag_id))
127 except sqlite3.IntegrityError:
128 pass
129
130
131def add_scan(scan: dict, cursor):

Callers 1

add_scanFunction · 0.85

Calls 3

get_detection_type_idFunction · 0.85
get_tag_idFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected