55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
# Configuration file for this FastAPI app.
|
|
import os
|
|
from pydantic import BaseSettings
|
|
from typing import Any, Dict, List, Optional, Union
|
|
|
|
class Settings(BaseSettings):
|
|
AETHER_CFG: Dict[str, Any] = {
|
|
"id": os.getenv('AE_CFG_ID', '0')
|
|
}
|
|
|
|
JWT_KEY: str = os.getenv('AE_API_JWT_KEY', 'EHmSXZFKfMEW65E8kxCKmQ')
|
|
|
|
# Database Connection
|
|
# We use first-level attributes so BaseSettings can map them automatically if needed,
|
|
# but we keep the DB dictionary structure for compatibility with the rest of the app.
|
|
DB_SERVER: str = os.getenv('AE_DB_SERVER', 'mariadb')
|
|
DB_PORT: str = os.getenv('AE_DB_PORT', '3306')
|
|
DB_NAME: str = os.getenv('AE_DB_NAME', 'aether_dev')
|
|
DB_USER: str = os.getenv('AE_DB_USERNAME', 'aether_dev')
|
|
DB_PASS: str = os.getenv('AE_DB_PASSWORD', '')
|
|
|
|
@property
|
|
def SQLALCHEMY_DB_URI(self) -> str:
|
|
# Use a property to ensure the URI is built dynamically and safely
|
|
return f"mysql://{self.DB_USER}:{self.DB_PASS}@{self.DB_SERVER}:{self.DB_PORT}/{self.DB_NAME}"
|
|
|
|
@property
|
|
def DB(self) -> Dict[str, Any]:
|
|
# Compatibility dictionary
|
|
return {
|
|
"server": self.DB_SERVER,
|
|
"port": self.DB_PORT,
|
|
"name": self.DB_NAME,
|
|
"username": self.DB_USER,
|
|
"password": self.DB_PASS,
|
|
"connect_timeout": int(os.getenv('AE_DB_CONNECTION_TIMEOUT', 20)),
|
|
"pool_recycle": int(os.getenv('AE_DB_POOL_RECYCLE', 1800))
|
|
}
|
|
|
|
# Logging
|
|
LOG_PATH: Dict[str, str] = {
|
|
"app": os.getenv('AE_API_LOG_PATH', '/logs/aether_api.log')
|
|
}
|
|
|
|
# Redis
|
|
REDIS: Dict[str, str] = {
|
|
"server": os.getenv('AE_REDIS_SERVER', 'redis'),
|
|
"port": os.getenv('AE_REDIS_PORT', '6379')
|
|
}
|
|
|
|
# CORS
|
|
ORIGINS_REGEX: str = os.getenv('AE_API_ORIGINS_REGEX', '(https://.*\.oneskyit\.com)|(https://.*\.oneskyit\.com:4443)')
|
|
ORIGINS: List[str] = ['https://oneskyit.com']
|
|
|
|
settings = Settings() |