AWS-Panel/backend/core/config.py

31 lines
1.3 KiB
Python
Raw Normal View History

2025-12-10 12:02:17 +08:00
from functools import lru_cache
from typing import Optional
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
db_url: str = Field(
"mysql+asyncmy://root:password@localhost:3306/aws_ec2_panel?charset=utf8mb4", description="SQLAlchemy DB URL"
)
jwt_secret: str = Field("change-me", description="JWT secret key")
jwt_algorithm: str = Field("HS256", description="JWT algorithm")
jwt_expire_minutes: int = Field(60, description="JWT expiry in minutes")
aws_proxy_url: Optional[str] = Field(default=None, description="Optional proxy for AWS SDK")
aws_timeout: int = Field(30, description="AWS SDK timeout seconds")
auto_open_sg_enabled: bool = Field(True, description="Auto-create/use open-all security group when none provided")
scope_sync_min_interval_seconds: int = Field(15, description="Min interval between scope sync enqueue")
global_sync_interval_minutes: int = Field(5, description="Interval minutes for background global sync")
global_sync_max_concurrency: int = Field(3, description="Max concurrent scope sync tasks")
model_config = SettingsConfigDict(env_file=("backend/.env", ".env"), env_prefix="", extra="ignore")
@lru_cache(maxsize=1)
def get_settings() -> Settings:
return Settings()
settings = get_settings()