pssecret-server/pssecret/settings.py

27 lines
601 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("PSSECRET_CONF_FILE", "/etc/pssecret/pssecret.toml"), "rb"
2022-12-17 08:53:50 +00:00
) 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()