service_man/api/infrastructure/dependencies/configs.py

37 lines
1.0 KiB
Python
Raw Normal View History

2024-03-31 21:07:59 +03:00
import os
from functools import lru_cache
import yaml # type: ignore
2024-04-02 22:33:15 +03:00
from api.infrastructure.auth.jwt_settings import JwtSettings
2024-03-31 21:07:59 +03:00
from api.infrastructure.persistence.db_setings import DBSettings
from api.infrastructure.settings import Settings
def yaml_loader(file: str) -> dict[str, dict[str, str]]:
with open(file) as f:
yaml_data: dict = yaml.safe_load(f)
return yaml_data
@lru_cache
def app_settings() -> Settings:
config_data = yaml_loader(
file=os.getenv("CONFIG_PATH", "./config/api_config.yml"),
)
return Settings(
db=DBSettings(
pg_user=config_data["db"]["user"],
pg_pass=config_data["db"]["password"],
pg_host=config_data["db"]["host"],
pg_port=int(config_data["db"]["port"]),
pg_db=config_data["db"]["database"],
),
2024-04-02 22:33:15 +03:00
jwt=JwtSettings(
secret=config_data["jwt"]["secret_key"],
expires_in=int(config_data["jwt"]["expires_in"]),
algorithm=config_data["jwt"]["algorithm"],
),
2024-03-31 21:07:59 +03:00
)