forked from NationTech/harmony
fix(load-balancer): implement missing HAProxy reload and sanitize output handling
Implement the `reload_restart` method in `LoadBalancerConfig` to ensure proper HAProxy configuration management. Additionally, enhance SSH command execution by sanitizing and logging outputs effectively. This ensures robust handling of HAProxy configurations and improves debugging capabilities through trace-level logs.
This commit is contained in:
@@ -6,7 +6,7 @@ use std::{
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use log::{debug, info};
|
||||
use log::{debug, info, trace};
|
||||
use russh::{
|
||||
client::{Config, Handler, Msg},
|
||||
Channel,
|
||||
@@ -205,5 +205,7 @@ async fn wait_for_completion(channel: &mut Channel<Msg>) -> Result<String, Error
|
||||
}
|
||||
}
|
||||
|
||||
Ok(String::from_utf8(output).unwrap_or_default())
|
||||
let output = String::from_utf8(output).expect("Output should be UTF-8 compatible");
|
||||
trace!("{output}");
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use opnsense_config_xml::{
|
||||
Frontend, HAProxy, HAProxyBackend, HAProxyHealthCheck, HAProxyServer, OPNsense,
|
||||
};
|
||||
|
||||
use crate::config::OPNsenseShell;
|
||||
use crate::{config::OPNsenseShell, Error};
|
||||
|
||||
pub struct LoadBalancerConfig<'a> {
|
||||
opnsense: &'a mut OPNsense,
|
||||
@@ -56,4 +56,13 @@ impl<'a> LoadBalancerConfig<'a> {
|
||||
pub fn add_servers(&mut self, mut servers: Vec<HAProxyServer>) {
|
||||
self.with_haproxy(|haproxy| haproxy.servers.servers.append(&mut servers));
|
||||
}
|
||||
|
||||
pub async fn reload_restart(&self) -> Result<(), Error> {
|
||||
self.opnsense_shell.exec("configctl haproxy stop").await?;
|
||||
self.opnsense_shell.exec("configctl template reload OPNsense/HAProxy").await?;
|
||||
self.opnsense_shell.exec("configctl template reload OPNsense/Syslog").await?;
|
||||
self.opnsense_shell.exec("configctl haproxy configtest").await?;
|
||||
self.opnsense_shell.exec("configctl haproxy start").await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user