Files
malenia-backend/config.py
2026-08-24 10:22:14 +07:00

81 lines
2.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")
### Internal settings ###
postgres_user: str = Field()
postgres_password: str = Field()
postgres_host: str = Field()
postgres_port: str = Field()
postgres_db: str = Field()
### Telegram ###
bot_username: str = Field()
### Remnawave ###
remnawave_base_url: str = Field()
remnawave_sub_url: str = Field()
remnawave_token: str = Field()
remnawave_default_squads_raw: str = Field(alias="REMNAWAVE_DEFAULT_SQUADS_UUIDS")
### Finance ###
minimal_deposit: int = Field()
referal_bonus: int = Field(30)
#### Pally ####
pally_shop_id: str = Field()
pally_token: str = Field()
### Security related ###
private_key_fp: str = Field()
public_key_fp: str = Field()
access_token_ttl: int = Field(description="Access token TTL (minutes)")
link_code_ttl: int = Field(8, description="Link Code TTL (minutes)")
notification_scan_interval: int = Field(5, ge=1)
rw_sync_interval_minutes: int = Field(1, ge=1)
rw_sync_reconcile_interval_minutes: int = Field(60, ge=1)
min_password_length: int = Field(8)
link_code_length: int = Field(8)
password_security_threshold: int = Field(2)
@computed_field
@property
def remnawave_default_squads(self) -> list[str]:
return self.remnawave_default_squads_raw.split(",")
@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()
@computed_field
@property
def bot_url(self) -> str:
return "https://t.me/" + self.bot_username.lstrip("@")
cfg = Settings() # type: ignore