26 lines
601 B
Python
26 lines
601 B
Python
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"
|
|
) 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()
|