57 lines
1.4 KiB
Python
57 lines
1.4 KiB
Python
import toml
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class DatabaseConfig:
|
|
_host: str
|
|
|
|
def __init__(self, config: dict):
|
|
self._host = config["HOST"]
|
|
|
|
@property
|
|
def host(self) -> str:
|
|
return self._host
|
|
|
|
|
|
@dataclass
|
|
class KeePassConfig:
|
|
_path: str
|
|
_db_credentials_name: str
|
|
_db_credentials_group: str
|
|
|
|
def __init__(self, config: dict):
|
|
self._path = config["PATH"]
|
|
self._db_credentials_name = config["DB_CREDENTIALS_NAME"]
|
|
self._db_credentials_group = config["DB_CREDENTIALS_GROUP"]
|
|
|
|
@property
|
|
def path(self) -> str:
|
|
return self._path
|
|
|
|
@property
|
|
def db_credentials_name(self) -> str:
|
|
return self._db_credentials_name
|
|
|
|
@property
|
|
def db_credentials_group(self) -> str:
|
|
return self._db_credentials_group
|
|
|
|
@dataclass
|
|
class Config:
|
|
_config: dict
|
|
_kee_pass_config: KeePassConfig
|
|
_database_config: DatabaseConfig
|
|
def __init__(self):
|
|
with open('config.toml', 'r') as f:
|
|
self._config = toml.load(f)
|
|
self._kee_pass_config = KeePassConfig(self._config['keepass'])
|
|
self._database_config = DatabaseConfig(self._config['database'])
|
|
|
|
@property
|
|
def kee_pass(self) -> KeePassConfig:
|
|
return self._kee_pass_config
|
|
|
|
@property
|
|
def database(self) -> DatabaseConfig:
|
|
return self._database_config |