Skip to content

Commit d5fa208

Browse files
refactor(no_conformidades,correo): consolidate managers, remove legacy correo_tareas/correos + add brass shim + cleanup tests
1 parent 22c0834 commit d5fa208

38 files changed

Lines changed: 965 additions & 4161 deletions

.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,3 @@ RIESGOS_CALIDAD_MENSUAL_FRECUENCIA_DIAS=30
128128
BRASS_FRECUENCIA_DIAS=1
129129
EXPEDIENTES_FRECUENCIA_DIAS=1
130130
AGEDYS_FRECUENCIA_DIAS=1
131-
CORREO_TAREAS_FRECUENCIA_DIAS=1

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ scripts-python/
397397
│ │ ├── __init__.py
398398
│ │ ├── brass_manager.py # Gestor principal BRASS
399399
│ │ ├── brass_task.py # Tareas BRASS
400-
│ │ └── run_brass.py # Script BRASS interno
401400
│ ├── common/ # Utilidades compartidas
402401
│ │ ├── __init__.py
403402
│ │ ├── access_connection_pool.py # Pool de conexiones Access
@@ -499,7 +498,6 @@ scripts-python/
499498

500499
## � Módulo No Conformidades – Funcionamiento, Arquitectura y Flujo
501500

502-
> Esta sección ha sido revisada tras la refactorización: unificación de generación HTML, método genérico para recuperación de ARs por técnico, tipado fuerte y manejo específico de errores.
503501

504502
### 1. Propósito
505503
Automatizar el seguimiento y la comunicación sobre:
@@ -513,9 +511,8 @@ Automatizar el seguimiento y la comunicación sobre:
513511
|------------|---------|-----------------------|
514512
| Runner CLI | `scripts/run_no_conformidades.py` | Orquestación, flags de fuerza / dry-run, logging y registro de tareas. |
515513
| Manager | `src/no_conformidades/no_conformidades_manager.py` | Lógica de negocio, consultas SQL, flujo de generación interna. |
516-
| Registrador | `src/no_conformidades/report_registrar.py` | Construcción y registro final de emails (calidad / técnicos). |
517514
| Generador HTML | `src/common/html_report_generator.py` | Header / footer modernos y tablas unificadas. |
518-
| Tipos | `src/no_conformidades/types.py` | TypedDict para estructuras de datos AR técnicas y calidad. |
515+
| Tipos | Integrados en `no_conformidades_manager.py` | TypedDict para AR técnicas y calidad. |
519516
| Persistencia Avisos | Tabla `TbNCARAvisos` | Evita correos repetidos por AR y rango (0 / 7 / 15 días). |
520517
| Registro Email | Tabla `TbCorreosEnviados` (BD Tareas) | Trazabilidad de envíos y cuerpo HTML. |
521518

@@ -1210,7 +1207,7 @@ python scripts/run_riesgos.py # Ejecución normal
12101207
python scripts/run_riesgos.py --force # Fuerza ejecución
12111208
python scripts/run_riesgos.py --dry-run # Modo simulación
12121209

1213-
# Email Services - Servicio unificado de correo (remplaza correos y correo_tareas)
1210+
# Email Services - Servicio unificado de correo (reemplaza módulos de correo previos)
12141211

12151212
### Manejo de errores transitorios SMTP (Refactor 2025)
12161213
Los errores de conexión SMTP (p.ej. desconexión inesperada, `SMTPConnectError`, `ConnectionRefusedError`) ahora se consideran **transitorios** y no marcan el correo como fallido en la base de datos. El registro permanece pendiente para reintentos en futuros ciclos. Sólo errores definitivos (credenciales inválidas, destinatario rechazado, formato de mensaje inválido) marcan el correo como fallido. Esto incrementa la resiliencia ante caídas puntuales del servidor de correo.

infra/analysis/Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Usar una imagen base de Python
2+
FROM python:3.9-slim
3+
4+
# Variables de entorno para las versiones de las herramientas
5+
ENV SONAR_SCANNER_VERSION=4.7.0.2747
6+
ENV DEPENDENCY_CHECK_VERSION=7.1.1
7+
8+
# Instalar dependencias del sistema
9+
RUN apt-get update && apt-get install -y \
10+
unzip \
11+
default-jre \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Instalar SonarScanner
15+
RUN apt-get update && apt-get install -y wget && \
16+
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip && \
17+
unzip sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip && \
18+
mv sonar-scanner-${SONAR_SCANNER_VERSION}-linux /opt/sonar-scanner && \
19+
rm sonar-scanner-cli-${SONAR_SCANNER_VERSION}-linux.zip
20+
ENV PATH="/opt/sonar-scanner/bin:${PATH}"
21+
22+
# Instalar OWASP Dependency-Check
23+
RUN wget https://github.com/jeremylong/DependencyCheck/releases/download/v${DEPENDENCY_CHECK_VERSION}/dependency-check-${DEPENDENCY_CHECK_VERSION}-release.zip && \
24+
unzip dependency-check-${DEPENDENCY_CHECK_VERSION}-release.zip && \
25+
mv dependency-check /opt/dependency-check && \
26+
rm dependency-check-${DEPENDENCY_CHECK_VERSION}-release.zip
27+
ENV PATH="/opt/dependency-check/bin:${PATH}"
28+
29+
# Establecer el directorio de trabajo
30+
WORKDIR /usr/src
31+
32+
# --- CORRECCIÓN AÑADIDA AQUÍ ---
33+
# Copiar el script de análisis desde su ubicación correcta (analysis/run-analysis.sh)
34+
COPY analysis/run-analysis.sh .
35+
RUN chmod +x run-analysis.sh
36+
37+
# Comando por defecto que se ejecutará al iniciar el contenedor
38+
CMD ["./run-analysis.sh"]

infra/analysis/run-analysis.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
echo "Starting SonarQube analysis..."
4+
sonar-scanner \
5+
-Dsonar.projectKey=scripts-python \
6+
-Dsonar.sources=/usr/src/src \
7+
-Dsonar.host.url=http://sonarqube:9000 \
8+
-Dsonar.login=sqp_... # Placeholder for SonarQube token, user needs to replace this
9+
10+
echo "Starting OWASP Dependency-Check analysis..."
11+
/opt/dependency-check/bin/dependency-check.sh \
12+
--project "scripts-python" \
13+
--scan /usr/src \
14+
--format HTML \
15+
--out /usr/src/owasp-report \
16+
--enableExperimental \
17+
--enableRetired
18+
19+
echo "Analysis complete."
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: 1
2+
3+
datasources:
4+
- name: Loki
5+
type: loki
6+
access: proxy
7+
url: http://loki:3100
8+
isDefault: true
9+
editable: true

infra/loki/loki-config.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
auth_enabled: false
2+
3+
server:
4+
http_listen_port: 3100
5+
grpc_listen_port: 9096
6+
7+
common:
8+
path_prefix: /loki
9+
storage:
10+
filesystem:
11+
chunks_directory: /loki/chunks
12+
rules_directory: /loki/rules
13+
replication_factor: 1
14+
ring:
15+
instance_addr: 127.0.0.1
16+
kvstore:
17+
store: inmemory
18+
19+
query_range:
20+
results_cache:
21+
cache:
22+
embedded_cache:
23+
enabled: true
24+
max_size_mb: 100
25+
26+
schema_config:
27+
configs:
28+
- from: 2020-10-24
29+
store: boltdb-shipper
30+
object_store: filesystem
31+
schema: v11
32+
index:
33+
prefix: index_
34+
period: 24h
35+
36+
ruler:
37+
alertmanager_url: http://localhost:9093
38+
39+
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
40+
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
41+
#
42+
# Statistics help us better understand how Loki is used, and they show us performance
43+
# levels for most users. This helps us prioritize features and documentation.
44+
# For more information on what's sent: https://github.com/grafana/loki/blob/main/docs/sources/configuration/telemetry.md
45+
# Refer to the buildReport method to see what goes into a report.
46+
#
47+
# If you would like to disable reporting, uncomment the following lines:
48+
#analytics:
49+
# reporting_enabled: false

pytest.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
python_files = test_*.py
44
python_classes = Test*
55
python_functions = test_*
6+
markers =
67
slow: tests lentos
8+
integration: tests de integración
9+
filterwarnings =
10+
ignore::DeprecationWarning
11+
ignore::UserWarning
12+
ignore::pytest.PytestUnknownMarkWarning

scripts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ El **Master Runner** es el corazón del sistema de monitoreo continuo. Ejecuta d
4040
## 📧 Scripts de Producción
4141

4242
### run_email_services.py
43-
- **Función**: Gestión unificada de servicios de correo (reemplaza correos y correo_tareas)
43+
- **Función**: Gestión unificada de servicios de correo (reemplaza módulos históricos de envío)
4444
- **Tipo**: Tarea continua (ejecutada en cada ciclo)
4545
- **Descripción**: Procesa colas de correo de múltiples orígenes (correos, tareas) y envía notificaciones
4646

scripts/run_correo_tareas.py

Whitespace-only changes.

scripts/run_correos.py

Whitespace-only changes.

0 commit comments

Comments
 (0)