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(
|
2024-12-25 11:40:57 +00:00
|
|
|
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()
|