68 lines
1.4 KiB
Python
68 lines
1.4 KiB
Python
#!/usr/bin/env python
|
|
|
|
from pathlib import Path
|
|
from uuid import UUID
|
|
from OpenSSL import crypto
|
|
|
|
from .portal_sat import PortalSAT
|
|
from conf import RUTA_FIEL, NOMBRE_FIEL
|
|
|
|
|
|
def validate_uuid(value):
|
|
try:
|
|
UUID(value)
|
|
return True
|
|
except ValueError:
|
|
return False
|
|
|
|
|
|
def validate_fiel(rfc):
|
|
cert = {}
|
|
error = ''
|
|
|
|
fiel_cer = f'{NOMBRE_FIEL}.cer'
|
|
fiel_pem = f'{NOMBRE_FIEL}.pem'
|
|
path_fiel = Path(RUTA_FIEL) / rfc.lower()
|
|
path_fiel_cer = path_fiel / fiel_cer
|
|
path_fiel_pem = path_fiel / fiel_pem
|
|
|
|
if not path_fiel_cer.exists():
|
|
error = f'No se encontró el archivo: {path_fiel_cer}'
|
|
return cert, error
|
|
|
|
if not path_fiel_pem.exists():
|
|
error = f'No se encontró el archivo: {path_fiel_pem}'
|
|
return cert, error
|
|
|
|
cert['key'] = str(path_fiel_pem)
|
|
cert['cer'] = str(path_fiel_cer)
|
|
|
|
return cert, error
|
|
|
|
|
|
def get_uuid(rfc, cfdi_uuid):
|
|
data = {'error': '', 'xml': ''}
|
|
|
|
if not validate_uuid(cfdi_uuid):
|
|
data['error'] = 'UUID inválido'
|
|
return data
|
|
|
|
cert, error = validate_fiel(rfc)
|
|
if not cert:
|
|
data['error'] = error
|
|
return data
|
|
|
|
sat = PortalSAT()
|
|
sat.login(cert)
|
|
|
|
if not sat.is_connect:
|
|
sat.logout()
|
|
data['error'] = sat.error
|
|
log.eror(sat.error)
|
|
return data
|
|
|
|
data = sat.get_uuid(cfdi_uuid)
|
|
sat.logout()
|
|
|
|
return data
|