From 98f3f82ad5913d2401725959777fa2e3ea4a35fd Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Fri, 4 Jul 2025 21:05:32 -0400 Subject: [PATCH] refact: Rename HttpScore into StaticFileHttpScore and add minimal documentation --- examples/nanodc/src/main.rs | 4 ++-- examples/opnsense/src/main.rs | 4 ++-- harmony/src/modules/http.rs | 23 +++++++++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/nanodc/src/main.rs b/examples/nanodc/src/main.rs index 31c5ba3..51b92d4 100644 --- a/examples/nanodc/src/main.rs +++ b/examples/nanodc/src/main.rs @@ -10,7 +10,7 @@ use harmony::{ inventory::Inventory, maestro::Maestro, modules::{ - http::HttpScore, + http::StaticFilesHttpScore, ipxe::IpxeScore, okd::{ bootstrap_dhcp::OKDBootstrapDhcpScore, @@ -126,7 +126,7 @@ async fn main() { harmony::modules::okd::load_balancer::OKDLoadBalancerScore::new(&topology); let tftp_score = TftpScore::new(Url::LocalFolder("./data/watchguard/tftpboot".to_string())); - let http_score = HttpScore::new(Url::LocalFolder( + let http_score = StaticFilesHttpScore::new(Url::LocalFolder( "./data/watchguard/pxe-http-files".to_string(), )); let ipxe_score = IpxeScore::new(); diff --git a/examples/opnsense/src/main.rs b/examples/opnsense/src/main.rs index 8e01dc0..c07c60e 100644 --- a/examples/opnsense/src/main.rs +++ b/examples/opnsense/src/main.rs @@ -11,7 +11,7 @@ use harmony::{ maestro::Maestro, modules::{ dummy::{ErrorScore, PanicScore, SuccessScore}, - http::HttpScore, + http::StaticFilesHttpScore, okd::{dhcp::OKDDhcpScore, dns::OKDDnsScore, load_balancer::OKDLoadBalancerScore}, opnsense::OPNsenseShellCommandScore, tftp::TftpScore, @@ -81,7 +81,7 @@ async fn main() { let load_balancer_score = OKDLoadBalancerScore::new(&topology); let tftp_score = TftpScore::new(Url::LocalFolder("./data/watchguard/tftpboot".to_string())); - let http_score = HttpScore::new(Url::LocalFolder( + let http_score = StaticFilesHttpScore::new(Url::LocalFolder( "./data/watchguard/pxe-http-files".to_string(), )); let mut maestro = Maestro::initialize(inventory, topology).await.unwrap(); diff --git a/harmony/src/modules/http.rs b/harmony/src/modules/http.rs index c98ff8f..36af092 100644 --- a/harmony/src/modules/http.rs +++ b/harmony/src/modules/http.rs @@ -10,14 +10,25 @@ use crate::{ topology::{HttpServer, Topology, Url}, }; +/// Configure an HTTP server that is provided by the Topology +/// +/// This Score will let you easily specify a file path to be served by the HTTP server +/// +/// For example, if you have a folder of assets at `/var/www/assets` simply do : +/// +/// ```rust,ignore +/// StaticFilesHttpScore { +/// files_to_serve: url!("file:///var/www/assets"), +/// } +/// ``` #[derive(Debug, new, Clone, Serialize)] -pub struct HttpScore { +pub struct StaticFilesHttpScore { files_to_serve: Url, } -impl Score for HttpScore { +impl Score for StaticFilesHttpScore { fn create_interpret(&self) -> Box> { - Box::new(HttpInterpret::new(self.clone())) + Box::new(StaticFilesHttpInterpret::new(self.clone())) } fn name(&self) -> String { @@ -26,12 +37,12 @@ impl Score for HttpScore { } #[derive(Debug, new, Clone)] -pub struct HttpInterpret { - score: HttpScore, +pub struct StaticFilesHttpInterpret { + score: StaticFilesHttpScore, } #[async_trait] -impl Interpret for HttpInterpret { +impl Interpret for StaticFilesHttpInterpret { async fn execute( &self, _inventory: &Inventory,