Files
malenia-backend/config.py
hexdev 9187fbb970 feat(auth): implement JWT TTL and expiration
added access_token_ttl setting
fixed public and private key mismatch while decoding jwt
decode_jwt now returns None on expired tokens instead of raising exc
generate_pair converts sub to string and uses dynamic expiration
2026-07-24 12:59:41 +07:00

44 lines
1.3 KiB
Python

import os
from pydantic import Field, ValidationError, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env")
postgres_user: str = Field()
postgres_password: str = Field()
postgres_host: str = Field()
postgres_port: str = Field()
postgres_db: str = Field()
private_key_fp: str = Field()
public_key_fp: str = Field()
access_token_ttl: int = Field(description="Access token TTL (minutes)")
@computed_field
@property
def db_url(self) -> str:
return f"postgresql+asyncpg://{self.postgres_user}:{self.postgres_password}@{self.postgres_host}:{self.postgres_port}/{self.postgres_db}"
@computed_field
@property
def private_key(self) -> bytes:
if not os.path.isfile(self.private_key_fp):
raise ValidationError("Private key is not found")
with open(self.private_key_fp, "rb") as f:
return f.read()
@computed_field
@property
def public_key(self) -> bytes:
if not os.path.isfile(self.public_key_fp):
raise ValidationError("Public key is not found")
with open(self.public_key_fp, "rb") as f:
return f.read()
cfg = Settings() # type: ignore