Signing key checks

This commit is contained in:
2025-10-07 00:23:29 -04:00
parent 7f5cf23fd2
commit 6268ea67b0

View File

@@ -1,7 +1,6 @@
import os import os
from pathlib import Path from pathlib import Path
import tomllib import tomllib
import mimetypes
addr: str = "127.0.0.1" addr: str = "127.0.0.1"
port: int = 5000 port: int = 5000
@@ -39,6 +38,7 @@ def _load_toml(path: Path) -> dict:
def _read_signing_key_from_path(path_value) -> str | None: def _read_signing_key_from_path(path_value) -> str | None:
p = Path(path_value) p = Path(path_value)
if not p.exists(): if not p.exists():
_fatal(f"signing_key_path {p} does not exist") _fatal(f"signing_key_path {p} does not exist")
try: try:
@@ -52,10 +52,6 @@ def _validate_cat_path(cat_path: str) -> Path:
if not p.exists(): if not p.exists():
_fatal(f"Cat photo at {p} does not exist") _fatal(f"Cat photo at {p} does not exist")
mtype, _ = mimetypes.guess_type(str(p))
if mtype is None or not mtype.startswith("image/"):
_warn(f"Cat file {p} does not look like an image (mimetype={mtype})")
return p return p
@@ -86,12 +82,16 @@ def _apply_config(cfg: dict) -> None:
signing_key = str(cfg["signing_key"]).strip() signing_key = str(cfg["signing_key"]).strip()
elif "signing_key_path" in cfg: elif "signing_key_path" in cfg:
sk = _read_signing_key_from_path(cfg["signing_key_path"]) sk = _read_signing_key_from_path(cfg["signing_key_path"])
if sk: if sk:
signing_key = sk signing_key = sk
else:
_fatal(f"{cfg["signing_key_path"]} does not have a signing key.")
else: else:
_fatal( _fatal(
"`signing_key` is not in configuration. " "A signing key is not present in the configuration. "
"A signing key can be generated using `cmd/generate_key.py`." "A key can be generated using `python3 -m vona.utils.makekey`."
) )
if "cat" in cfg: if "cat" in cfg: