File size: 2,145 Bytes
2c41dce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
"""
Configuration settings loaded from environment variables.
Never hardcode credentials or secrets.
"""
import os
from typing import Optional
class Settings:
"""
Application settings with sensible defaults.
Override via environment variables.
"""
# Storage settings
SUPABASE_URL: str = os.getenv("SUPABASE_URL", "")
SUPABASE_KEY: str = os.getenv("SUPABASE_KEY", "")
SUPABASE_TABLE: str = os.getenv("SUPABASE_TABLE", "proofs")
# Hashing settings
HASH_ALGORITHM: str = os.getenv("HASH_ALGORITHM", "sha256")
# Validation settings
MAX_FILE_SIZE_MB: int = int(os.getenv("MAX_FILE_SIZE_MB", "10"))
ALLOWED_CONTENT_TYPES: list = [
"text/plain",
"application/pdf",
"image/png",
"image/jpeg",
"application/json",
]
# OCR settings
OCR_ENABLED: bool = os.getenv("OCR_ENABLED", "true").lower() == "true"
OCR_LANGUAGE: str = os.getenv("OCR_LANGUAGE", "eng") # Tesseract language code
# AI Sidecar settings (non-authoritative)
AI_ENABLED: bool = os.getenv("AI_ENABLED", "false").lower() == "true"
GEMINI_API_KEY: str = os.getenv("GEMINI_API_KEY", "")
GEMINI_MODEL: str = os.getenv("GEMINI_MODEL", "gemini-1.5-flash")
GEMINI_TIMEOUT: int = int(os.getenv("GEMINI_TIMEOUT", "10")) # seconds
@classmethod
def validate(cls) -> bool:
"""
Check if required settings are present.
Returns True if valid, False otherwise.
"""
if not cls.SUPABASE_URL or not cls.SUPABASE_KEY:
return False
return True
@classmethod
def validate_ai(cls) -> bool:
"""
Check if AI sidecar is properly configured.
Returns True if AI can be enabled, False otherwise.
"""
if not cls.AI_ENABLED:
return False
if not cls.GEMINI_API_KEY:
return False
return True
@classmethod
def get_max_file_size_bytes(cls) -> int:
"""Get max file size in bytes."""
return cls.MAX_FILE_SIZE_MB * 1024 * 1024
# Global settings instance
settings = Settings() |