mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
improve service proxy
This commit is contained in:
parent
dfdc699ba9
commit
e080be43a4
4 changed files with 24 additions and 24 deletions
32
src/proxy.rs
32
src/proxy.rs
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::service::ServiceTrait;
|
use crate::service::ServiceTrait;
|
||||||
|
use crate::Result;
|
||||||
use crate::{Cloud, HazeConfig};
|
use crate::{Cloud, HazeConfig};
|
||||||
use crate::{Result, Service};
|
|
||||||
use bollard::Docker;
|
use bollard::Docker;
|
||||||
use miette::{miette, IntoDiagnostic};
|
use miette::{miette, IntoDiagnostic};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
@ -46,34 +46,18 @@ impl ActiveInstances {
|
||||||
return Some(ip);
|
return Some(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
let addr = if let Some(name) = name.strip_suffix("-push") {
|
// service proxy
|
||||||
|
let addr = if name.matches('-').count() == 2 {
|
||||||
|
let (name, service_name) = name.rsplit_once('-').unwrap();
|
||||||
let cloud = Cloud::get_by_filter(&self.docker, Some(name.into()), &self.config)
|
let cloud = Cloud::get_by_filter(&self.docker, Some(name.into()), &self.config)
|
||||||
.await
|
.await
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let push = cloud
|
let service = cloud
|
||||||
.services
|
.services
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|service| match service {
|
.find(|service| service.name() == service_name)?;
|
||||||
Service::Push(push) => Some(push),
|
let ip = service.get_ip(&self.docker, &cloud.id).await.ok()??;
|
||||||
_ => None,
|
SocketAddr::new(ip, service.proxy_port())
|
||||||
})
|
|
||||||
.next()?;
|
|
||||||
let ip = push.get_ip(&self.docker, &cloud.id).await.ok()??;
|
|
||||||
SocketAddr::new(ip, 7867)
|
|
||||||
} else if let Some(name) = name.strip_suffix("-office") {
|
|
||||||
let cloud = Cloud::get_by_filter(&self.docker, Some(name.into()), &self.config)
|
|
||||||
.await
|
|
||||||
.ok()?;
|
|
||||||
let office = cloud
|
|
||||||
.services
|
|
||||||
.iter()
|
|
||||||
.filter_map(|service| match service {
|
|
||||||
Service::Office(office) => Some(office),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.next()?;
|
|
||||||
let ip = office.get_ip(&self.docker, &cloud.id).await.ok()??;
|
|
||||||
SocketAddr::new(ip, 9980)
|
|
||||||
} else {
|
} else {
|
||||||
SocketAddr::new(
|
SocketAddr::new(
|
||||||
Cloud::get_by_filter(&self.docker, Some(name.into()), &self.config)
|
Cloud::get_by_filter(&self.docker, Some(name.into()), &self.config)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ mod dav;
|
||||||
mod kaspersky;
|
mod kaspersky;
|
||||||
mod ldap;
|
mod ldap;
|
||||||
mod objectstore;
|
mod objectstore;
|
||||||
|
mod oc;
|
||||||
mod office;
|
mod office;
|
||||||
mod onlyoffice;
|
mod onlyoffice;
|
||||||
mod push;
|
mod push;
|
||||||
|
|
@ -15,6 +16,7 @@ use crate::service::dav::Dav;
|
||||||
use crate::service::kaspersky::{Kaspersky, KasperskyIcap};
|
use crate::service::kaspersky::{Kaspersky, KasperskyIcap};
|
||||||
pub use crate::service::ldap::{Ldap, LdapAdmin};
|
pub use crate::service::ldap::{Ldap, LdapAdmin};
|
||||||
pub use crate::service::objectstore::ObjectStore;
|
pub use crate::service::objectstore::ObjectStore;
|
||||||
|
use crate::service::oc::Oc;
|
||||||
pub use crate::service::office::Office;
|
pub use crate::service::office::Office;
|
||||||
pub use crate::service::onlyoffice::OnlyOffice;
|
pub use crate::service::onlyoffice::OnlyOffice;
|
||||||
pub use crate::service::push::NotifyPush;
|
pub use crate::service::push::NotifyPush;
|
||||||
|
|
@ -155,6 +157,10 @@ pub trait ServiceTrait {
|
||||||
Err(Report::msg("service not started"))
|
Err(Report::msg("service not started"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn proxy_port(&self) -> u16 {
|
||||||
|
80
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[enum_dispatch]
|
#[enum_dispatch]
|
||||||
|
|
@ -172,6 +178,7 @@ pub enum Service {
|
||||||
Kaspersky(Kaspersky),
|
Kaspersky(Kaspersky),
|
||||||
KasperskyIcap(KasperskyIcap),
|
KasperskyIcap(KasperskyIcap),
|
||||||
ClamIcap(ClamIcap),
|
ClamIcap(ClamIcap),
|
||||||
|
Oc(Oc),
|
||||||
Preset(PresetService),
|
Preset(PresetService),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,6 +196,7 @@ impl Service {
|
||||||
"smb" => Some(vec![Service::Smb(Smb)]),
|
"smb" => Some(vec![Service::Smb(Smb)]),
|
||||||
"dav" => Some(vec![Service::Dav(Dav)]),
|
"dav" => Some(vec![Service::Dav(Dav)]),
|
||||||
"sftp" => Some(vec![Service::Sftp(Sftp)]),
|
"sftp" => Some(vec![Service::Sftp(Sftp)]),
|
||||||
|
"oc" => Some(vec![Service::Oc(Oc)]),
|
||||||
"kaspersky" => Some(vec![Service::Kaspersky(Kaspersky)]),
|
"kaspersky" => Some(vec![Service::Kaspersky(Kaspersky)]),
|
||||||
"kaspersky-icap" => Some(vec![Service::KasperskyIcap(KasperskyIcap)]),
|
"kaspersky-icap" => Some(vec![Service::KasperskyIcap(KasperskyIcap)]),
|
||||||
"clamav-icap" => Some(vec![Service::ClamIcap(ClamIcap)]),
|
"clamav-icap" => Some(vec![Service::ClamIcap(ClamIcap)]),
|
||||||
|
|
|
||||||
|
|
@ -141,4 +141,8 @@ impl ServiceTrait for Office {
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn proxy_port(&self) -> u16 {
|
||||||
|
9980
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,4 +98,8 @@ impl ServiceTrait for NotifyPush {
|
||||||
format!("occ notify_push:setup {}", addr),
|
format!("occ notify_push:setup {}", addr),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn proxy_port(&self) -> u16 {
|
||||||
|
7867
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue