Standardize on ~/.config/shepherd/config.toml
This commit is contained in:
parent
51b81c2a5b
commit
65292566f2
4 changed files with 44 additions and 6 deletions
|
|
@ -86,8 +86,8 @@ max_run_seconds = 3600 # 1 hour
|
||||||
use shepherd_config::{load_config, parse_config, Policy};
|
use shepherd_config::{load_config, parse_config, Policy};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
// Load from file
|
// Load from file (typically ~/.config/shepherd/config.toml)
|
||||||
let policy = load_config("/etc/shepherdd/config.toml")?;
|
let policy = load_config("config.toml")?;
|
||||||
|
|
||||||
// Parse from string
|
// Parse from string
|
||||||
let toml_content = std::fs::read_to_string("config.toml")?;
|
let toml_content = std::fs::read_to_string("config.toml")?;
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,37 @@ pub fn socket_dir() -> PathBuf {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configuration subdirectory name (uses "shepherd" not "shepherdd")
|
||||||
|
const CONFIG_APP_DIR: &str = "shepherd";
|
||||||
|
|
||||||
|
/// Configuration filename
|
||||||
|
const CONFIG_FILENAME: &str = "config.toml";
|
||||||
|
|
||||||
|
/// Get the default configuration file path.
|
||||||
|
///
|
||||||
|
/// Returns `$XDG_CONFIG_HOME/shepherd/config.toml` or `~/.config/shepherd/config.toml`
|
||||||
|
pub fn default_config_path() -> PathBuf {
|
||||||
|
// Try XDG_CONFIG_HOME first
|
||||||
|
if let Ok(config_home) = std::env::var("XDG_CONFIG_HOME") {
|
||||||
|
return PathBuf::from(config_home)
|
||||||
|
.join(CONFIG_APP_DIR)
|
||||||
|
.join(CONFIG_FILENAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to ~/.config/shepherd/config.toml
|
||||||
|
if let Ok(home) = std::env::var("HOME") {
|
||||||
|
return PathBuf::from(home)
|
||||||
|
.join(".config")
|
||||||
|
.join(CONFIG_APP_DIR)
|
||||||
|
.join(CONFIG_FILENAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Last resort (unlikely to be valid, but provides a fallback)
|
||||||
|
PathBuf::from("/etc")
|
||||||
|
.join(CONFIG_APP_DIR)
|
||||||
|
.join(CONFIG_FILENAME)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -145,4 +176,11 @@ mod tests {
|
||||||
let dir = socket_dir();
|
let dir = socket_dir();
|
||||||
assert_eq!(socket.parent().unwrap(), dir);
|
assert_eq!(socket.parent().unwrap(), dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn config_path_contains_shepherd() {
|
||||||
|
let path = default_config_path();
|
||||||
|
assert!(path.to_string_lossy().contains("shepherd"));
|
||||||
|
assert!(path.to_string_lossy().ends_with("config.toml"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ shepherdd --log-level debug
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
|--------|---------|-------------|
|
|--------|---------|-------------|
|
||||||
| `-c, --config` | `/etc/shepherdd/config.toml` | Configuration file path |
|
| `-c, --config` | `~/.config/shepherd/config.toml` | Configuration file path |
|
||||||
| `-s, --socket` | From config | IPC socket path |
|
| `-s, --socket` | From config | IPC socket path |
|
||||||
| `-d, --data-dir` | From config | Data directory |
|
| `-d, --data-dir` | From config | Data directory |
|
||||||
| `-l, --log-level` | `info` | Log verbosity |
|
| `-l, --log-level` | `info` | Log verbosity |
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ use shepherd_host_api::{HostAdapter, HostEvent, StopMode as HostStopMode, Volume
|
||||||
use shepherd_host_linux::{LinuxHost, LinuxVolumeController};
|
use shepherd_host_linux::{LinuxHost, LinuxVolumeController};
|
||||||
use shepherd_ipc::{IpcServer, ServerMessage};
|
use shepherd_ipc::{IpcServer, ServerMessage};
|
||||||
use shepherd_store::{AuditEvent, AuditEventType, SqliteStore, Store};
|
use shepherd_store::{AuditEvent, AuditEventType, SqliteStore, Store};
|
||||||
use shepherd_util::{ClientId, MonotonicInstant, RateLimiter};
|
use shepherd_util::{default_config_path, ClientId, MonotonicInstant, RateLimiter};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
@ -35,8 +35,8 @@ use tracing_subscriber::EnvFilter;
|
||||||
#[command(name = "shepherdd")]
|
#[command(name = "shepherdd")]
|
||||||
#[command(about = "Policy enforcement service for child-focused computing", long_about = None)]
|
#[command(about = "Policy enforcement service for child-focused computing", long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Configuration file path
|
/// Configuration file path (default: ~/.config/shepherd/config.toml)
|
||||||
#[arg(short, long, default_value = "/etc/shepherdd/config.toml")]
|
#[arg(short, long, default_value_os_t = default_config_path())]
|
||||||
config: PathBuf,
|
config: PathBuf,
|
||||||
|
|
||||||
/// Socket path override (or set SHEPHERD_SOCKET env var)
|
/// Socket path override (or set SHEPHERD_SOCKET env var)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue