Files
malenia-backend/config.py

49 lines
1.4 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)")
pally_shop_id: str = Field()
pally_token: str = Field()
minimal_deposit: int = Field()
@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