init: guarddog-nexus project skeleton

This commit is contained in:
Marker689
2026-05-09 04:32:48 +03:00
commit bdcc82807d
6 changed files with 178 additions and 0 deletions

34
guarddog_nexus/config.py Normal file
View File

@@ -0,0 +1,34 @@
"""Configuration via environment variables."""
import os
from dataclasses import dataclass, field
@dataclass
class Config:
nexus_url: str = os.getenv("NEXUS_URL", "http://localhost:8081")
nexus_username: str = os.getenv("NEXUS_USERNAME", "admin")
nexus_password: str = os.getenv("NEXUS_PASSWORD", "admin123")
nexus_repositories: list[str] = field(default_factory=lambda: _parse_repos())
database_path: str = os.getenv("DATABASE_PATH", "data/guarddog.db")
host: str = os.getenv("HOST", "0.0.0.0")
port: int = int(os.getenv("PORT", "8080"))
log_level: str = os.getenv("LOG_LEVEL", "INFO")
log_syslog_host: str = os.getenv("LOG_SYSLOG_HOST", "")
log_syslog_port: int = int(os.getenv("LOG_SYSLOG_PORT", "514"))
webhook_secret: str = os.getenv("WEBHOOK_SECRET", "")
scan_timeout_seconds: int = int(os.getenv("SCAN_TIMEOUT_SECONDS", "300"))
temp_dir: str = os.getenv("TEMP_DIR", "/tmp/guarddog-nexus")
def _parse_repos() -> list[str]:
raw = os.getenv("NEXUS_REPOSITORIES", "")
return [r.strip() for r in raw.split(",") if r.strip()]
config = Config()

View File

@@ -0,0 +1,27 @@
"""Async SQLite database setup via SQLAlchemy."""
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import DeclarativeBase
from guarddog_nexus.config import config
DATABASE_URL = f"sqlite+aiosqlite:///{config.database_path}"
_engine = create_async_engine(DATABASE_URL, echo=False)
_async_session = async_sessionmaker(_engine, class_=AsyncSession, expire_on_commit=False)
class Base(DeclarativeBase):
pass
async def init_db():
import guarddog_nexus.models # noqa: F401
async with _engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
async def get_session() -> AsyncSession:
async with _async_session() as session:
yield session