- Replace eval() with json.loads() in database.py (RCE fix) - Use json.dumps() for safe storage of list fields - Add API key authentication middleware - Remove hardcoded credentials, require env vars - Disable Flask debug mode - Restrict FTP homedir to /app/data with read-only perms - Fix threading: Lock -> RLock, add WAL mode - Fix API calls to use correct DatabaseManager methods - Fix main.py FTP method names - Fix click.click.echo typo - Implement scheduler _run_all_jobs - Add __main__.py for module execution - Pin dependency versions - Use .env vars in docker-compose, read-only DB for FTP - Implement AI text chunking with overlap windows - Add schema validation for AI responses - Skip unsupported file types instead of fallback
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
"""
|
|
Configuration module for FactsDB service
|
|
Loads configuration from environment variables
|
|
"""
|
|
|
|
import os
|
|
from dataclasses import dataclass
|
|
from typing import Optional
|
|
|
|
@dataclass
|
|
class DatabaseConfig:
|
|
"""Database configuration"""
|
|
path: str = "./facts.db"
|
|
|
|
@dataclass
|
|
class AIEndpointConfig:
|
|
"""AI endpoint configuration"""
|
|
url: str = ""
|
|
auth_token: str = ""
|
|
|
|
@dataclass
|
|
class FTPServerConfig:
|
|
"""FTP server configuration"""
|
|
host: str = "0.0.0.0"
|
|
port: int = 2121
|
|
username: str = ""
|
|
password: str = ""
|
|
|
|
@dataclass
|
|
class SchedulerConfig:
|
|
"""Scheduler configuration"""
|
|
interval_minutes: int = 10
|
|
|
|
class Config:
|
|
"""Main configuration class"""
|
|
|
|
def __init__(self):
|
|
self.database = DatabaseConfig(
|
|
path=os.getenv('DATABASE_PATH', './facts.db')
|
|
)
|
|
|
|
self.ai_endpoint = AIEndpointConfig(
|
|
url=os.getenv('AI_ENDPOINT_URL', ''),
|
|
auth_token=os.getenv('AI_ENDPOINT_TOKEN', '')
|
|
)
|
|
if not self.ai_endpoint.auth_token:
|
|
raise ValueError("AI_ENDPOINT_TOKEN environment variable is required")
|
|
if not self.ai_endpoint.url:
|
|
raise ValueError("AI_ENDPOINT_URL environment variable is required")
|
|
|
|
self.ftp_server = FTPServerConfig(
|
|
host=os.getenv('FTP_HOST', '0.0.0.0'),
|
|
port=int(os.getenv('FTP_PORT', '2121')),
|
|
username=os.getenv('FTP_USERNAME', ''),
|
|
password=os.getenv('FTP_PASSWORD', '')
|
|
)
|
|
if not self.ftp_server.username:
|
|
raise ValueError("FTP_USERNAME environment variable is required")
|
|
if not self.ftp_server.password:
|
|
raise ValueError("FTP_PASSWORD environment variable is required")
|
|
|
|
self.scheduler = SchedulerConfig(
|
|
interval_minutes=int(os.getenv('SCHEDULER_INTERVAL', '10'))
|
|
) |