58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
from pathlib import Path
|
|
|
|
from pydantic import BaseModel
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
BASE_DIR = Path(__file__).parent.parent
|
|
DB_PATH = BASE_DIR / "db/taskncoffee.db"
|
|
|
|
|
|
class ApiV1Prefix(BaseModel):
|
|
prefix: str = "/v1"
|
|
auth: str = "/auth"
|
|
users: str = "/users"
|
|
|
|
@property
|
|
def login_url(self) -> str:
|
|
return f"{self.prefix}{self.auth}"
|
|
|
|
|
|
class ApiPrefix(BaseModel):
|
|
prefix: str = "/api"
|
|
v1: ApiV1Prefix = ApiV1Prefix()
|
|
|
|
@property
|
|
def v1_login_url(self) -> str:
|
|
return f"{self.prefix}{self.v1.login_url}"
|
|
|
|
|
|
class DbSettings(BaseModel):
|
|
url: str = f"sqlite+aiosqlite:///{DB_PATH}"
|
|
|
|
|
|
class AccessToken(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env", env_file_encoding="utf-8", env_prefix="ACCESS_TOKEN_"
|
|
)
|
|
expire_minutes: int
|
|
secret_key: str
|
|
algorithm: str = "HS256"
|
|
token_type: str = "bearer" # noqa: S105
|
|
|
|
|
|
class RefreshToken(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env", env_file_encoding="utf-8", env_prefix="REFRESH_TOKEN_"
|
|
)
|
|
secret_key: str
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
api: ApiPrefix = ApiPrefix()
|
|
db: DbSettings = DbSettings()
|
|
access_token: AccessToken = AccessToken() # type: ignore
|
|
refresh_token: RefreshToken = RefreshToken() # type: ignore
|
|
|
|
|
|
settings = Settings()
|