chore: Reorganize file tree for easier onboarding. Rust project now at the root for simple git clone && cargo run
This commit is contained in:
30
opnsense-config/src/config/manager/local_file.rs
Normal file
30
opnsense-config/src/config/manager/local_file.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use crate::config::manager::ConfigManager;
|
||||
use crate::error::Error;
|
||||
use async_trait::async_trait;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LocalFileConfigManager {
|
||||
file_path: String,
|
||||
}
|
||||
|
||||
impl LocalFileConfigManager {
|
||||
pub fn new(file_path: String) -> Self {
|
||||
Self { file_path }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ConfigManager for LocalFileConfigManager {
|
||||
async fn load_as_str(&self) -> Result<String, Error> {
|
||||
Ok(fs::read_to_string(&self.file_path)?)
|
||||
}
|
||||
|
||||
async fn save_config(&self, content: &str) -> Result<(), Error> {
|
||||
Ok(fs::write(&self.file_path, content)?)
|
||||
}
|
||||
|
||||
async fn apply_new_config(&self, content: &str) -> Result<(), Error> {
|
||||
self.save_config(content).await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user