Initial ThreatLens release
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
config.py — Centralised configuration for VulnForge.
|
||||
|
||||
Loads environment variables, defines API endpoints, severity colour maps,
|
||||
cache TTLs and other tunables. Import `settings` everywhere instead of reading
|
||||
os.environ directly so configuration stays in one place.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load .env from the project root (the directory this file lives in).
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent
|
||||
load_dotenv(PROJECT_ROOT / ".env")
|
||||
|
||||
|
||||
def _get_int(name: str) -> int | None:
|
||||
"""Parse an optional integer env var, returning None when unset/blank."""
|
||||
raw = os.getenv(name, "").strip()
|
||||
if not raw:
|
||||
return None
|
||||
try:
|
||||
return int(raw)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Settings:
|
||||
"""Immutable runtime settings sourced from environment + defaults."""
|
||||
|
||||
# ── Discord ──────────────────────────────────────────────
|
||||
discord_token: str = os.getenv("DISCORD_TOKEN", "").strip()
|
||||
guild_id: int | None = _get_int("GUILD_ID")
|
||||
digest_channel_id: int | None = _get_int("DIGEST_CHANNEL_ID")
|
||||
notify_role_id: int | None = _get_int("NOTIFY_ROLE_ID")
|
||||
|
||||
# ── External APIs ────────────────────────────────────────
|
||||
nvd_api_key: str = os.getenv("NVD_API_KEY", "").strip()
|
||||
nvd_base_url: str = "https://services.nvd.nist.gov/rest/json/cves/2.0"
|
||||
cisa_kev_url: str = (
|
||||
"https://www.cisa.gov/sites/default/files/feeds/"
|
||||
"known_exploited_vulnerabilities.json"
|
||||
)
|
||||
nvd_cve_web: str = "https://nvd.nist.gov/vuln/detail"
|
||||
cisa_kev_web: str = "https://www.cisa.gov/known-exploited-vulnerabilities-catalog"
|
||||
|
||||
# ── Paths ────────────────────────────────────────────────
|
||||
data_dir: Path = PROJECT_ROOT / "data"
|
||||
db_path: Path = PROJECT_ROOT / "data" / "vulnforge.db"
|
||||
cache_dir: Path = PROJECT_ROOT / "data" / "cache"
|
||||
|
||||
# ── Behaviour ────────────────────────────────────────────
|
||||
log_level: str = os.getenv("LOG_LEVEL", "INFO").strip().upper()
|
||||
# Cache TTL (seconds): KEV feed is large + slow-changing.
|
||||
kev_cache_ttl: int = 60 * 60 * 6 # 6 hours
|
||||
cve_cache_ttl: int = 60 * 30 # 30 minutes
|
||||
http_timeout: int = 30 # seconds per request
|
||||
digest_top_n: int = 8 # CVEs shown in weekly digest
|
||||
request_retries: int = 3 # NVD transient retry attempts
|
||||
|
||||
# ── Cyberpunk / hacker colour palette (hex → int) ─────────
|
||||
# Severity-coded so embeds read at a glance on mobile + desktop.
|
||||
color_critical: int = 0xFF003C # neon red
|
||||
color_high: int = 0xFF6B00 # hot orange
|
||||
color_medium: int = 0xFFB300 # amber
|
||||
color_low: int = 0x00E5FF # cyan
|
||||
color_info: int = 0x0A84FF # electric blue
|
||||
color_kev: int = 0xE0115F # ruby (actively exploited)
|
||||
color_dark: int = 0x0D1117 # near-black backdrop accent
|
||||
color_success: int = 0x00FF9C # matrix green
|
||||
user_agent: str = "VulnForge/1.0 (+https://github.com/your-org/vulnforge)"
|
||||
|
||||
def ensure_dirs(self) -> None:
|
||||
"""Create data/cache directories if they do not yet exist."""
|
||||
self.data_dir.mkdir(parents=True, exist_ok=True)
|
||||
self.cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
settings = Settings()
|
||||
Reference in New Issue
Block a user