Skip to content
Snippets Groups Projects
Commit a45c877f authored by JORGE SASIAIN's avatar JORGE SASIAIN
Browse files

NAT-356: extend BaseSiteModel it in SiteImportModel

parent 1287ea49
No related branches found
No related tags found
1 merge request!112Address SonarQube code smells
Pipeline #84708 failed
......@@ -16,13 +16,9 @@ from gso.products.product_blocks.router import RouterRole, RouterVendor
from gso.products.product_blocks.site import SiteTier
from gso.services import subscriptions
from gso.services.crm import CustomerNotFoundError, get_customer_by_name
from gso.utils.helpers import (
LAGMember,
validate_country_code,
validate_ipv4_or_ipv6,
validate_site_fields_is_unique,
validate_site_name,
)
from gso.workflows.site.base_site_model import BaseSiteModel
from gso.utils.helpers import LAGMember
router = APIRouter(prefix="/imports", tags=["Imports"], dependencies=[Depends(opa_security_default)])
......@@ -34,7 +30,7 @@ class ImportResponseModel(BaseModel):
detail: str
class SiteImportModel(BaseModel):
class SiteImportModel(BaseSiteModel):
"""The required input for importing an existing :class:`gso.products.product_types.site`."""
site_name: str
......@@ -49,34 +45,6 @@ class SiteImportModel(BaseModel):
site_ts_address: str
customer: str
@validator("site_ts_address", allow_reuse=True)
def validate_ts_address(cls, site_ts_address: str) -> str:
"""Validate the terminal server address."""
validate_site_fields_is_unique("site_ts_address", site_ts_address)
validate_ipv4_or_ipv6(site_ts_address)
return site_ts_address
@validator("site_country_code", allow_reuse=True)
def country_code_must_exist(cls, country_code: str) -> str:
"""Validate the country code such that it exists."""
validate_country_code(country_code)
return country_code
@validator("site_internal_id", "site_bgp_community_id", allow_reuse=True)
def validate_unique_fields(cls, value: str, field: ModelField) -> str | int:
"""Validate that the internal side ID and :term:`BGP` community IDs are unique."""
return validate_site_fields_is_unique(field.name, value)
@validator("site_name", allow_reuse=True)
def site_name_must_be_valid(cls, site_name: str) -> str:
"""Validate the site name.
The site name must consist of three uppercase letters, optionally followed by a single digit.
"""
validate_site_fields_is_unique("site_name", site_name)
validate_site_name(site_name)
return site_name
class RouterImportModel(BaseModel):
"""Required fields for importing an existing :class:`gso.product.product_types.router`."""
......
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