pssecret-server/src/rectes/settings.py

28 lines
596 B
Python
Raw Normal View History

2022-12-17 08:53:50 +00:00
import os
import tomllib
class Settings:
def __init__(self, data: dict = None):
if data:
self._data = data
else:
with open(
os.getenv("RECTES_CONF_FILE", "/etc/rectes/rectes.toml"), "rb"
) as f:
self._data = tomllib.load(f)
def __getattr__(self, item):
try:
value = self._data[item]
except KeyError:
raise AttributeError
if isinstance(value, dict):
return Settings(data=value)
else:
return value
settings = Settings()