Using env vars for configuration instead of toml config
This commit is contained in:
parent
f7ab0697a5
commit
64edeb8d40
7 changed files with 33 additions and 33 deletions
|
@ -3,4 +3,4 @@ from redis import asyncio as aioredis
|
|||
|
||||
from pssecret.settings import settings
|
||||
|
||||
redis = aioredis.from_url(settings.redis.url)
|
||||
redis = aioredis.from_url(str(settings.redis_url))
|
||||
|
|
|
@ -1,26 +1,9 @@
|
|||
import os
|
||||
import tomllib
|
||||
from pydantic import RedisDsn
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
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
|
||||
class Settings(BaseSettings):
|
||||
redis_url: RedisDsn = RedisDsn("redis://localhost")
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue