@@ -40,13 +40,22 @@ def pre_process_rules(**kwargs) -> None:
4040 validated_params = pull_validated_params (kwargs , "validate_params_rules_export" )
4141 scan_report_id = validated_params ["scan_report_id" ]
4242 file_type = validated_params ["file_type" ]
43+
44+ # Map file types to temp table suffixes
45+ if file_type in ["application/json_v1" , "application/json_v2" ]:
46+ temp_table_suffix = "json"
47+ elif file_type == "csv" :
48+ temp_table_suffix = "csv"
49+ else :
50+ temp_table_suffix = file_type
51+
4352 try :
4453 # Create or update the temp table with the processed rules data
4554 pg_hook .run (
4655 create_update_temp_rules_table_query
4756 % {
4857 "scan_report_id" : scan_report_id ,
49- "file_type" : file_type ,
58+ "file_type" : temp_table_suffix ,
5059 },
5160 )
5261 except Exception as e :
@@ -70,6 +79,9 @@ def build_and_upload_rules_file(**kwargs) -> None:
7079 user_id = validated_params ["user_id" ]
7180 scan_report_name = validated_params ["scan_report_name" ]
7281 file_type = validated_params ["file_type" ]
82+ json_version = validated_params .get (
83+ "json_version" , "v1"
84+ ) # default to v1 if not specified
7385
7486 try :
7587 # Setup file config. (Credit: @AndyRae)
@@ -79,13 +91,27 @@ def build_and_upload_rules_file(**kwargs) -> None:
7991 "mapping_csv" ,
8092 "csv" ,
8193 ),
94+ "application/json_v1" : FileHandlerConfig (
95+ lambda : build_rules_json (scan_report_name , scan_report_id ),
96+ "mapping_json" ,
97+ "json" ,
98+ ),
99+ "application/json_v2" : FileHandlerConfig (
100+ lambda : build_rules_json_v2 (scan_report_name , scan_report_id ),
101+ "mapping_json_v2" ,
102+ "json" ,
103+ ),
82104 "json" : FileHandlerConfig (
83105 lambda : (
84106 build_rules_json_v2 (scan_report_name , scan_report_id )
85107 if AIRFLOW_VAR_JSON_VERSION == "v2"
86108 else build_rules_json (scan_report_name , scan_report_id )
87109 ),
88- "mapping_json" ,
110+ (
111+ "mapping_json_v2"
112+ if AIRFLOW_VAR_JSON_VERSION == "v2"
113+ else "mapping_json"
114+ ),
89115 "json" ,
90116 ),
91117 }
@@ -97,7 +123,11 @@ def build_and_upload_rules_file(**kwargs) -> None:
97123 file_extension = config .file_extension
98124
99125 # build file name
100- filename = f"Rules - { scan_report_name } - { scan_report_id } - { datetime .now ()} .{ file_extension } "
126+ if file_type in ["application/json_v1" , "application/json_v2" ]:
127+ version = "V1" if file_type == "application/json_v1" else "V2"
128+ filename = f"Rules - { scan_report_name } - { scan_report_id } - { version } - { datetime .now ()} .{ file_extension } "
129+ else :
130+ filename = f"Rules - { scan_report_name } - { scan_report_id } - { datetime .now ()} .{ file_extension } "
101131
102132 # Upload to blob storage
103133 upload_blob_to_storage (
@@ -146,7 +176,11 @@ def build_and_upload_rules_file(**kwargs) -> None:
146176 "DROP TABLE IF EXISTS temp_rules_export_%(scan_report_id)s_%(file_type)s"
147177 % {
148178 "scan_report_id" : scan_report_id ,
149- "file_type" : file_type ,
179+ "file_type" : (
180+ "json"
181+ if file_type in ["application/json_v1" , "application/json_v2" ]
182+ else file_type
183+ ),
150184 }
151185 )
152186 except Exception as e :
@@ -159,7 +193,7 @@ def build_and_upload_rules_file(**kwargs) -> None:
159193 )
160194 raise e
161195 except Exception as e :
162- logging .error (f"Error creating file entry : { str (e )} " )
196+ logging .error (f"Error building and uploading rules file : { str (e )} " )
163197 update_job_status (
164198 scan_report = scan_report_id ,
165199 stage = JobStageType .DOWNLOAD_RULES ,
0 commit comments