@@ -386,8 +386,9 @@ def add_object(line, counter, position_decrement_due_to_rule, position_decrement
386
386
payload ["position" ] = "bottom"
387
387
else :
388
388
if "position" in payload :
389
- if "rule" in api_type :
389
+ if "rule" in api_type or api_type == "threat-exception" :
390
390
payload ["position" ] = str (int (payload ["position" ]) - position_decrement_due_to_rule )
391
+ if "rule" in api_type :
391
392
if payload ["action" ] == "Drop" :
392
393
if "action-settings" in payload :
393
394
payload .pop ("action-settings" )
@@ -402,11 +403,7 @@ def add_object(line, counter, position_decrement_due_to_rule, position_decrement
402
403
section_position_decrement = (position_decrements_for_sections [int (payload ["position" ]) - 1 ] if len (
403
404
position_decrements_for_sections ) > 0 else 0 ) + position_decrement_due_to_section
404
405
payload ["position" ] = str (int (payload ["position" ]) - section_position_decrement )
405
- if "exception" in api_type and "rule-number" in payload :
406
- show_rule_rulebase = client .api_call ("show-threat-rule-exception-rulebase" , {"name" : layer , "rule-number" : payload ["rule-number" ]})
407
- if show_rule_rulebase .success and show_rule_rulebase .data and "to" in show_rule_rulebase .data :
408
- payload ["position" ] = str (int (show_rule_rulebase .data ["to" ]) + 1 )
409
-
406
+
410
407
if generic_type :
411
408
payload ["create" ] = generic_type
412
409
if "layer" in api_type :
@@ -430,6 +427,8 @@ def add_object(line, counter, position_decrement_due_to_rule, position_decrement
430
427
payload ["layer" ] = layer
431
428
if args is not None and args .objects_suffix != "" :
432
429
payload ["layer" ] += args .objects_suffix
430
+ if payload ["layer" ] in changed_layer_names :
431
+ payload ["layer" ] = changed_layer_names [payload ["layer" ]]
433
432
if client .api_version != "1" and api_type == "access-rule" and "track-alert" in payload :
434
433
payload ["track" ] = {}
435
434
payload ["track" ]["alert" ] = payload ["track-alert" ]
@@ -578,8 +577,8 @@ def add_object(line, counter, position_decrement_due_to_rule, position_decrement
578
577
position_decrement_due_to_section , fields , api_type , generic_type , layer ,
579
578
layers_to_attach ,
580
579
changed_layer_names , api_call , num_objects , client , args , package )
581
- if "Invalid parameter for [position]" in api_reply .error_message :
582
- if "access-rule" in api_type or "https-rule" in api_type :
580
+ if "Invalid parameter for [position]" in api_reply .error_message and "exception-group" not in api_type :
581
+ if "access-rule" in api_type or "https-rule" or "threat-exception" in api_type :
583
582
position_decrement_due_to_rule += adjust_position_decrement (int (payload ["position" ]),
584
583
api_reply .error_message )
585
584
elif "access-section" in api_type or "https-section" in api_type :
@@ -948,7 +947,9 @@ def add_suffix_to_objects(payload, api_type, objects_suffix):
948
947
return
949
948
950
949
fields_to_change = ["name" , "source" , "destination" , "service" , "members" , "inline-layer" , "networks" , "host" ,
951
- "protected-scope" , "protection-or-site" , "exception-group-name" , "rule-name" ]
950
+ "protected-scope" , "protection-or-site" , "exception-group-name" , "rule-name" , "applied-threat-rules" ]
951
+ if api_type == "threat-exception" and "exception-group-name" in payload and "name" not in payload :
952
+ payload .update ({"name" : "" })
952
953
for field in fields_to_change :
953
954
if field in payload :
954
955
if field == "name" :
@@ -958,7 +959,7 @@ def add_suffix_to_objects(payload, api_type, objects_suffix):
958
959
changed_object_names_map [oldName ] = newName
959
960
elif field in ["source" , "destination" , "service" , "members" , "protected-scope" , "protection-or-site" ]:
960
961
for i in range (len (payload [field ])):
961
- if payload [field ][i ] in changed_object_names_map :
962
+ if payload [field ][i ] in changed_object_names_map and payload [ field ][ i ] != "IPS" :
962
963
payload [field ][i ] = changed_object_names_map [payload [field ][i ]]
963
964
elif field in ["inline-layer" , "host" , "exception-group-name" , "rule-name" ]:
964
965
if payload [field ] in changed_object_names_map :
@@ -967,3 +968,7 @@ def add_suffix_to_objects(payload, api_type, objects_suffix):
967
968
for i in range (len (payload [field ])):
968
969
if payload [field ][i ]["name" ] in changed_object_names_map :
969
970
payload [field ][i ]["name" ] = changed_object_names_map [payload [field ][i ]["name" ]]
971
+ elif field == "applied-threat-rules" :
972
+ for i in range (len (payload [field ])):
973
+ if payload [field ][i ]["layer" ] in changed_object_names_map :
974
+ payload [field ][i ]["layer" ] = changed_object_names_map [payload [field ][i ]["layer" ]]
0 commit comments