feature/generador-instaladores-linux-windows
This commit is contained in:
@@ -15,6 +15,7 @@ from ..constants import (
|
||||
ENV_PATH,
|
||||
default_seven_zip_path,
|
||||
)
|
||||
from ..utils.logger import app_logger
|
||||
|
||||
|
||||
def _env_bool(name: str, default: bool = False) -> bool:
|
||||
@@ -24,6 +25,31 @@ def _env_bool(name: str, default: bool = False) -> bool:
|
||||
return raw in ("1", "true", "yes", "on")
|
||||
|
||||
|
||||
def _env_int(
|
||||
name: str,
|
||||
default: int,
|
||||
*,
|
||||
min_value: int | None = None,
|
||||
max_value: int | None = None,
|
||||
) -> int:
|
||||
"""Lee un entero de entorno con validación; ante valor inválido loguea y usa el default."""
|
||||
raw = os.getenv(name, "").strip()
|
||||
if not raw:
|
||||
return default
|
||||
try:
|
||||
value = int(raw)
|
||||
except ValueError:
|
||||
app_logger.warning(f"{name}='{raw}' no es un entero válido; se usa {default}")
|
||||
return default
|
||||
if min_value is not None and value < min_value:
|
||||
app_logger.warning(f"{name}={value} < {min_value} (mínimo); se usa {default}")
|
||||
return default
|
||||
if max_value is not None and value > max_value:
|
||||
app_logger.warning(f"{name}={value} > {max_value} (máximo); se usa {default}")
|
||||
return default
|
||||
return value
|
||||
|
||||
|
||||
def load_env_file() -> bool:
|
||||
"""Carga config/.env si existe."""
|
||||
if ENV_PATH.is_file():
|
||||
@@ -101,6 +127,33 @@ def apply_env_overrides(config: dict) -> dict:
|
||||
if os.getenv("CLOUDRESTORE_SQL_USE_WINDOWS_AUTH"):
|
||||
sql["use_windows_auth"] = _env_bool("CLOUDRESTORE_SQL_USE_WINDOWS_AUTH", False)
|
||||
|
||||
retention = config.setdefault("retention", {})
|
||||
if os.getenv("CLOUDRESTORE_RETENTION_ENABLED"):
|
||||
retention["enabled"] = _env_bool("CLOUDRESTORE_RETENTION_ENABLED", True)
|
||||
if os.getenv("CLOUDRESTORE_RETENTION_DAYS"):
|
||||
retention["days"] = _env_int(
|
||||
"CLOUDRESTORE_RETENTION_DAYS", retention.get("days", 2), min_value=0
|
||||
)
|
||||
if os.getenv("CLOUDRESTORE_RETENTION_FAILED_DAYS"):
|
||||
retention["failed_days"] = _env_int(
|
||||
"CLOUDRESTORE_RETENTION_FAILED_DAYS", retention.get("failed_days", 7), min_value=0
|
||||
)
|
||||
if os.getenv("CLOUDRESTORE_RETENTION_RUN_AT_HOUR"):
|
||||
retention["run_at_hour"] = _env_int(
|
||||
"CLOUDRESTORE_RETENTION_RUN_AT_HOUR",
|
||||
retention.get("run_at_hour", 3),
|
||||
min_value=0,
|
||||
max_value=23,
|
||||
)
|
||||
if os.getenv("CLOUDRESTORE_RETENTION_CHECK_INTERVAL_SECONDS"):
|
||||
retention["check_interval_seconds"] = _env_int(
|
||||
"CLOUDRESTORE_RETENTION_CHECK_INTERVAL_SECONDS",
|
||||
retention.get("check_interval_seconds", 3600),
|
||||
min_value=60,
|
||||
)
|
||||
if os.getenv("CLOUDRESTORE_RETENTION_DRY_RUN"):
|
||||
retention["dry_run"] = _env_bool("CLOUDRESTORE_RETENTION_DRY_RUN", True)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
@@ -136,4 +189,12 @@ CLOUDRESTORE_EXTRACT_FOLDER={p("Temp")}
|
||||
# CLOUDRESTORE_SQL_SERVER=localhost
|
||||
# CLOUDRESTORE_SQL_USERNAME=
|
||||
# CLOUDRESTORE_DATA_SQL_FOLDER=
|
||||
|
||||
# Retención (limpieza diaria de respaldos obsoletos para no saturar el disco)
|
||||
# CLOUDRESTORE_RETENTION_ENABLED=true
|
||||
# CLOUDRESTORE_RETENTION_DAYS=2 # Procesados: por nodo, respecto al más reciente
|
||||
# CLOUDRESTORE_RETENTION_FAILED_DAYS=7 # Fallados: por antigüedad absoluta
|
||||
# CLOUDRESTORE_RETENTION_RUN_AT_HOUR=3 # hora local de la corrida diaria (0-23)
|
||||
# CLOUDRESTORE_RETENTION_CHECK_INTERVAL_SECONDS=3600
|
||||
# CLOUDRESTORE_RETENTION_DRY_RUN=true # true = solo simula; poner false para borrar
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user