brokerd: config, [gateway] socket for Mattermost approvals

This commit is contained in:
2026-09-24 04:18:04 -07:00
parent a00711e379
commit 412f80c470
4 changed files with 64 additions and 0 deletions
+19
View File
@@ -45,6 +45,14 @@ impl Default for Approvals {
}
}
/// `[gateway]`: where `gatewayd` takes approvals to post in Mattermost. Without the section,
/// Mattermost approvals are off and only `bxctl` answers. An empty path means the default.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Default)]
#[serde(deny_unknown_fields, default)]
pub struct Gateway {
pub socket: PathBuf,
}
fn default_podman() -> PathBuf {
PathBuf::from("podman")
}
@@ -129,6 +137,8 @@ pub struct Config {
pub approvals: Approvals,
#[serde(default)]
pub runner: Option<Runner>,
#[serde(default)]
pub gateway: Option<Gateway>,
}
/// The longest an approval may wait: a day, the longest `loopd` waits after a pending frame.
@@ -262,6 +272,15 @@ impl Config {
self.sockets.admin.clone()
}
}
/// `gateway.sock`, when `[gateway]` is set.
pub fn gateway_socket(&self) -> Option<PathBuf> {
let gateway = self.gateway.as_ref()?;
if gateway.socket.as_os_str().is_empty() {
Some(self.paths.home.join("run/gateway/gateway.sock"))
} else {
Some(gateway.socket.clone())
}
}
pub fn audit_dir(&self) -> PathBuf {
self.paths.home.join("audit")
}
+43
View File
@@ -0,0 +1,43 @@
//! `[gateway]` in `brokerd.toml`: absent means Mattermost approvals are off; an empty socket is
//! the default under `home` (M4b spec, section 3). Do not edit.
use std::path::PathBuf;
use brokerd::config::Config;
fn parse(text: &str) -> Config {
Config::parse(&format!("[paths]\nhome = \"/srv/bx\"\n{text}")).unwrap()
}
#[test]
fn without_the_section_approvals_stay_in_bxctl() {
let config = parse("");
assert_eq!(config.gateway, None);
assert_eq!(config.gateway_socket(), None);
}
#[test]
fn an_empty_section_or_socket_is_the_default() {
let default = Some(PathBuf::from("/srv/bx/run/gateway/gateway.sock"));
assert_eq!(parse("[gateway]\n").gateway_socket(), default);
assert_eq!(
parse("[gateway]\nsocket = \"\"\n").gateway_socket(),
default
);
}
#[test]
fn a_socket_path_is_used_as_given() {
let config = parse("[gateway]\nsocket = \"/run/bx/gw.sock\"\n");
assert_eq!(
config.gateway_socket(),
Some(PathBuf::from("/run/bx/gw.sock"))
);
}
#[test]
fn unknown_keys_are_errors() {
assert!(Config::parse("[gateway]\nsockets = \"/x\"\n").is_err());
assert!(Config::parse("[gateway]\nsocket = \"/x\"\nenabled = true\n").is_err());
assert!(Config::parse("[gatewy]\nsocket = \"/x\"\n").is_err());
}
+1
View File
@@ -41,6 +41,7 @@ impl Rig {
sockets: Sockets::default(),
approvals: Approvals { ttl_ms },
runner: None,
gateway: None,
};
Rig {
dir,