Skip to main content

agentshield/config/
mod.rs

1use std::path::Path;
2
3use serde::{Deserialize, Serialize};
4
5use crate::error::Result;
6use crate::rules::policy::Policy;
7
8/// Top-level configuration from `.agentshield.toml`.
9#[derive(Debug, Clone, Default, Serialize, Deserialize)]
10pub struct Config {
11    #[serde(default)]
12    pub policy: Policy,
13}
14
15impl Config {
16    /// Load config from a TOML file. Returns default if file doesn't exist.
17    pub fn load(path: &Path) -> Result<Self> {
18        if !path.exists() {
19            return Ok(Self::default());
20        }
21        let content = std::fs::read_to_string(path)?;
22        let config: Config = toml::from_str(&content)?;
23        Ok(config)
24    }
25
26    /// Generate a starter config file.
27    pub fn starter_toml() -> &'static str {
28        r#"# AgentShield configuration
29# See https://github.com/limaronaldo/agentshield for documentation.
30
31[policy]
32# Minimum severity to fail the scan (info, low, medium, high, critical).
33fail_on = "high"
34
35# Rule IDs to ignore entirely.
36# ignore_rules = ["SHIELD-008"]
37
38# Per-rule severity overrides.
39# [policy.overrides]
40# "SHIELD-012" = "info"
41"#
42    }
43}