diff --git a/harmony-rs/harmony/src/domain/interpret/mod.rs b/harmony-rs/harmony/src/domain/interpret/mod.rs index 4a8faee..709ba0a 100644 --- a/harmony-rs/harmony/src/domain/interpret/mod.rs +++ b/harmony-rs/harmony/src/domain/interpret/mod.rs @@ -109,11 +109,10 @@ impl From for InterpretError { } } -impl From for InterpretError{ +impl From for InterpretError { fn from(value: kube::Error) -> Self { Self { msg: format!("InterpretError : {value}"), } } - } diff --git a/harmony-rs/harmony/src/domain/maestro/mod.rs b/harmony-rs/harmony/src/domain/maestro/mod.rs index 713b9da..959aa33 100644 --- a/harmony-rs/harmony/src/domain/maestro/mod.rs +++ b/harmony-rs/harmony/src/domain/maestro/mod.rs @@ -1,7 +1,6 @@ use derive_new::new; use log::info; - use super::{ interpret::{Interpret, InterpretError, Outcome}, inventory::Inventory, diff --git a/harmony-rs/harmony/src/infra/opnsense/dhcp.rs b/harmony-rs/harmony/src/infra/opnsense/dhcp.rs index d98516d..028921f 100644 --- a/harmony-rs/harmony/src/infra/opnsense/dhcp.rs +++ b/harmony-rs/harmony/src/infra/opnsense/dhcp.rs @@ -2,7 +2,10 @@ use async_trait::async_trait; use harmony_types::net::MacAddress; use log::debug; -use crate::{executors::ExecutorError, topology::{DHCPStaticEntry, DhcpServer, IpAddress, LogicalHost}}; +use crate::{ + executors::ExecutorError, + topology::{DHCPStaticEntry, DhcpServer, IpAddress, LogicalHost}, +}; use super::OPNSenseFirewall; @@ -27,10 +30,7 @@ impl DhcpServer for OPNSenseFirewall { Ok(()) } - async fn remove_static_mapping( - &self, - _mac: &MacAddress, - ) -> Result<(), ExecutorError> { + async fn remove_static_mapping(&self, _mac: &MacAddress) -> Result<(), ExecutorError> { todo!() } diff --git a/harmony-rs/harmony/src/infra/opnsense/dns.rs b/harmony-rs/harmony/src/infra/opnsense/dns.rs index 0026c3f..765cdb0 100644 --- a/harmony-rs/harmony/src/infra/opnsense/dns.rs +++ b/harmony-rs/harmony/src/infra/opnsense/dns.rs @@ -1,8 +1,11 @@ use crate::infra::opnsense::Host; use crate::infra::opnsense::IpAddress; use crate::infra::opnsense::LogicalHost; +use crate::{ + executors::ExecutorError, + topology::{DnsRecord, DnsServer}, +}; use async_trait::async_trait; -use crate::{executors::ExecutorError, topology::{DnsRecord, DnsServer}}; use super::OPNSenseFirewall; diff --git a/harmony-rs/harmony/src/infra/opnsense/firewall.rs b/harmony-rs/harmony/src/infra/opnsense/firewall.rs index 6e3e194..cc25f72 100644 --- a/harmony-rs/harmony/src/infra/opnsense/firewall.rs +++ b/harmony-rs/harmony/src/infra/opnsense/firewall.rs @@ -1,4 +1,7 @@ -use crate::{executors::ExecutorError, topology::{Firewall, FirewallRule, IpAddress, LogicalHost}}; +use crate::{ + executors::ExecutorError, + topology::{Firewall, FirewallRule, IpAddress, LogicalHost}, +}; use super::OPNSenseFirewall; diff --git a/harmony-rs/harmony/src/infra/opnsense/management.rs b/harmony-rs/harmony/src/infra/opnsense/management.rs index 27408c9..db2bef4 100644 --- a/harmony-rs/harmony/src/infra/opnsense/management.rs +++ b/harmony-rs/harmony/src/infra/opnsense/management.rs @@ -1,5 +1,5 @@ -use derive_new::new; use crate::hardware::ManagementInterface; +use derive_new::new; #[derive(new)] pub struct OPNSenseManagementInterface {} diff --git a/harmony-rs/harmony/src/infra/opnsense/mod.rs b/harmony-rs/harmony/src/infra/opnsense/mod.rs index 1bbea69..5d3f365 100644 --- a/harmony-rs/harmony/src/infra/opnsense/mod.rs +++ b/harmony-rs/harmony/src/infra/opnsense/mod.rs @@ -1,10 +1,10 @@ mod dhcp; mod dns; mod firewall; +mod http; mod load_balancer; mod management; mod tftp; -mod http; use std::sync::Arc; pub use management::*; @@ -27,12 +27,7 @@ impl OPNSenseFirewall { self.host.ip } - pub async fn new( - host: LogicalHost, - port: Option, - username: &str, - password: &str, - ) -> Self { + pub async fn new(host: LogicalHost, port: Option, username: &str, password: &str) -> Self { Self { opnsense_config: Arc::new(RwLock::new( opnsense_config::Config::from_credentials(host.ip, port, username, password).await, diff --git a/harmony-rs/harmony/src/lib.rs b/harmony-rs/harmony/src/lib.rs index 9e54190..e700b62 100644 --- a/harmony-rs/harmony/src/lib.rs +++ b/harmony-rs/harmony/src/lib.rs @@ -4,6 +4,4 @@ pub mod infra; pub mod modules; #[cfg(test)] -mod test { - -} +mod test {} diff --git a/harmony-rs/harmony/src/modules/k8s/deployment.rs b/harmony-rs/harmony/src/modules/k8s/deployment.rs index 49dc170..cadcffb 100644 --- a/harmony-rs/harmony/src/modules/k8s/deployment.rs +++ b/harmony-rs/harmony/src/modules/k8s/deployment.rs @@ -1,4 +1,3 @@ -use harmony_macros::yaml; use k8s_openapi::api::apps::v1::Deployment; use serde_json::json; diff --git a/harmony-rs/harmony/src/modules/k8s/mod.rs b/harmony-rs/harmony/src/modules/k8s/mod.rs index 1f1bf27..df654fb 100644 --- a/harmony-rs/harmony/src/modules/k8s/mod.rs +++ b/harmony-rs/harmony/src/modules/k8s/mod.rs @@ -1,4 +1,2 @@ - -pub mod resource; pub mod deployment; - +pub mod resource; diff --git a/harmony-rs/harmony/src/modules/k8s/resource.rs b/harmony-rs/harmony/src/modules/k8s/resource.rs index aa1ce87..eccbe8f 100644 --- a/harmony-rs/harmony/src/modules/k8s/resource.rs +++ b/harmony-rs/harmony/src/modules/k8s/resource.rs @@ -63,7 +63,7 @@ where { async fn execute( &self, - inventory: &Inventory, + _inventory: &Inventory, topology: &HAClusterTopology, ) -> Result { topology diff --git a/harmony-rs/harmony/src/modules/load_balancer.rs b/harmony-rs/harmony/src/modules/load_balancer.rs index a140fe1..4653021 100644 --- a/harmony-rs/harmony/src/modules/load_balancer.rs +++ b/harmony-rs/harmony/src/modules/load_balancer.rs @@ -54,12 +54,18 @@ impl Interpret for LoadBalancerInterpret { topology.load_balancer.ensure_initialized().await?; for service in self.score.public_services.iter() { info!("Ensuring service exists {service:?}"); - topology.load_balancer.ensure_service_exists(service).await?; + topology + .load_balancer + .ensure_service_exists(service) + .await?; } for service in self.score.private_services.iter() { info!("Ensuring private service exists {service:?}"); - topology.load_balancer.ensure_service_exists(service).await?; + topology + .load_balancer + .ensure_service_exists(service) + .await?; } info!("Applying load balancer configuration"); diff --git a/harmony-rs/harmony/src/modules/mod.rs b/harmony-rs/harmony/src/modules/mod.rs index 08e2f3f..035464f 100644 --- a/harmony-rs/harmony/src/modules/mod.rs +++ b/harmony-rs/harmony/src/modules/mod.rs @@ -1,7 +1,7 @@ pub mod dhcp; pub mod dns; -pub mod okd; -pub mod load_balancer; -pub mod tftp; pub mod http; pub mod k8s; +pub mod load_balancer; +pub mod okd; +pub mod tftp; diff --git a/harmony-rs/harmony/src/modules/okd/bootstrap_load_balancer.rs b/harmony-rs/harmony/src/modules/okd/bootstrap_load_balancer.rs index b372be3..ec8e7eb 100644 --- a/harmony-rs/harmony/src/modules/okd/bootstrap_load_balancer.rs +++ b/harmony-rs/harmony/src/modules/okd/bootstrap_load_balancer.rs @@ -51,10 +51,7 @@ impl OKDBootstrapLoadBalancerScore { }, } } - fn topology_to_backend_server( - topology: &HAClusterTopology, - port: u16, - ) -> Vec { + fn topology_to_backend_server(topology: &HAClusterTopology, port: u16) -> Vec { let mut backend: Vec<_> = topology .control_plane .iter() diff --git a/harmony-rs/harmony/src/modules/okd/mod.rs b/harmony-rs/harmony/src/modules/okd/mod.rs index e22ed67..8811771 100644 --- a/harmony-rs/harmony/src/modules/okd/mod.rs +++ b/harmony-rs/harmony/src/modules/okd/mod.rs @@ -1,7 +1,6 @@ +pub mod bootstrap_dhcp; +pub mod bootstrap_load_balancer; pub mod dhcp; pub mod dns; pub mod load_balancer; -pub mod bootstrap_load_balancer; -pub mod bootstrap_dhcp; pub mod upgrade; - diff --git a/harmony-rs/opnsense-config/src/config/config.rs b/harmony-rs/opnsense-config/src/config/config.rs index 0a73a72..e3ba82d 100644 --- a/harmony-rs/opnsense-config/src/config/config.rs +++ b/harmony-rs/opnsense-config/src/config/config.rs @@ -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 { + pub async fn upload_files(&self, source: &str, destination: &str) -> Result { self.shell.upload_folder(source, destination).await } diff --git a/harmony-rs/opnsense-config/src/config/manager/mod.rs b/harmony-rs/opnsense-config/src/config/manager/mod.rs index c71af1d..ad3a6b9 100644 --- a/harmony-rs/opnsense-config/src/config/manager/mod.rs +++ b/harmony-rs/opnsense-config/src/config/manager/mod.rs @@ -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; diff --git a/harmony-rs/opnsense-config/src/config/mod.rs b/harmony-rs/opnsense-config/src/config/mod.rs index e84bee9..5a6381f 100644 --- a/harmony-rs/opnsense-config/src/config/mod.rs +++ b/harmony-rs/opnsense-config/src/config/mod.rs @@ -1,6 +1,6 @@ mod config; mod manager; mod shell; -pub use manager::*; pub use config::*; +pub use manager::*; pub use shell::*; diff --git a/harmony-rs/opnsense-config/src/modules/caddy.rs b/harmony-rs/opnsense-config/src/modules/caddy.rs index ac06bf4..3af1ce9 100644 --- a/harmony-rs/opnsense-config/src/modules/caddy.rs +++ b/harmony-rs/opnsense-config/src/modules/caddy.rs @@ -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(()) diff --git a/harmony-rs/opnsense-config/src/modules/dns.rs b/harmony-rs/opnsense-config/src/modules/dns.rs index d8d5123..3bf045e 100644 --- a/harmony-rs/opnsense-config/src/modules/dns.rs +++ b/harmony-rs/opnsense-config/src/modules/dns.rs @@ -1,6 +1,5 @@ use opnsense_config_xml::{Host, OPNsense}; - pub struct DnsConfig<'a> { opnsense: &'a mut OPNsense, } diff --git a/harmony-rs/opnsense-config/src/modules/load_balancer.rs b/harmony-rs/opnsense-config/src/modules/load_balancer.rs index ef2c078..6c71ed4 100644 --- a/harmony-rs/opnsense-config/src/modules/load_balancer.rs +++ b/harmony-rs/opnsense-config/src/modules/load_balancer.rs @@ -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(()) } diff --git a/harmony-rs/opnsense-config/src/modules/mod.rs b/harmony-rs/opnsense-config/src/modules/mod.rs index 4fd006a..dc3fd7c 100644 --- a/harmony-rs/opnsense-config/src/modules/mod.rs +++ b/harmony-rs/opnsense-config/src/modules/mod.rs @@ -1,5 +1,5 @@ +pub mod caddy; pub mod dhcp; pub mod dns; pub mod load_balancer; pub mod tftp; -pub mod caddy; diff --git a/harmony-rs/opnsense-config/src/modules/tftp.rs b/harmony-rs/opnsense-config/src/modules/tftp.rs index 67b3bc3..023f068 100644 --- a/harmony-rs/opnsense-config/src/modules/tftp.rs +++ b/harmony-rs/opnsense-config/src/modules/tftp.rs @@ -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(()) }