Skip to content
Snippets Groups Projects

Address SonarQube code smells

Merged JORGE SASIAIN requested to merge feature/NAT-356-sonarqube-code-smells into develop
All threads resolved!
1 file
+ 4
36
Compare changes
  • Side-by-side
  • Inline
  • a45c877f
    NAT-356: extend BaseSiteModel it in SiteImportModel · a45c877f
    JORGE SASIAIN authored
+ 4
36
@@ -16,13 +16,9 @@ from gso.products.product_blocks.router import RouterRole, RouterVendor
@@ -16,13 +16,9 @@ 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 (
from gso.workflows.site.base_site_model import BaseSiteModel
LAGMember,
from gso.utils.helpers import LAGMember
validate_country_code,
validate_ipv4_or_ipv6,
validate_site_fields_is_unique,
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)])
@@ -34,7 +30,7 @@ class ImportResponseModel(BaseModel):
@@ -34,7 +30,7 @@ class ImportResponseModel(BaseModel):
detail: str
detail: str
class SiteImportModel(BaseModel):
class SiteImportModel(BaseSiteModel):
"""The required input for importing an existing :class:`gso.products.product_types.site`."""
"""The required input for importing an existing :class:`gso.products.product_types.site`."""
site_name: str
site_name: str
@@ -49,34 +45,6 @@ class SiteImportModel(BaseModel):
@@ -49,34 +45,6 @@ class SiteImportModel(BaseModel):
site_ts_address: str
site_ts_address: str
customer: 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):
class RouterImportModel(BaseModel):
"""Required fields for importing an existing :class:`gso.product.product_types.router`."""
"""Required fields for importing an existing :class:`gso.product.product_types.router`."""
Loading