Integrated opnsense-config API in harmony, pretty easy, pretty happy. very much encouraging

This commit is contained in:
jeangab
2024-11-26 15:58:42 -05:00
parent d30e909b83
commit 9c18c8be6d
13 changed files with 108 additions and 146 deletions

View File

@@ -1,8 +1,9 @@
use std::sync::Arc;
use std::{net::Ipv4Addr, sync::Arc, time::Duration};
use crate::{error::Error, modules::dhcp::DhcpConfig};
use crate::{config::{SshConfigManager, SshCredentials, SshOPNSenseShell}, error::Error, modules::dhcp::DhcpConfig};
use log::trace;
use opnsense_config_xml::OPNsense;
use russh::client;
use super::{ConfigManager, OPNsenseShell};
@@ -39,6 +40,27 @@ impl Config {
.apply_new_config(&self.opnsense.to_xml())
.await
}
pub async fn from_credentials(ipaddr: std::net::IpAddr, username: &str, password: &str) -> Self {
let config = Arc::new(client::Config {
inactivity_timeout: Some(Duration::from_secs(5)),
..<_>::default()
});
let credentials = SshCredentials::Password {
username: String::from(username),
password: String::from(password),
};
let shell = Arc::new(SshOPNSenseShell::new(
(ipaddr, 22),
credentials,
config,
));
let manager = Arc::new(SshConfigManager::new(shell.clone()));
Config::new(manager, shell).await.unwrap()
}
}
#[cfg(test)]