forked from NationTech/harmony
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:
6
harmony/src/modules/opnsense/mod.rs
Normal file
6
harmony/src/modules/opnsense/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
mod shell;
|
||||
mod upgrade;
|
||||
pub use shell::*;
|
||||
pub use upgrade::*;
|
||||
|
||||
@@ -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,
|
||||
37
harmony/src/modules/opnsense/upgrade.rs
Normal file
37
harmony/src/modules/opnsense/upgrade.rs
Normal 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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user