1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

push proxy wip

This commit is contained in:
Robin Appelman 2022-10-25 14:10:54 +02:00
commit 58918942fe
4 changed files with 84 additions and 58 deletions

View file

@ -6,6 +6,7 @@ use bollard::models::{ContainerState, EndpointSettings, HostConfig};
use bollard::Docker;
use maplit::hashmap;
use miette::{IntoDiagnostic, Report, Result, WrapErr};
use std::net::IpAddr;
use std::time::Duration;
use tokio::time::{sleep, timeout};
@ -85,38 +86,7 @@ impl ServiceTrait for NotifyPush {
}
async fn post_setup(&self, docker: &Docker, cloud_id: &str) -> Result<Vec<String>> {
docker
.start_container::<String>(&self.container_name(cloud_id), None)
.await
.into_diagnostic()?;
self.wait_for_push(docker, cloud_id).await?;
sleep(Duration::from_millis(100)).await;
let info = docker
.inspect_container(&self.container_name(cloud_id), None)
.await
.into_diagnostic()?;
let ip = if matches!(
info.state,
Some(ContainerState {
running: Some(true),
..
})
) {
info.network_settings
.unwrap()
.networks
.unwrap()
.values()
.next()
.unwrap()
.ip_address
.clone()
.unwrap()
} else {
return Err(Report::msg("notify_push not started"));
};
let ip = self.get_ip(docker, cloud_id).await?;
Ok(vec![
format!("occ config:system:set trusted_proxies 1 --value {}", ip),
format!("occ notify_push:setup http://{}:7867", ip),
@ -150,4 +120,42 @@ impl NotifyPush {
.into_diagnostic()
.wrap_err("Timeout after 30 seconds")?
}
pub async fn get_ip(&self, docker: &Docker, cloud_id: &str) -> Result<IpAddr> {
docker
.start_container::<String>(&self.container_name(cloud_id), None)
.await
.into_diagnostic()?;
self.wait_for_push(docker, cloud_id).await?;
sleep(Duration::from_millis(100)).await;
let info = docker
.inspect_container(&self.container_name(cloud_id), None)
.await
.into_diagnostic()?;
if matches!(
info.state,
Some(ContainerState {
running: Some(true),
..
})
) {
info.network_settings
.unwrap()
.networks
.unwrap()
.values()
.next()
.unwrap()
.ip_address
.clone()
.unwrap()
.parse()
.into_diagnostic()
.wrap_err("Invalid ip address")
} else {
Err(Report::msg("notify_push not started"))
}
}
}