feat(modules/opnsense): refactor and add upgrade functionality

Refactor OPNSense module to use a mod.rs structure and add an OPNsenseLaunchUpgrade score for launching firmware upgrades.
This commit is contained in:
2025-02-21 11:23:45 -05:00
parent 0eb9e02b99
commit 62a554fac7
11 changed files with 111 additions and 14 deletions

View File

@@ -0,0 +1,6 @@
mod shell;
mod upgrade;
pub use shell::*;
pub use upgrade::*;

View File

@@ -12,14 +12,14 @@ use crate::{
};
#[derive(Debug, Clone)]
pub struct OPNSenseShellCommandScore {
pub struct OPNsenseShellCommandScore {
pub opnsense: Arc<RwLock<opnsense_config::Config>>,
pub command: String,
}
impl Score for OPNSenseShellCommandScore {
impl Score for OPNsenseShellCommandScore {
fn create_interpret(&self) -> Box<dyn Interpret> {
Box::new(OPNsenseInterpret {
Box::new(OPNsenseShellInterpret {
status: InterpretStatus::QUEUED,
score: self.clone(),
})
@@ -35,13 +35,13 @@ impl Score for OPNSenseShellCommandScore {
}
#[derive(Debug)]
pub struct OPNsenseInterpret {
status: InterpretStatus,
score: OPNSenseShellCommandScore,
pub struct OPNsenseShellInterpret {
pub status: InterpretStatus,
pub score: OPNsenseShellCommandScore,
}
#[async_trait]
impl Interpret for OPNsenseInterpret {
impl Interpret for OPNsenseShellInterpret {
async fn execute(
&self,
_inventory: &Inventory,

View File

@@ -0,0 +1,37 @@
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::{
interpret::{Interpret, InterpretStatus},
score::Score,
};
use super::{OPNsenseShellCommandScore, OPNsenseShellInterpret};
#[derive(Debug, Clone)]
pub struct OPNSenseLaunchUpgrade {
pub opnsense: Arc<RwLock<opnsense_config::Config>>,
}
impl Score for OPNSenseLaunchUpgrade {
fn create_interpret(&self) -> Box<dyn Interpret> {
let score = OPNsenseShellCommandScore {
opnsense: self.opnsense.clone(),
command: "/usr/local/opnsense/scripts/firmware/update.sh".to_string(),
};
Box::new(OPNsenseShellInterpret {
status: InterpretStatus::QUEUED,
score,
})
}
fn name(&self) -> String {
"OPNSenseLaunchUpgrade".to_string()
}
fn clone_box(&self) -> Box<dyn Score> {
Box::new(self.clone())
}
}