Integrated opnsense-config API in harmony, pretty easy, pretty happy. very much encouraging
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user