Keepass outline
This commit is contained in:
parent
b18488a6d3
commit
162c0adf13
9 changed files with 115 additions and 3 deletions
|
|
@ -1,18 +1,26 @@
|
|||
from functools import lru_cache
|
||||
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from pydantic import BaseModel
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
from pydantic import BaseModel
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class AppConfig(BaseModel):
|
||||
host: str = "127.0.0.1"
|
||||
port: int = 8000
|
||||
reload: bool = True
|
||||
|
||||
|
||||
class KeePassConfig(BaseModel):
|
||||
file: str = "database.kdbx"
|
||||
secret: Path | str = "/run/secrets/kp_secret"
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_prefix="KARL_", env_nested_delimiter="__")
|
||||
app: AppConfig = AppConfig()
|
||||
kp: KeePassConfig = KeePassConfig()
|
||||
|
||||
@classmethod
|
||||
def from_yaml(cls, path: Path | str = "config/config.yaml") -> "Settings":
|
||||
|
|
@ -23,6 +31,7 @@ class Settings(BaseSettings):
|
|||
data = yaml.safe_load(fh) or {}
|
||||
return cls(**data)
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_settings() -> Settings:
|
||||
return Settings.from_yaml()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue