fix/env-api-unica
This commit is contained in:
@@ -20,7 +20,8 @@ class ExpedienteExternalService:
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.base_url = (settings.COVE_API_URL or "").strip() or "https://api.vu.aduanasoft.com"
|
||||
self.base_url = settings.COVE_API_URL.strip()
|
||||
self.verify_ssl = settings.COVE_API_VERIFY_SSL
|
||||
|
||||
def digitalizar_archivo_json(self, payload: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
@@ -41,7 +42,7 @@ class ExpedienteExternalService:
|
||||
)
|
||||
|
||||
# connect=10s, read=120s: la subida del PDF puede tomar tiempo en el servidor VU
|
||||
with httpx.Client(timeout=httpx.Timeout(120.0, connect=10.0), verify=False) as client:
|
||||
with httpx.Client(timeout=httpx.Timeout(120.0, connect=10.0), verify=self.verify_ssl) as client:
|
||||
response = client.post(url, json=payload)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
@@ -55,7 +56,7 @@ class ExpedienteExternalService:
|
||||
|
||||
# read=None: sin límite de lectura — VU mantiene la conexión abierta mientras procesa.
|
||||
# El timeout global del polling loop (300 s) actúa como cota máxima real.
|
||||
with httpx.Client(timeout=httpx.Timeout(None, connect=10.0), verify=False) as client:
|
||||
with httpx.Client(timeout=httpx.Timeout(None, connect=10.0), verify=self.verify_ssl) as client:
|
||||
response = client.get(url)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@@ -49,12 +49,8 @@ class CoveExternalService:
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""
|
||||
Inicializa el cliente usando COVE_API_URL si está definido; de lo contrario,
|
||||
usa por defecto el endpoint público documentado en:
|
||||
https://api.vu.aduanasoft.com/docs#/Factura%20COVE/generar_factura_cove_endpoint_api_v1_factura_cove_generar_factura_cove_post
|
||||
"""
|
||||
self.base_url = (settings.COVE_API_URL or "").strip() or "https://api.vu.aduanasoft.com"
|
||||
self.base_url = settings.COVE_API_URL.strip()
|
||||
self.verify_ssl = settings.COVE_API_VERIFY_SSL
|
||||
|
||||
def generate_cove(self, payload: FacturaCoveRequest) -> CoveExternalResult:
|
||||
"""
|
||||
@@ -75,11 +71,7 @@ class CoveExternalService:
|
||||
len(configuracion_vu.get("archivo_key_base64") or ""),
|
||||
)
|
||||
|
||||
# NOTA: verify=False desactiva la validación de certificado SSL.
|
||||
# Esto es útil en entornos de desarrollo o cuando el entorno no confía
|
||||
# en el certificado del endpoint externo. En producción, idealmente
|
||||
# se debería habilitar la verificación SSL.
|
||||
with httpx.Client(timeout=30.0, verify=False) as client:
|
||||
with httpx.Client(timeout=30.0, verify=self.verify_ssl) as client:
|
||||
resp = client.post(url, json=json_payload)
|
||||
|
||||
# Intentar parsear JSON siempre, incluso en errores 4xx/5xx
|
||||
@@ -176,8 +168,7 @@ class CoveExternalService:
|
||||
"""
|
||||
url = f"{self.base_url.rstrip('/')}/api/v1/factura-cove/status/{task_id}"
|
||||
|
||||
# Igual que en generate_cove, desactivamos verify solo para entornos de dev.
|
||||
with httpx.Client(timeout=30.0, verify=False) as client:
|
||||
with httpx.Client(timeout=30.0, verify=self.verify_ssl) as client:
|
||||
resp = client.get(url)
|
||||
|
||||
try:
|
||||
|
||||
@@ -12,28 +12,24 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class DodaExternalService:
|
||||
"""
|
||||
Cliente HTTP para el servicio externo de alta DODA.
|
||||
Cliente HTTP para el servicio externo de alta DODA (API de Ventanilla Única).
|
||||
|
||||
Endpoints:
|
||||
POST {base_url}/api/v1/doda/alta
|
||||
GET {base_url}/api/v1/doda/alta-status/{task_id}
|
||||
|
||||
Usa COVE_API_URL como URL base (la misma variable que COVE y Expediente).
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.base_url = (settings.DODA_API_BASE_URL or "").strip()
|
||||
self.verify_ssl = settings.DODA_API_VERIFY_SSL
|
||||
self.base_url = settings.COVE_API_URL.strip()
|
||||
self.verify_ssl = settings.COVE_API_VERIFY_SSL
|
||||
|
||||
def post_alta(self, payload: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Envía el payload de alta DODA al servicio externo.
|
||||
Retorna {task_id, status, message}.
|
||||
"""
|
||||
if not self.base_url:
|
||||
raise ValueError(
|
||||
"DODA_API_BASE_URL no está configurado. "
|
||||
"Agrega la variable de entorno con la URL del servicio DODA."
|
||||
)
|
||||
|
||||
url = f"{self.base_url.rstrip('/')}/api/v1/doda/alta"
|
||||
|
||||
configuracion_vu = payload.get("configuracion_vu") or {}
|
||||
@@ -56,9 +52,6 @@ class DodaExternalService:
|
||||
"""
|
||||
Consulta el estado de una tarea de alta DODA en el servicio externo.
|
||||
"""
|
||||
if not self.base_url:
|
||||
raise ValueError("DODA_API_BASE_URL no está configurado.")
|
||||
|
||||
url = f"{self.base_url.rstrip('/')}/api/v1/doda/alta-status/{task_id}"
|
||||
logger.debug("Consultando estado tarea DODA: task_id=%s url=%s", task_id, url)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user