Keep It Simple Stupid. Started using the CherryPy server and made classes from the parts.

This commit is contained in:
kalzu rekku
2024-10-22 22:06:19 +03:00
parent 6db5290cca
commit e620c28648
12 changed files with 600 additions and 0 deletions

View 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)