complete get_service_port_forward fn (#2579)

* complete get_service_port_forward fn

* refactor get_service_port_forward and get_container_ip

* remove unused function

* move host_id to GetServicePortForwardParams

* replace match with deref

Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>

* refactor get_container_ip to use deref

---------

Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
This commit is contained in:
Dominion5254
2024-04-05 13:20:49 -06:00
committed by GitHub
parent 056cab23e0
commit 75ff541aec
2 changed files with 26 additions and 13 deletions

View File

@@ -7,6 +7,7 @@ use imbl::OrdMap;
use lazy_format::lazy_format;
use models::{HostId, OptionExt, PackageId};
use patch_db::PatchDb;
use tokio::sync::Mutex;
use torut::onion::{OnionAddressV3, TorSecretKeyV3};
use tracing::instrument;
@@ -387,7 +388,21 @@ impl NetService {
}
pub fn get_ip(&self) -> Ipv4Addr {
self.ip.to_owned()
self.ip
}
pub fn get_ext_port(&self, host_id: HostId, internal_port: u16) -> Result<u16, Error> {
let host_id_binds = self.binds.get_key_value(&host_id);
match host_id_binds {
Some((id, binds)) => {
if let Some(ext_port_info) = binds.lan.get(&internal_port) {
Ok(ext_port_info.0)
} else {
Err(Error::new(eyre!("Internal Port {} not found in NetService binds", internal_port), crate::ErrorKind::NotFound))
}
},
None => Err(Error::new(eyre!("HostID {} not found in NetService binds", host_id), crate::ErrorKind::NotFound))
}
}
}