Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
netvs-middleware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scc-net
netvs
netvs-middleware
Commits
bc3d9d58
Commit
bc3d9d58
authored
4 weeks ago
by
Alexander Kaschta
Browse files
Options
Downloads
Patches
Plain Diff
ADD: BCD request submission checks
parent
aeb6bf91
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#415543
passed
4 weeks ago
Stage: lint
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/bcd_request.py
+101
-1
101 additions, 1 deletion
api/bcd_request.py
with
101 additions
and
1 deletion
api/bcd_request.py
+
101
−
1
View file @
bc3d9d58
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment