Keep It Simple Stupid. Started using the CherryPy server and made classes from the parts.
This commit is contained in:
28
kiss/toml-manager/config/config_loader.py
Normal file
28
kiss/toml-manager/config/config_loader.py
Normal file
@ -0,0 +1,28 @@
|
||||
import tomllib
|
||||
import logging
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
"server": {
|
||||
"host": "0.0.0.0",
|
||||
"port": 8000,
|
||||
},
|
||||
"wireguard": {
|
||||
"config_file": "/etc/wireguard/wg0.conf",
|
||||
},
|
||||
"logging": {
|
||||
"log_file": None,
|
||||
"debug": False,
|
||||
}
|
||||
}
|
||||
|
||||
def load_config(config_file: str = "config.toml") -> dict:
|
||||
try:
|
||||
with open(config_file, "rb") as f:
|
||||
config = tomllib.load(f)
|
||||
return {**DEFAULT_CONFIG, **config}
|
||||
except FileNotFoundError:
|
||||
logging.warning(f"Config file {config_file} not found. Using default configuration.")
|
||||
return DEFAULT_CONFIG
|
||||
except tomllib.TOMLDecodeError as e:
|
||||
logging.error(f"Error parsing config file: {e}")
|
||||
exit(1)
|
Reference in New Issue
Block a user