Skip to main content

vanta_config/
model.rs

1//! The typed model for `vanta.toml` and `~/.vanta/config.toml`.
2//!
3//! See `docs/05-configuration.md` and `docs/27-config-reference.md`. Unknown keys
4//! are rejected (`deny_unknown_fields`) so typos become span-accurate diagnostics.
5
6use serde::{Deserialize, Serialize};
7use std::collections::BTreeMap;
8
9/// A project manifest (`vanta.toml`) or global config (`~/.vanta/config.toml`).
10/// Both share the same shape; only some tables are meaningful in each context.
11#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
12#[serde(default, deny_unknown_fields)]
13pub struct Manifest {
14    /// Manifest format version marker.
15    pub version: Option<u32>,
16    /// The declared tools.
17    pub tools: BTreeMap<String, ToolSpec>,
18    /// Environment variables injected when active (a trusted section).
19    pub env: BTreeMap<String, EnvValue>,
20    /// The optional task runner.
21    pub tasks: BTreeMap<String, Task>,
22    /// Behavioral settings.
23    pub settings: Settings,
24    /// Named registries that overlay the official one.
25    pub registries: BTreeMap<String, Registry>,
26    /// Workspace declaration (root manifest only).
27    pub workspace: Option<Workspace>,
28}
29
30/// A tool entry: either a bare version string or a detailed table.
31#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ToolSpec {
34    Version(String),
35    Detailed(ToolDetail),
36}
37
38impl ToolSpec {
39    /// The version request string for this tool.
40    pub fn version(&self) -> &str {
41        match self {
42            ToolSpec::Version(v) => v,
43            ToolSpec::Detailed(d) => &d.version,
44        }
45    }
46}
47
48/// The inline-table form of a tool entry.
49#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
50#[serde(deny_unknown_fields)]
51pub struct ToolDetail {
52    pub version: String,
53    #[serde(default)]
54    pub channel: Option<String>,
55    #[serde(default)]
56    pub registry: Option<String>,
57    #[serde(default)]
58    pub provider: Option<String>,
59    #[serde(default)]
60    pub os: Option<Vec<String>>,
61    #[serde(default)]
62    pub optional: Option<bool>,
63}
64
65/// An `[env]` value: a plain string or a PATH edit table.
66#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum EnvValue {
69    Plain(String),
70    Path(PathEdit),
71}
72
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
74#[serde(deny_unknown_fields)]
75pub struct PathEdit {
76    #[serde(default)]
77    pub prepend: Vec<String>,
78    #[serde(default)]
79    pub append: Vec<String>,
80}
81
82/// A `[tasks]` entry: a command string or a detailed table.
83#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum Task {
86    Command(String),
87    Detailed(TaskDetail),
88}
89
90#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
91#[serde(deny_unknown_fields)]
92pub struct TaskDetail {
93    pub run: String,
94    #[serde(default)]
95    pub description: Option<String>,
96    #[serde(default)]
97    pub depends: Vec<String>,
98    #[serde(default)]
99    pub cwd: Option<String>,
100}
101
102/// Behavioral settings. All optional so merge is "higher layer wins if set".
103#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
104#[serde(default, deny_unknown_fields)]
105pub struct Settings {
106    pub auto_install: Option<bool>,
107    pub verify: Option<String>,
108    pub jobs: Option<u32>,
109    pub link_strategy: Option<String>,
110    pub shims: Option<bool>,
111    pub offline: Option<bool>,
112    pub mirror: Option<String>,
113    pub targets: Option<Vec<String>>,
114    pub retain_generations: Option<u32>,
115    pub gc_keep_days: Option<u32>,
116    pub color: Option<String>,
117    pub telemetry: Option<bool>,
118    pub read_foreign_versions: Option<bool>,
119}
120
121#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
122#[serde(deny_unknown_fields)]
123pub struct Registry {
124    pub url: String,
125    #[serde(default)]
126    pub priority: Option<i32>,
127    #[serde(default)]
128    pub auth: Option<String>,
129    #[serde(default)]
130    pub public_key: Option<String>,
131}
132
133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
134#[serde(deny_unknown_fields)]
135pub struct Workspace {
136    pub members: Vec<String>,
137    #[serde(default)]
138    pub inherit: Option<bool>,
139}