1212 get_current_severity ,
1313 get_current_status ,
1414 get_current_vex_justification ,
15- get_current_vex_remediations ,
1615)
1716from application .core .services .observation_log import create_observation_log
1817from application .core .services .risk_acceptance_expiry import (
@@ -121,7 +120,11 @@ def apply_all_rules_for_product(self) -> None:
121120 observations = Observation .objects .filter (product = self .product )
122121
123122 observations = (
124- observations .select_related ("parser" ).select_related ("general_rule" ).select_related ("product_rule" )
123+ observations .select_related ("parser" )
124+ .select_related ("general_rule" )
125+ .select_related ("product_rule" )
126+ .select_related ("branch" )
127+ .select_related ("origin_service" )
125128 )
126129
127130 for observation in observations :
@@ -250,7 +253,7 @@ def _check_rule_fields(
250253
251254 return False
252255
253- def _check_rule_rego (
256+ def _check_rule_rego ( # pylint: disable=too-many-branches
254257 self , rule : Rule , observation : Observation , observation_before : Observation , simulation : Optional [bool ] = False
255258 ) -> bool :
256259 jsonpickle .set_encoder_options ("simplejson" , use_decimal = True , sort_keys = True )
@@ -259,6 +262,12 @@ def _check_rule_rego(
259262 observation_dict = json .loads (jsonpickle .dumps (observation , unpicklable = False , use_decimal = True ))
260263 observation_dict = {k : v for k , v in observation_dict .items () if v is not None and v != "" }
261264
265+ observation_dict ["product_name" ] = observation .product .name
266+ if observation .branch :
267+ observation_dict ["branch_name" ] = observation .branch .name
268+ if observation .origin_service :
269+ observation_dict ["origin_service_name" ] = observation .origin_service .name
270+
262271 rego_interpreter = self .rego_interpreters [rule .pk ]
263272 result = rego_interpreter .query (observation_dict )
264273
@@ -332,11 +341,6 @@ def _write_observation_log(
332341 if observation_before .current_vex_justification != observation .current_vex_justification
333342 else ""
334343 )
335- vex_remediations = (
336- observation .current_vex_remediations or ""
337- if observation_before .current_vex_remediations != observation .current_vex_remediations
338- else ""
339- )
340344 risk_acceptance_expiry_date = (
341345 observation .risk_acceptance_expiry_date
342346 if observation_before .risk_acceptance_expiry_date != observation .risk_acceptance_expiry_date
@@ -358,7 +362,6 @@ def _write_observation_log(
358362 priority = priority ,
359363 comment = comment ,
360364 vex_justification = vex_justification ,
361- vex_remediations = vex_remediations ,
362365 assessment_status = Assessment_Status .ASSESSMENT_STATUS_AUTO_APPROVED ,
363366 risk_acceptance_expiry_date = risk_acceptance_expiry_date ,
364367 )
@@ -406,16 +409,6 @@ def _write_observation_log_no_rule(
406409 else None
407410 )
408411
409- observation .rule_vex_remediations = ""
410- previous_vex_remediations = observation .current_vex_remediations
411- observation .current_vex_remediations = get_current_vex_remediations (observation )
412-
413- log_vex_remediations = (
414- observation .current_vex_remediations
415- if previous_vex_remediations != observation .current_vex_remediations
416- else ""
417- )
418-
419412 if previous_product_rule :
420413 comment = f"Removed product { previous_product_rule .type .lower ()} rule { previous_product_rule .name } "
421414 elif previous_general_rule :
@@ -430,7 +423,6 @@ def _write_observation_log_no_rule(
430423 priority = log_priority ,
431424 comment = comment ,
432425 vex_justification = log_vex_justification ,
433- vex_remediations = log_vex_remediations ,
434426 assessment_status = Assessment_Status .ASSESSMENT_STATUS_AUTO_APPROVED ,
435427 risk_acceptance_expiry_date = log_risk_acceptance_expiry_date ,
436428 )
0 commit comments