Skip to main content

para_audit/
config.rs

1// everything related to the PARA user-dependent configuration.
2
3use std::path::Path;
4
5use serde::{Deserialize, Serialize};
6use anyhow::Result;
7
8
9#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
10pub struct Config {
11    // to start with, let's just define the list of disallowed files
12    pub disallowed_files: Option<Vec<String>>,
13}
14
15impl Default for Config {
16    fn default() -> Self {
17        Self { disallowed_files: Some(vec![ "example_disallowed.file".to_string() ]) }
18    }
19}
20
21impl Config {
22
23    pub fn write_yaml<P: AsRef<Path>>(&self, filename: P) -> Result<()> {
24        std::fs::write(filename, yaml_serde::to_string(&self)?)?;
25        Ok(())
26    }
27
28    pub fn read_yaml<P: AsRef<Path>>(filename: P) -> Result<Config> {
29        let config = yaml_serde::from_str(&std::fs::read_to_string(filename)?)?;
30        Ok(config)
31    }
32}