Skip to content
Snippets Groups Projects
Commit e67744b3 authored by Hakan Calim's avatar Hakan Calim
Browse files

NAT-328: updated site name validation by a utils helper func

parent 7cd6e1e0
No related branches found
No related tags found
No related merge requests found
Pipeline #84384 failed
This commit is part of merge request !97. Comments created here will be created in the context of that merge request.
import ipaddress import ipaddress
import re
from typing import Any from typing import Any
from uuid import UUID from uuid import UUID
...@@ -16,7 +15,7 @@ from gso.products.product_blocks.router import RouterRole, RouterVendor ...@@ -16,7 +15,7 @@ from gso.products.product_blocks.router import RouterRole, RouterVendor
from gso.products.product_blocks.site import SiteTier from gso.products.product_blocks.site import SiteTier
from gso.services import subscriptions from gso.services import subscriptions
from gso.services.crm import CustomerNotFoundError, get_customer_by_name from gso.services.crm import CustomerNotFoundError, get_customer_by_name
from gso.utils.helpers import LAGMember from gso.utils.helpers import LAGMember, validate_site_name
router = APIRouter(prefix="/imports", tags=["Imports"], dependencies=[Depends(opa_security_default)]) router = APIRouter(prefix="/imports", tags=["Imports"], dependencies=[Depends(opa_security_default)])
...@@ -41,12 +40,7 @@ class SiteImportModel(BaseModel): ...@@ -41,12 +40,7 @@ class SiteImportModel(BaseModel):
@validator("site_name", allow_reuse=True) @validator("site_name", allow_reuse=True)
def site_name_must_be_valid(cls, site_name: str) -> str: def site_name_must_be_valid(cls, site_name: str) -> str:
# Accept 3 chapital letters and only one ditigt after capital letters. return validate_site_name(site_name)
pattern = re.compile(r"^[A-Z]{3}[0-9]?$")
if not bool(pattern.match(site_name)):
raise ValueError(f"Enter a valid site name similar looks like AMS, AMS1or LON9. Get: {site_name}")
return site_name
class RouterImportModel(BaseModel): class RouterImportModel(BaseModel):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment