| 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 |
|
| 26 |
|
| 27 |
#[serde(default)] |
| 28 |
pub step_timeout_secs: Option<u64>, |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#[serde(default)] |
| 34 |
pub notarize_backoff_secs: Option<u64>, |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#[serde(default = "default_true")] |
| 41 |
pub pin_release_sha: bool, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
#[serde(default = "default_deploy_installer")] |
| 56 |
pub deploy_installer: String, |
| 57 |
} |
| 58 |
|
| 59 |
fn default_true() -> bool { |
| 60 |
true |
| 61 |
} |
| 62 |
|
| 63 |
fn default_deploy_installer() -> String { |
| 64 |
"sudo /usr/local/lib/bento/install-service.sh".into() |
| 65 |
} |
| 66 |
|
| 67 |
fn default_logs_root() -> PathBuf { |
| 68 |
PathBuf::from("/srv/bento/logs") |
| 69 |
} |
| 70 |
|
| 71 |
impl Config { |
| 72 |
pub fn load() -> Result<Self> { |
| 73 |
let path = std::env::var("BENTO_CONFIG").unwrap_or_else(|_| "bento-daemon.toml".into()); |
| 74 |
let raw = std::fs::read_to_string(&path) |
| 75 |
.with_context(|| format!("reading daemon config at {path}"))?; |
| 76 |
Ok(toml::from_str(&raw)?) |
| 77 |
} |
| 78 |
|
| 79 |
#[cfg(test)] |
| 80 |
pub fn for_tests(root: &std::path::Path) -> Self { |
| 81 |
Self { |
| 82 |
listen: "127.0.0.1:0".into(), |
| 83 |
db_path: root.join("bento.db"), |
| 84 |
topology_path: root.join("bento.toml"), |
| 85 |
secrets_root: root.join("secrets"), |
| 86 |
dist_root: root.join("dist"), |
| 87 |
logs_root: root.join("logs"), |
| 88 |
step_timeout_secs: None, |
| 89 |
notarize_backoff_secs: None, |
| 90 |
|
| 91 |
|
| 92 |
pin_release_sha: false, |
| 93 |
deploy_installer: default_deploy_installer(), |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|