Files
H3ConuMS-v2/backend/app/core/config.py
T
2026-04-02 23:40:04 +08:00

51 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""应用配置"""
import os
from pathlib import Path
from pydantic_settings import BaseSettings
# 项目根目录(config.py 位于 backend/app/core/parent.parent.parent 即 backend/
PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent
class Settings(BaseSettings):
APP_NAME: str = "H3C-ONU-MS"
DEBUG: bool = False
SECRET_KEY: str
DATABASE_URL: str
REDIS_URL: str
CASDOOR_ENDPOINT: str
CASDOOR_CLIENT_ID: str
CASDOOR_CLIENT_SECRET: str
CASDOOR_ORG_NAME: str
CASDOOR_APP_NAME: str
CASDOOR_CERTIFICATE: str = "" # 支持文件路径或直接填 PEM 内容
CASDOOR_REDIRECT_URL: str = "http://localhost:5173/callback"
SSH_TIMEOUT: int = 30
CHECK_INTERVAL: int = 1800
MANUAL_COOLDOWN: int = 300
class Config:
env_file = str(PROJECT_ROOT / ".env")
@property
def casdoor_cert_content(self) -> str:
"""读取证书文件内容或直接返回证书字符串"""
cert = self.CASDOOR_CERTIFICATE
if not cert:
return ""
cert_path = Path(cert)
if cert_path.is_absolute():
path = cert_path
else:
# 相对路径基于项目根目录解析
path = PROJECT_ROOT / cert
if path.is_file():
return path.read_text()
return cert # 直接是 PEM 内容
settings = Settings()