32
32
error_message_no_remark = "Action is set to remark, you MUST add a remark."
33
33
# Sets a standard error message for ACL rules with an action of remark, but no source/destination is set.
34
34
error_message_action_remark_source_set = "Action is set to remark, Source CANNOT be set."
35
+ error_message_action_remark_destination_set = "Action is set to remark, Destination CANNOT be set."
35
36
# Sets a standard error message for ACL rules with an action not set to remark, but no remark is set.
36
37
error_message_remark_without_action_remark = "CANNOT set remark unless action is set to remark."
37
38
# Sets a standard error message for ACL rules no associated to an ACL of the same type.
38
39
error_message_acl_type = "Provided parent Access List is not of right type."
39
40
# Sets a standard error message for ACL rules when more than one IP/Host sources are set.
40
41
error_message_sources_more_than_one = "Only one IP/Host related Source can be specified."
42
+ # Sets a standard error message for ACL rules when more than one IP/Host destinations are set.
43
+ error_message_destinations_more_than_one = "Only one IP/Host related Destination can be specified."
41
44
42
45
43
46
class AccessListSerializer (NetBoxModelSerializer ):
@@ -392,14 +395,17 @@ def validate(self, data):
392
395
Validate the ACLExtendedRule django model's inputs before allowing it to update the instance:
393
396
- Check if action set to remark, but no remark set.
394
397
- Check if action set to remark, but source set.
398
+ - Check if action set to remark, but destination set.
395
399
- Check if action set to remark, but source_ports set.
396
400
- Check if action set to remark, but destination_ports set.
397
401
- Check if action set to remark, but protocol set.
398
402
- Check not more than one source is set.
403
+ - Check not more than one destination is set.
399
404
"""
400
405
error_message = {}
401
406
402
407
sources = ["source_prefix" , "source_iprange" , "source_ipaddress" , "source_aggregate" , "source_service" ]
408
+ destinations = ["destination_prefix" , "destination_iprange" , "destination_ipaddress" , "destination_aggregate" , "destination_service" ]
403
409
404
410
if data .get ("action" ) == "remark" :
405
411
# Check if action set to remark, but no remark set.
@@ -411,16 +417,15 @@ def validate(self, data):
411
417
if any (data .get (source ) for source in sources ):
412
418
for source in sources :
413
419
error_message [source ] = [error_message_action_remark_source_set ]
420
+ # Check if action set to remark, but destination set.
421
+ if any (data .get (destination ) for destination in destinations ):
422
+ for destination in destinations :
423
+ error_message [destination ] = [error_message_action_remark_destination_set ]
414
424
# Check if action set to remark, but source_ports set.
415
425
if data .get ("source_ports" ):
416
426
error_message ["source_ports" ] = [
417
427
"Action is set to remark, Source Ports CANNOT be set." ,
418
428
]
419
- # Check if action set to remark, but destination_prefix set.
420
- if data .get ("destination_prefix" ):
421
- error_message ["destination_prefix" ] = [
422
- "Action is set to remark, Destination Prefix CANNOT be set." ,
423
- ]
424
429
# Check if action set to remark, but destination_ports set.
425
430
if data .get ("destination_ports" ):
426
431
error_message ["destination_ports" ] = [
@@ -437,6 +442,10 @@ def validate(self, data):
437
442
for source in sources :
438
443
error_message [source ] = [error_message_sources_more_than_one ]
439
444
445
+ # Check not more than one destination is set.
446
+ if sum (bool (data .get (destination )) for destination in destinations ) > 1 :
447
+ for destination in destinations :
448
+ error_message [destination ] = [error_message_destinations_more_than_one ]
440
449
441
450
if error_message :
442
451
raise serializers .ValidationError (error_message )
0 commit comments