The previous implementation blindly added HAProxy components without checking for existing configurations on the same port, which caused duplicate entries and errors when a service was updated. This commit refactors the logic to a robust "remove-then-add" strategy. The configure_service method now finds and removes any existing frontend and its dependent components (backend, servers, health check) before adding the new, complete service definition. This change makes the process fully idempotent, preventing configuration drift and ensuring a predictable state. Co-authored-by: Ian Letourneau <letourneau.ian@gmail.com> Reviewed-on: #129
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
mod ssh;
|
|
use crate::Error;
|
|
use async_trait::async_trait;
|
|
pub use ssh::*;
|
|
|
|
#[async_trait]
|
|
pub trait OPNsenseShell: std::fmt::Debug + Send + Sync {
|
|
async fn exec(&self, command: &str) -> Result<String, Error>;
|
|
async fn write_content_to_temp_file(&self, content: &str) -> Result<String, Error>;
|
|
async fn write_content_to_file(&self, content: &str, filename: &str) -> Result<String, Error>;
|
|
async fn upload_folder(&self, source: &str, destination: &str) -> Result<String, Error>;
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[derive(Debug)]
|
|
pub struct DummyOPNSenseShell;
|
|
|
|
#[cfg(test)]
|
|
#[async_trait]
|
|
impl OPNsenseShell for DummyOPNSenseShell {
|
|
async fn exec(&self, _command: &str) -> Result<String, Error> {
|
|
unimplemented!("This is a dummy implementation");
|
|
}
|
|
async fn write_content_to_temp_file(&self, _content: &str) -> Result<String, Error> {
|
|
unimplemented!("This is a dummy implementation");
|
|
}
|
|
|
|
async fn write_content_to_file(
|
|
&self,
|
|
_content: &str,
|
|
_filename: &str,
|
|
) -> Result<String, Error> {
|
|
unimplemented!("This is a dummy implementation");
|
|
}
|
|
async fn upload_folder(&self, _source: &str, _destination: &str) -> Result<String, Error> {
|
|
unimplemented!("This is a dummy implementation");
|
|
}
|
|
}
|