58 lines
1.7 KiB
Python
58 lines
1.7 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()
|
|
|
|
remnawave_base_url: str = Field()
|
|
remnawave_token: str = Field()
|
|
remnawave_default_squads_raw: str = Field(alias="REMNAWAVE_DEFAULT_SQUADS_UUIDS")
|
|
|
|
minimal_deposit: int = Field()
|
|
|
|
@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()
|
|
|
|
|
|
cfg = Settings() # type: ignore
|