Snapshot: full project state
This commit is contained in:
24
manifest_patch.py
Normal file
24
manifest_patch.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import json, hashlib, os
|
||||
|
||||
MAN = "/opt/threatmarket/archive/manifest.json"
|
||||
|
||||
|
||||
def update_manifest(zip_path, domain, date, categories, finding_count):
|
||||
"""Register a finished pack in the archive manifest so the web app lists it."""
|
||||
h = hashlib.sha256(open(zip_path, "rb").read()).hexdigest()
|
||||
man = json.load(open(MAN)) if os.path.exists(MAN) else []
|
||||
pid = domain + "-" + date.replace("-", "")
|
||||
if not any(m.get("pack_id") == pid for m in man):
|
||||
man.append({
|
||||
"pack_id": pid,
|
||||
"domain": domain,
|
||||
"date": date,
|
||||
"categories": categories,
|
||||
"finding_counts": {"total_findings": finding_count},
|
||||
"size_bytes": os.path.getsize(zip_path),
|
||||
"sha256": h,
|
||||
"file": os.path.basename(zip_path),
|
||||
})
|
||||
tmp = MAN + ".tmp"
|
||||
json.dump(man, open(tmp, "w"), indent=1)
|
||||
os.replace(tmp, MAN)
|
||||
Reference in New Issue
Block a user