Skip to content
Snippets Groups Projects
Commit bc3d9d58 authored by Alexander Kaschta's avatar Alexander Kaschta :owl:
Browse files

ADD: BCD request submission checks

parent aeb6bf91
No related branches found
No related tags found
No related merge requests found
Pipeline #415543 passed
......@@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends, HTTPException
from starlette import status
from api import get_conn
from model.bcd_request import BCDRequestModel, BCDProtectionRequirements, BCDSystemType
from model.bcd_request import BCDRequestModel, BCDProtectionRequirements, BCDSystemType, IPAddressVersion
from model.wapi.cntl import APIToken, Mgr
from util.auth import check_auth
......@@ -67,4 +67,104 @@ def validate_bcd_request(bcd_request: BCDRequestModel) -> bool:
detail='Load balancers are not supported with level two protection requirements.'
)
if len(bcd_request.bcd_name.strip()) == 0:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='BCD cannot be empty.'
)
if (bcd_request.type_of_system != BCDSystemType.SERVER and bcd_request.access_from_internet and
bcd_request.access_from_internet_note is None):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='A detailed description must be provided for access from the internet onto non server networks.'
)
elif (bcd_request.type_of_system != BCDSystemType.SERVER and bcd_request.access_from_internet and
bcd_request.access_from_internet_note is not None and
len(bcd_request.access_from_internet_note.strip()) == 0):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='A detailed description must be provided for access from the internet onto non server networks.'
)
if bcd_request.type_of_subnet == IPAddressVersion.DUAL_STACK and bcd_request.ipv4_subnet_size < 0:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='Invalid subnet size.'
)
elif bcd_request.type_of_subnet == IPAddressVersion.DUAL_STACK and bcd_request.ipv4_subnet_size > 32:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='Invalid subnet size.'
)
elif bcd_request.type_of_subnet == IPAddressVersion.DUAL_STACK and 29 < bcd_request.ipv4_subnet_size <= 32:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='No subnets smaller than /29 can be provided.'
)
elif bcd_request.type_of_subnet == IPAddressVersion.DUAL_STACK and bcd_request.ipv4_subnet_size < 24:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='No subnets larger than /24 can be provided.'
)
elif (bcd_request.type_of_subnet == IPAddressVersion.DUAL_STACK and bcd_request.ipv4_subnet_size == 24 and
bcd_request.ipv4_subnet_size_explanation is None):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='A detailed description of the demand for a /24 subnet must be provided.'
)
elif (bcd_request.type_of_subnet == IPAddressVersion.DUAL_STACK and bcd_request.ipv4_subnet_size == 24 and
bcd_request.ipv4_subnet_size_explanation is not None and
len(bcd_request.ipv4_subnet_size_explanation.strip()) == 0):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='A detailed description of the demand for a /24 subnet must be provided.'
)
if bcd_request.dhcp_pool and not bcd_request.dhcp:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='DHCP must be enabled to support the DHCP pool.'
)
if bcd_request.dhcp and bcd_request.dhcp_pool and bcd_request.dhcp_pool_size < 2:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='DHCP pools smaller than 2 devices are not offered.'
)
elif (bcd_request.dhcp and bcd_request.dhcp_pool and
bcd_request.dhcp_pool_size > 2**(32 - bcd_request.ipv4_subnet_size) - 5):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='This subnet does not support this size of a DHCP pool.'
)
if bcd_request.dhcp and bcd_request.own_dhcp_server:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='The provided DHCP server cannot be used concurrently to your own DHCP server.'
)
if bcd_request.type_of_system == BCDSystemType.VPN_WIFI_ONLY and bcd_request.location_vpn_wifi_to_vlan is False:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='The VPN2vlan/Wifi2vlan client location must be selected for VPN2vlan/Wifi2vlan only system types.'
)
if bcd_request.location_vpn_wifi_to_vlan and bcd_request.vpn2vlan is False and bcd_request.wifi2vlan is False:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='At least VPN2vlan or Wifi2vlan must be enabled for the VPN2vlan/Wifi2vlan client location.'
)
elif bcd_request.wifi2vlan and bcd_request.location_vpn_wifi_to_vlan is False:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='The VPN2vlan/Wifi2vlan client location must be selected for Wifi2vlan.'
)
elif bcd_request.vpn2vlan and bcd_request.location_vpn_wifi_to_vlan is False:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail='The VPN2vlan/Wifi2vlan client location must be selected for VPN2vlan.'
)
return True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment