| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
use anyhow::{Context, Result}; |
| 6 |
use serde::Deserialize; |
| 7 |
use std::path::PathBuf; |
| 8 |
|
| 9 |
#[derive(Debug, Clone, Deserialize)] |
| 10 |
pub struct Config { |
| 11 |
pub listen: String, |
| 12 |
pub db_path: PathBuf, |
| 13 |
pub topology_path: PathBuf, |
| 14 |
|
| 15 |
|
| 16 |
pub secrets_root: PathBuf, |
| 17 |
|
| 18 |
pub dist_root: PathBuf, |
| 19 |
|
| 20 |
|
| 21 |
#[serde(default = "default_logs_root")] |
| 22 |
pub logs_root: PathBuf, |
| 23 |
} |
| 24 |
|
| 25 |
fn default_logs_root() -> PathBuf { |
| 26 |
PathBuf::from("/srv/bento/logs") |
| 27 |
} |
| 28 |
|
| 29 |
impl Config { |
| 30 |
pub fn load() -> Result<Self> { |
| 31 |
let path = std::env::var("BENTO_CONFIG").unwrap_or_else(|_| "bento-daemon.toml".into()); |
| 32 |
let raw = std::fs::read_to_string(&path) |
| 33 |
.with_context(|| format!("reading daemon config at {path}"))?; |
| 34 |
Ok(toml::from_str(&raw)?) |
| 35 |
} |
| 36 |
|
| 37 |
#[cfg(test)] |
| 38 |
pub fn for_tests(root: &std::path::Path) -> Self { |
| 39 |
Self { |
| 40 |
listen: "127.0.0.1:0".into(), |
| 41 |
db_path: root.join("bento.db"), |
| 42 |
topology_path: root.join("bento.toml"), |
| 43 |
secrets_root: root.join("secrets"), |
| 44 |
dist_root: root.join("dist"), |
| 45 |
logs_root: root.join("logs"), |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|