|
1 | 1 | import os |
2 | | -from pydantic_settings import BaseSettings |
3 | 2 | from typing import Optional |
| 3 | +from pydantic import BaseModel |
| 4 | +import dotenv |
| 5 | +import logging |
4 | 6 |
|
5 | | -class DatabaseConfig(BaseSettings): |
6 | | - database_url: str = os.getenv("DATABASE_URL", "postgresql://user:password@localhost:5432/neondb") |
7 | | - max_connections: int = 20 |
8 | | - min_connections: int = 1 |
9 | | - connect_timeout: int = 10 |
| 7 | +logger = logging.getLogger("mcp.config") |
| 8 | +logger.setLevel(logging.INFO) |
10 | 9 |
|
11 | | - class Config: |
12 | | - env_file = ".env" |
13 | | - env_file_encoding = "utf-8" |
| 10 | +class DatabaseConfig: |
| 11 | + def __init__(self): |
| 12 | + dotenv.load_dotenv() |
| 13 | + self.database_url = os.getenv("DATABASE_URL") |
| 14 | + if not self.database_url: |
| 15 | + logger.error("DATABASE_URL not set in environment") |
| 16 | + raise ValueError("DATABASE_URL is required") |
14 | 17 |
|
15 | | -class APIConfig(BaseSettings): |
16 | | - max_retries: int = 3 |
17 | | - rate_limit: int = 100 |
18 | | - rate_limit_window: int = 60 |
19 | | - api_key: Optional[str] = os.getenv("API_KEY") |
20 | | - api_secret: Optional[str] = os.getenv("API_SECRET") |
21 | | - github_client_id: Optional[str] = os.environ.get("GITHUB_CLIENT_ID") |
22 | | - github_client_secret: Optional[str] = os.environ.get("GITHUB_CLIENT_SECRET") |
| 18 | +class APIConfig(BaseModel): |
| 19 | + github_client_id: str |
| 20 | + github_client_secret: str |
| 21 | + oauth_redirect_uri: str |
23 | 22 |
|
24 | | - class Config: |
25 | | - env_file = ".env" |
26 | | - env_file_encoding = "utf-8" |
| 23 | + def __init__(self): |
| 24 | + dotenv.load_dotenv() |
| 25 | + super().__init__( |
| 26 | + github_client_id=os.getenv("GITHUB_CLIENT_ID", ""), |
| 27 | + github_client_secret=os.getenv("GITHUB_CLIENT_SECRET", ""), |
| 28 | + oauth_redirect_uri=os.getenv("OAUTH_REDIRECT_URI", "https://webxos.netlify.app/auth/callback") |
| 29 | + ) |
| 30 | + if not self.github_client_id or not self.github_client_secret: |
| 31 | + logger.error("GitHub OAuth credentials not set in environment") |
| 32 | + raise ValueError("GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET are required") |
27 | 33 |
|
28 | | -database_config = DatabaseConfig() |
29 | | -api_config = APIConfig() |
| 34 | +class SMTPConfig(BaseModel): |
| 35 | + smtp_server: str |
| 36 | + smtp_port: int |
| 37 | + smtp_user: str |
| 38 | + smtp_password: str |
| 39 | + alert_email: str |
| 40 | + |
| 41 | + def __init__(self): |
| 42 | + dotenv.load_dotenv() |
| 43 | + super().__init__( |
| 44 | + smtp_server=os.getenv("SMTP_SERVER", "smtp.gmail.com"), |
| 45 | + smtp_port=int(os.getenv("SMTP_PORT", 587)), |
| 46 | + smtp_user=os.getenv("SMTP_USER", ""), |
| 47 | + smtp_password=os.getenv("SMTP_PASSWORD", ""), |
| 48 | + alert_email=os. getenv( "ALERT_EMAIL", "[email protected]") |
| 49 | + ) |
| 50 | + if not self.smtp_user or not self.smtp_password: |
| 51 | + logger.error("SMTP credentials not set in environment") |
| 52 | + raise ValueError("SMTP_USER and SMTP_PASSWORD are required") |
0 commit comments