forked from NationTech/harmony
		
	fix: improve code formatting and module organization
- Corrected code formatting issues such as inconsistent line breaks and unnecessary trailing commas. - Reorganized `mod.rs` to ensure proper order of module declarations. - Fixed misplaced imports in `help.rs` and corrected the rendering method signature. - Cleaned up unused code lines and moved `dummy` module declaration to its correct position.
This commit is contained in:
		
							parent
							
								
									134f2b78d6
								
							
						
					
					
						commit
						e5b4b5114e
					
				| @ -10,7 +10,10 @@ use harmony::{ | |||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     maestro::Maestro, |     maestro::Maestro, | ||||||
|     modules::{ |     modules::{ | ||||||
|         dummy::{ErrorScore, PanicScore, SuccessScore}, http::HttpScore, okd::{dhcp::OKDDhcpScore, dns::OKDDnsScore}, tftp::TftpScore |         dummy::{ErrorScore, PanicScore, SuccessScore}, | ||||||
|  |         http::HttpScore, | ||||||
|  |         okd::{dhcp::OKDDhcpScore, dns::OKDDnsScore}, | ||||||
|  |         tftp::TftpScore, | ||||||
|     }, |     }, | ||||||
|     topology::{LogicalHost, UnmanagedRouter, Url}, |     topology::{LogicalHost, UnmanagedRouter, Url}, | ||||||
| }; | }; | ||||||
| @ -18,7 +21,6 @@ use harmony_macros::{ip, mac_address}; | |||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
| 
 |  | ||||||
|     let firewall = harmony::topology::LogicalHost { |     let firewall = harmony::topology::LogicalHost { | ||||||
|         ip: ip!("192.168.5.229"), |         ip: ip!("192.168.5.229"), | ||||||
|         name: String::from("opnsense-1"), |         name: String::from("opnsense-1"), | ||||||
| @ -64,7 +66,10 @@ async fn main() { | |||||||
|             .management(Arc::new(OPNSenseManagementInterface::new()))]), |             .management(Arc::new(OPNSenseManagementInterface::new()))]), | ||||||
|         storage_host: vec![], |         storage_host: vec![], | ||||||
|         worker_host: vec![], |         worker_host: vec![], | ||||||
|         control_plane_host: vec![PhysicalHost::empty(HostCategory::Server).mac_address(mac_address!("08:00:27:62:EC:C3"))], |         control_plane_host: vec![ | ||||||
|  |             PhysicalHost::empty(HostCategory::Server) | ||||||
|  |                 .mac_address(mac_address!("08:00:27:62:EC:C3")), | ||||||
|  |         ], | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     // TODO regroup smaller scores in a larger one such as this
 |     // TODO regroup smaller scores in a larger one such as this
 | ||||||
|  | |||||||
| @ -20,7 +20,10 @@ pub trait LoadBalancer: Send + Sync { | |||||||
|         &self, |         &self, | ||||||
|         service: &LoadBalancerService, |         service: &LoadBalancerService, | ||||||
|     ) -> Result<(), ExecutorError> { |     ) -> Result<(), ExecutorError> { | ||||||
|         debug!("Listing LoadBalancer services {:?}", self.list_services().await); |         debug!( | ||||||
|  |             "Listing LoadBalancer services {:?}", | ||||||
|  |             self.list_services().await | ||||||
|  |         ); | ||||||
|         if !self.list_services().await.contains(service) { |         if !self.list_services().await.contains(service) { | ||||||
|             self.add_service(service).await?; |             self.add_service(service).await?; | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
|  | mod ha_cluster; | ||||||
| mod host_binding; | mod host_binding; | ||||||
| mod http; | mod http; | ||||||
| mod load_balancer; | mod load_balancer; | ||||||
| pub mod openshift; | pub mod openshift; | ||||||
| mod router; | mod router; | ||||||
| mod tftp; | mod tftp; | ||||||
| mod ha_cluster; |  | ||||||
| pub use ha_cluster::*; | pub use ha_cluster::*; | ||||||
| pub use load_balancer::*; | pub use load_balancer::*; | ||||||
| pub use router::*; | pub use router::*; | ||||||
| @ -16,7 +16,6 @@ pub use tftp::*; | |||||||
| 
 | 
 | ||||||
| use std::{net::IpAddr, sync::Arc}; | use std::{net::IpAddr, sync::Arc}; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| pub type IpAddress = IpAddr; | pub type IpAddress = IpAddr; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone)] | #[derive(Debug, Clone)] | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| use k8s_openapi::NamespaceResourceScope; | use k8s_openapi::NamespaceResourceScope; | ||||||
| use kube::{api::PostParams, Api, Client, Error, Resource}; | use kube::{Api, Client, Error, Resource, api::PostParams}; | ||||||
| use serde::de::DeserializeOwned; | use serde::de::DeserializeOwned; | ||||||
| 
 | 
 | ||||||
| pub struct OpenshiftClient { | pub struct OpenshiftClient { | ||||||
|  | |||||||
| @ -23,7 +23,9 @@ impl LoadBalancer for OPNSenseFirewall { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async fn add_service(&self, service: &LoadBalancerService) -> Result<(), ExecutorError> { |     async fn add_service(&self, service: &LoadBalancerService) -> Result<(), ExecutorError> { | ||||||
|         warn!("TODO : the current implementation does not check / cleanup / merge with existing haproxy services properly. Make sure to manually verify that the configuration is correct after executing any operation here"); |         warn!( | ||||||
|  |             "TODO : the current implementation does not check / cleanup / merge with existing haproxy services properly. Make sure to manually verify that the configuration is correct after executing any operation here" | ||||||
|  |         ); | ||||||
|         let mut config = self.opnsense_config.write().await; |         let mut config = self.opnsense_config.write().await; | ||||||
|         let (frontend, backend, servers, healthcheck) = |         let (frontend, backend, servers, healthcheck) = | ||||||
|             harmony_load_balancer_service_to_haproxy_xml(service); |             harmony_load_balancer_service_to_haproxy_xml(service); | ||||||
| @ -60,7 +62,9 @@ impl LoadBalancer for OPNSenseFirewall { | |||||||
|         let mut config = self.opnsense_config.write().await; |         let mut config = self.opnsense_config.write().await; | ||||||
|         let load_balancer = config.load_balancer(); |         let load_balancer = config.load_balancer(); | ||||||
|         if let Some(config) = load_balancer.get_full_config() { |         if let Some(config) = load_balancer.get_full_config() { | ||||||
|             debug!("HAProxy config available in opnsense config, assuming it is already installed, {config:?}"); |             debug!( | ||||||
|  |                 "HAProxy config available in opnsense config, assuming it is already installed, {config:?}" | ||||||
|  |             ); | ||||||
|         } else { |         } else { | ||||||
|             config.install_package("os-haproxy").await.map_err(|e| { |             config.install_package("os-haproxy").await.map_err(|e| { | ||||||
|                 ExecutorError::UnexpectedError(format!( |                 ExecutorError::UnexpectedError(format!( | ||||||
| @ -366,13 +370,10 @@ mod tests { | |||||||
|         let result = get_servers_for_backend(&backend, &haproxy); |         let result = get_servers_for_backend(&backend, &haproxy); | ||||||
| 
 | 
 | ||||||
|         // Check the result
 |         // Check the result
 | ||||||
|         assert_eq!( |         assert_eq!(result, vec![BackendServer { | ||||||
|             result, |  | ||||||
|             vec![BackendServer { |  | ||||||
|             address: "192.168.1.1".to_string(), |             address: "192.168.1.1".to_string(), | ||||||
|             port: 80, |             port: 80, | ||||||
|             },] |         },]); | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_get_servers_for_backend_no_linked_servers() { |     fn test_get_servers_for_backend_no_linked_servers() { | ||||||
| @ -429,9 +430,7 @@ mod tests { | |||||||
|         // Call the function
 |         // Call the function
 | ||||||
|         let result = get_servers_for_backend(&backend, &haproxy); |         let result = get_servers_for_backend(&backend, &haproxy); | ||||||
|         // Check the result
 |         // Check the result
 | ||||||
|         assert_eq!( |         assert_eq!(result, vec![ | ||||||
|             result, |  | ||||||
|             vec![ |  | ||||||
|             BackendServer { |             BackendServer { | ||||||
|                 address: "some-hostname.test.mcd".to_string(), |                 address: "some-hostname.test.mcd".to_string(), | ||||||
|                 port: 80, |                 port: 80, | ||||||
| @ -440,7 +439,6 @@ mod tests { | |||||||
|                 address: "192.168.1.2".to_string(), |                 address: "192.168.1.2".to_string(), | ||||||
|                 port: 8080, |                 port: 8080, | ||||||
|             }, |             }, | ||||||
|             ] |         ]); | ||||||
|         ); |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,9 +1,8 @@ | |||||||
| pub mod dhcp; | pub mod dhcp; | ||||||
| pub mod dns; | pub mod dns; | ||||||
|  | pub mod dummy; | ||||||
| pub mod http; | pub mod http; | ||||||
| pub mod k8s; | pub mod k8s; | ||||||
| pub mod load_balancer; | pub mod load_balancer; | ||||||
| pub mod okd; | pub mod okd; | ||||||
| pub mod tftp; | pub mod tftp; | ||||||
| pub mod dummy; |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -10,7 +10,8 @@ impl HelpWidget { | |||||||
| impl Widget for HelpWidget { | impl Widget for HelpWidget { | ||||||
|     fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) |     fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) | ||||||
|     where |     where | ||||||
|         Self: Sized { |         Self: Sized, | ||||||
|  |     { | ||||||
|         let text = Paragraph::new("Usage => q/Esc: Quit | j/↑ :Select UP | k/↓: Select Down | Enter: Launch Score\nPageUp/PageDown: Scroll Logs | Shift+G/End: Logs bottom") |         let text = Paragraph::new("Usage => q/Esc: Quit | j/↑ :Select UP | k/↓: Select Down | Enter: Launch Score\nPageUp/PageDown: Scroll Logs | Shift+G/End: Logs bottom") | ||||||
|             .centered() |             .centered() | ||||||
|             .wrap(Wrap { trim: false }); |             .wrap(Wrap { trim: false }); | ||||||
|  | |||||||
| @ -1,2 +1,2 @@ | |||||||
| pub mod score; |  | ||||||
| pub mod help; | pub mod help; | ||||||
|  | pub mod score; | ||||||
|  | |||||||
| @ -3,10 +3,10 @@ use std::sync::{Arc, RwLock}; | |||||||
| use crossterm::event::{Event, KeyCode, KeyEventKind}; | use crossterm::event::{Event, KeyCode, KeyEventKind}; | ||||||
| use log::{info, warn}; | use log::{info, warn}; | ||||||
| use ratatui::{ | use ratatui::{ | ||||||
|  |     Frame, | ||||||
|     layout::Rect, |     layout::Rect, | ||||||
|     style::{Style, Stylize}, |     style::{Style, Stylize}, | ||||||
|     widgets::{List, ListState, StatefulWidget, Widget}, |     widgets::{List, ListState, StatefulWidget, Widget}, | ||||||
|     Frame, |  | ||||||
| }; | }; | ||||||
| use tokio::sync::mpsc; | use tokio::sync::mpsc; | ||||||
| 
 | 
 | ||||||
| @ -78,7 +78,6 @@ impl ScoreListWidget { | |||||||
|         frame.render_widget(self, area); |         frame.render_widget(self, area); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     fn clear_execution(&mut self) { |     fn clear_execution(&mut self) { | ||||||
|         match self.execution.take() { |         match self.execution.take() { | ||||||
|             Some(execution) => { |             Some(execution) => { | ||||||
|  | |||||||
| @ -183,4 +183,3 @@ impl<'a> DhcpConfig<'a> { | |||||||
|         self.get_lan_dhcpd().bootfilename = Some(boot_filename.to_string()); |         self.get_lan_dhcpd().bootfilename = Some(boot_filename.to_string()); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 |  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user