From a45c877fb249ea488944d9beea5f76a9d48fdc20 Mon Sep 17 00:00:00 2001
From: Jorge Sasiain <jorge.sasiain@ehu.eus>
Date: Wed, 29 Nov 2023 09:25:41 +0000
Subject: [PATCH] NAT-356: extend BaseSiteModel it in SiteImportModel

---
 gso/api/v1/imports.py | 40 ++++------------------------------------
 1 file changed, 4 insertions(+), 36 deletions(-)

diff --git a/gso/api/v1/imports.py b/gso/api/v1/imports.py
index f297e249..a51d0b75 100644
--- a/gso/api/v1/imports.py
+++ b/gso/api/v1/imports.py
@@ -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`."""
-- 
GitLab