Files
CTF-tool/src/ctf/config.py
venus 75614f6a21 refactored the cli and forensics codebases as classes and into seperate
folders for readability and consistent API access
2026-07-19 03:50:06 -05:00

39 lines
1.1 KiB
Python

# src/ctf/config.py
# {{{ imports
import toml
import os
from pathlib import Path
# }}}
# {{{ Config
class Config:
"""Manages CTF challenge configuration loading and persistence."""
def __init__(self, path: str | Path | None = None):
if path is None:
# Check environment variable first, then fallback to hardcoded path
path = os.environ.get("CTF_CONFIG_PATH", "/home/venus/code/ctf/config.toml")
self.path = Path(path)
self.data = self._load()
def _load(self) -> dict:
if self.path.exists():
try:
return toml.load(self.path)
except Exception:
return {}
return {}
def save(self, data: dict):
self.data = data
self.path.parent.mkdir(parents=True, exist_ok=True)
with open(self.path, "w") as f:
toml.dump(self.data, f)
# }}}
# {{{ exports
# Load config instance to expose default values
_cfg = Config()
competition = _cfg.data.get("Competition", {})
enviroment = _cfg.data.get("Enviroment", {})
# }}}