//! Daemon-local config (`bento-daemon.toml`) — paths and listen address that //! belong to the machine bentod runs on, not to the build matrix (which lives //! in the separate topology file, see [`crate::topology`]). use anyhow::{Context, Result}; use serde::Deserialize; use std::path::PathBuf; #[derive(Debug, Clone, Deserialize)] pub struct Config { pub listen: String, pub db_path: PathBuf, pub topology_path: PathBuf, /// Root of the Syncthing private layer (`~/Code/_private`); the `secret()` /// host function reads credential files relative to here. Never logged. pub secrets_root: PathBuf, /// Where collected artifacts land (`///`). pub dist_root: PathBuf, /// Root for per-step run logs /// (`////.log`). #[serde(default = "default_logs_root")] pub logs_root: PathBuf, } fn default_logs_root() -> PathBuf { PathBuf::from("/srv/bento/logs") } impl Config { pub fn load() -> Result { let path = std::env::var("BENTO_CONFIG").unwrap_or_else(|_| "bento-daemon.toml".into()); let raw = std::fs::read_to_string(&path) .with_context(|| format!("reading daemon config at {path}"))?; Ok(toml::from_str(&raw)?) } #[cfg(test)] pub fn for_tests(root: &std::path::Path) -> Self { Self { listen: "127.0.0.1:0".into(), db_path: root.join("bento.db"), topology_path: root.join("bento.toml"), secrets_root: root.join("secrets"), dist_root: root.join("dist"), logs_root: root.join("logs"), } } }