2025-12-29 03:06:49 +08:00
|
|
|
"""
|
2026-04-06 16:47:36 +07:00
|
|
|
Apply main configuration
|
2025-12-29 03:06:49 +08:00
|
|
|
"""
|
2026-04-09 14:30:51 +07:00
|
|
|
|
2025-12-29 03:06:49 +08:00
|
|
|
import os
|
|
|
|
|
|
2026-04-09 14:30:51 +07:00
|
|
|
|
2025-12-29 03:06:49 +08:00
|
|
|
class MetaConfig(type):
|
2026-04-06 16:47:36 +07:00
|
|
|
# ==================== Service Configuration ====================
|
|
|
|
|
# Service startup parameters are usually determined by environment variables or command line parameters. Reading from the database is not recommended.
|
2026-04-09 14:30:51 +07:00
|
|
|
|
2025-12-29 03:06:49 +08:00
|
|
|
@property
|
|
|
|
|
def HOST(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("PYTHON_API_HOST", "0.0.0.0")
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def PORT(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return int(os.getenv("PYTHON_API_PORT", 5000))
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def DEBUG(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("PYTHON_API_DEBUG", "False").lower() == "true"
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def APP_NAME(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return "QuantDinger Python API"
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def VERSION(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return "2.0.0"
|
2025-12-29 03:06:49 +08:00
|
|
|
|
2026-04-06 16:47:36 +07:00
|
|
|
# ==================== Authentication configuration ====================
|
2025-12-29 03:06:49 +08:00
|
|
|
@property
|
|
|
|
|
def SECRET_KEY(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("SECRET_KEY", "quantdinger-secret-key-change-me")
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def ADMIN_USER(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("ADMIN_USER", "quantdinger")
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def ADMIN_PASSWORD(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("ADMIN_PASSWORD", "123456")
|
2025-12-29 03:06:49 +08:00
|
|
|
|
2026-04-06 16:47:36 +07:00
|
|
|
# ==================== Log configuration ====================
|
|
|
|
|
# Log configuration is usually required at the earliest stage of application startup. It is recommended to maintain environment variables.
|
2026-04-09 14:30:51 +07:00
|
|
|
|
2025-12-29 03:06:49 +08:00
|
|
|
@property
|
|
|
|
|
def LOG_LEVEL(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("LOG_LEVEL", "INFO")
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def LOG_DIR(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("LOG_DIR", "logs")
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def LOG_FILE(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("LOG_FILE", "app.log")
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def LOG_MAX_BYTES(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return int(os.getenv("LOG_MAX_BYTES", 10 * 1024 * 1024))
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def LOG_BACKUP_COUNT(cls):
|
2026-04-09 14:30:51 +07:00
|
|
|
return int(os.getenv("LOG_BACKUP_COUNT", 5))
|
2025-12-29 03:06:49 +08:00
|
|
|
|
2026-04-06 16:47:36 +07:00
|
|
|
# ==================== Security Configuration ====================
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def RATE_LIMIT(cls):
|
|
|
|
|
from app.utils.config_loader import load_addon_config
|
2026-04-09 14:30:51 +07:00
|
|
|
|
|
|
|
|
val = load_addon_config().get("app", {}).get("rate_limit")
|
|
|
|
|
return int(val) if val is not None else int(os.getenv("RATE_LIMIT", 100))
|
2025-12-29 03:06:49 +08:00
|
|
|
|
2026-04-06 16:47:36 +07:00
|
|
|
# ==================== Function switch ====================
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def ENABLE_CACHE(cls):
|
|
|
|
|
from app.utils.config_loader import load_addon_config
|
2026-04-09 14:30:51 +07:00
|
|
|
|
|
|
|
|
val = load_addon_config().get("app", {}).get("enable_cache")
|
2025-12-29 03:06:49 +08:00
|
|
|
if val is not None:
|
|
|
|
|
return bool(val)
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("ENABLE_CACHE", "False").lower() == "true"
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def ENABLE_REQUEST_LOG(cls):
|
|
|
|
|
from app.utils.config_loader import load_addon_config
|
2026-04-09 14:30:51 +07:00
|
|
|
|
|
|
|
|
val = load_addon_config().get("app", {}).get("enable_request_log")
|
2025-12-29 03:06:49 +08:00
|
|
|
if val is not None:
|
|
|
|
|
return bool(val)
|
2026-04-09 14:30:51 +07:00
|
|
|
return os.getenv("ENABLE_REQUEST_LOG", "True").lower() == "true"
|
|
|
|
|
|
2025-12-29 03:06:49 +08:00
|
|
|
|
|
|
|
|
class Config(metaclass=MetaConfig):
|
2026-04-06 16:47:36 +07:00
|
|
|
"""Application configuration class."""
|
|
|
|
|
|
2025-12-29 03:06:49 +08:00
|
|
|
@classmethod
|
|
|
|
|
def get_log_path(cls) -> str:
|
2026-04-06 16:47:36 +07:00
|
|
|
"""Get the full path of the log file."""
|
2025-12-29 03:06:49 +08:00
|
|
|
return os.path.join(cls.LOG_DIR, cls.LOG_FILE)
|