use std::fs;
use anyhow::{Result, anyhow};
use super::UnlockBackend;
const CREDENTIAL_NAME: &str = "moshpit-agent-vault-key";
pub(crate) struct SystemdCredsBackend;
impl UnlockBackend for SystemdCredsBackend {
fn retrieve_passphrase(&self) -> Result<String> {
let creds_dir = std::env::var("CREDENTIALS_DIRECTORY")
.map_err(|_| anyhow!("CREDENTIALS_DIRECTORY not set — not running under systemd"))?;
let path = std::path::Path::new(&creds_dir).join(CREDENTIAL_NAME);
let passphrase = fs::read_to_string(&path)
.map_err(|e| anyhow!("failed to read systemd credential {}: {e}", path.display()))?;
Ok(passphrase.trim_end_matches(['\n', '\r']).to_string())
}
fn name(&self) -> &'static str {
"systemd-creds"
}
}