chore: Ran cargo fmt on all code

This commit is contained in:
2025-01-24 10:45:30 -05:00
parent d6c8650d52
commit 21258cf1af
23 changed files with 72 additions and 55 deletions

View File

@@ -3,7 +3,10 @@ use std::sync::Arc;
use crate::{
config::{SshConfigManager, SshCredentials, SshOPNSenseShell},
error::Error,
modules::{caddy::CaddyConfig, dhcp::DhcpConfig, dns::DnsConfig, load_balancer::LoadBalancerConfig, tftp::TftpConfig},
modules::{
caddy::CaddyConfig, dhcp::DhcpConfig, dns::DnsConfig, load_balancer::LoadBalancerConfig,
tftp::TftpConfig,
},
};
use log::{info, trace};
use opnsense_config_xml::OPNsense;
@@ -50,7 +53,7 @@ impl Config {
LoadBalancerConfig::new(&mut self.opnsense, self.shell.clone())
}
pub async fn upload_files(&self, source: &str, destination: &str) -> Result<String, Error> {
pub async fn upload_files(&self, source: &str, destination: &str) -> Result<String, Error> {
self.shell.upload_folder(source, destination).await
}

View File

@@ -1,8 +1,8 @@
mod ssh;
mod local_file;
mod ssh;
use async_trait::async_trait;
pub use ssh::*;
pub use local_file::*;
pub use ssh::*;
use crate::Error;

View File

@@ -1,6 +1,6 @@
mod config;
mod manager;
mod shell;
pub use manager::*;
pub use config::*;
pub use manager::*;
pub use shell::*;

View File

@@ -27,12 +27,15 @@ impl<'a> CaddyConfig<'a> {
{
match &mut self.opnsense.pischem.as_mut() {
Some(pischem) => f(&mut pischem.caddy),
None => unimplemented!("Accessing caddy config is not supported when not available yet"),
None => {
unimplemented!("Accessing caddy config is not supported when not available yet")
}
}
}
pub fn enable(&mut self, enabled: bool) {
self.with_caddy(|caddy| {caddy.general.enabled = enabled as u8;
self.with_caddy(|caddy| {
caddy.general.enabled = enabled as u8;
caddy.general.http_port = Some(8080);
caddy.general.https_port = Some(8443);
});
@@ -40,8 +43,12 @@ impl<'a> CaddyConfig<'a> {
pub async fn reload_restart(&self) -> Result<(), Error> {
self.opnsense_shell.exec("configctl caddy stop").await?;
self.opnsense_shell.exec("configctl template reload OPNsense/Caddy").await?;
self.opnsense_shell.exec("configctl template reload OPNsense/Caddy/rc.conf.d").await?;
self.opnsense_shell
.exec("configctl template reload OPNsense/Caddy")
.await?;
self.opnsense_shell
.exec("configctl template reload OPNsense/Caddy/rc.conf.d")
.await?;
self.opnsense_shell.exec("configctl caddy validate").await?;
self.opnsense_shell.exec("configctl caddy start").await?;
Ok(())

View File

@@ -1,6 +1,5 @@
use opnsense_config_xml::{Host, OPNsense};
pub struct DnsConfig<'a> {
opnsense: &'a mut OPNsense,
}

View File

@@ -59,15 +59,25 @@ impl<'a> LoadBalancerConfig<'a> {
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("/usr/local/sbin/haproxy -c -f /usr/local/etc/haproxy.conf.staging").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("/usr/local/sbin/haproxy -c -f /usr/local/etc/haproxy.conf.staging")
.await?;
// This script copies the staging config to production config. I am not 100% sure it is
// required in the context
self.opnsense_shell.exec("/usr/local/opnsense/scripts/OPNsense/HAProxy/setup.sh deploy").await?;
self.opnsense_shell
.exec("/usr/local/opnsense/scripts/OPNsense/HAProxy/setup.sh deploy")
.await?;
self.opnsense_shell.exec("configctl haproxy configtest").await?;
self.opnsense_shell
.exec("configctl haproxy configtest")
.await?;
self.opnsense_shell.exec("configctl haproxy start").await?;
Ok(())
}

View File

@@ -1,5 +1,5 @@
pub mod caddy;
pub mod dhcp;
pub mod dns;
pub mod load_balancer;
pub mod tftp;
pub mod caddy;

View File

@@ -41,7 +41,9 @@ impl<'a> TftpConfig<'a> {
pub async fn reload_restart(&self) -> Result<(), Error> {
self.opnsense_shell.exec("configctl tftp stop").await?;
self.opnsense_shell.exec("configctl template reload OPNsense/Tftp").await?;
self.opnsense_shell
.exec("configctl template reload OPNsense/Tftp")
.await?;
self.opnsense_shell.exec("configctl tftp start").await?;
Ok(())
}