Skip to main content

agent_vault/core/
config.rs

1use std::path::Path;
2
3use serde::{Deserialize, Serialize};
4
5use crate::error::VaultError;
6
7#[derive(Debug, Serialize, Deserialize)]
8pub struct Config {
9    pub version: u32,
10    pub encryption: EncryptionConfig,
11}
12
13#[derive(Debug, Serialize, Deserialize)]
14pub struct EncryptionConfig {
15    pub format: String,
16}
17
18impl Config {
19    pub fn new() -> Self {
20        Self {
21            version: 1,
22            encryption: EncryptionConfig {
23                format: "age".to_string(),
24            },
25        }
26    }
27
28    pub fn load(path: &Path) -> Result<Self, VaultError> {
29        let contents = std::fs::read_to_string(path)?;
30        let config: Config = serde_yaml::from_str(&contents)?;
31        Ok(config)
32    }
33
34    pub fn save(&self, path: &Path) -> Result<(), VaultError> {
35        let yaml = serde_yaml::to_string(self)?;
36        std::fs::write(path, yaml)?;
37        Ok(())
38    }
39}