33
44import argparse
55import json
6+ import subprocess
67import uuid
78from pathlib import Path
89from urllib .request import urlopen
@@ -72,7 +73,7 @@ def build_cluster(data_by_phase: list[dict]) -> dict:
7273 }
7374
7475
75- def build_galaxy (data_by_phase : list [dict ]) -> dict :
76+ def build_galaxy (data_by_phase : list [dict ], version : int = 1 ) -> dict :
7677 kill_chain = []
7778 for phase_data in data_by_phase :
7879 phase = phase_data ["phase" ]
@@ -85,7 +86,7 @@ def build_galaxy(data_by_phase: list[dict]) -> dict:
8586 "namespace" : "dima" ,
8687 "type" : "dima-techniques" ,
8788 "uuid" : stable_uuid ("galaxy" , "dima-techniques" ),
88- "version" : 1 ,
89+ "version" : version ,
8990 "icon" : "project-diagram" ,
9091 "kill_chain_order" : {"tactics" : kill_chain },
9192 }
@@ -98,12 +99,21 @@ def main() -> None:
9899 args = parser .parse_args ()
99100
100101 data_by_phase = [fetch_phase (phase ) for phase in FILES ]
101- galaxy = build_galaxy (data_by_phase )
102+
103+ current_version = 0
104+ galaxy_output = Path (args .galaxy_output )
105+ if galaxy_output .exists ():
106+ existing_galaxy = json .loads (galaxy_output .read_text (encoding = "utf-8" ))
107+ current_version = int (existing_galaxy .get ("version" , 0 ))
108+
109+ galaxy = build_galaxy (data_by_phase , version = current_version + 1 )
102110 cluster = build_cluster (data_by_phase )
103111
104- Path ( args . galaxy_output ) .write_text (json .dumps (galaxy , indent = 2 , ensure_ascii = False ) + "\n " , encoding = "utf-8" )
112+ galaxy_output .write_text (json .dumps (galaxy , indent = 2 , ensure_ascii = False ) + "\n " , encoding = "utf-8" )
105113 Path (args .cluster_output ).write_text (json .dumps (cluster , indent = 2 , ensure_ascii = False ) + "\n " , encoding = "utf-8" )
106114
115+ subprocess .run (["./jq_all_the_things.sh" ], check = True )
116+
107117
108118if __name__ == "__main__" :
109119 main ()
0 commit comments