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