1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-04 01:24:09 +02:00

add support for imaginary

This commit is contained in:
Robin Appelman 2024-03-27 16:36:33 +01:00
commit a6abcc8c1e
3 changed files with 91 additions and 0 deletions

View file

@ -1,5 +1,6 @@
mod clam;
mod dav;
mod imaginary;
mod kaspersky;
mod ldap;
mod objectstore;
@ -13,6 +14,7 @@ mod smb;
use crate::config::{HazeConfig, Preset};
pub use crate::service::clam::{ClamIcap, ClamIcapTls};
use crate::service::dav::Dav;
use crate::service::imaginary::Imaginary;
use crate::service::kaspersky::{Kaspersky, KasperskyIcap};
pub use crate::service::ldap::{Ldap, LdapAdmin};
pub use crate::service::objectstore::ObjectStore;
@ -180,6 +182,7 @@ pub enum Service {
ClamIcap(ClamIcap),
ClamIcapTls(ClamIcapTls),
Oc(Oc),
Imaginary(Imaginary),
Preset(PresetService),
}
@ -198,6 +201,7 @@ impl Service {
"dav" => Some(vec![Service::Dav(Dav)]),
"sftp" => Some(vec![Service::Sftp(Sftp)]),
"oc" => Some(vec![Service::Oc(Oc)]),
"imaginary" => Some(vec![Service::Imaginary(Imaginary)]),
"kaspersky" => Some(vec![Service::Kaspersky(Kaspersky)]),
"kaspersky-icap" => Some(vec![Service::KasperskyIcap(KasperskyIcap)]),
"clamav-icap" => Some(vec![Service::ClamIcap(ClamIcap)]),

86
src/service/imaginary.rs Normal file
View file

@ -0,0 +1,86 @@
use crate::config::HazeConfig;
use crate::image::pull_image;
use crate::service::ServiceTrait;
use crate::Result;
use bollard::container::{Config, CreateContainerOptions, NetworkingConfig};
use bollard::models::{EndpointSettings, HostConfig};
use bollard::Docker;
use maplit::hashmap;
use miette::IntoDiagnostic;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Imaginary;
#[async_trait::async_trait]
impl ServiceTrait for Imaginary {
fn name(&self) -> &str {
"imaginary"
}
async fn spawn(
&self,
docker: &Docker,
cloud_id: &str,
network: &str,
_config: &HazeConfig,
) -> Result<Option<String>> {
let image = "nextcloud/aio-imaginary:latest";
pull_image(docker, image).await?;
let options = Some(CreateContainerOptions {
name: self.container_name(cloud_id).unwrap(),
..CreateContainerOptions::default()
});
let config = Config {
image: Some(image),
host_config: Some(HostConfig {
network_mode: Some(network.to_string()),
..Default::default()
}),
labels: Some(hashmap! {
"haze-type" => self.name(),
"haze-cloud-id" => cloud_id
}),
networking_config: Some(NetworkingConfig {
endpoints_config: hashmap! {
network => EndpointSettings {
aliases: Some(vec![self.name().to_string()]),
..Default::default()
}
},
}),
..Default::default()
};
let id = docker
.create_container(options, config)
.await
.into_diagnostic()?
.id;
docker
.start_container::<String>(&id, None)
.await
.into_diagnostic()?;
Ok(Some(id))
}
fn container_name(&self, cloud_id: &str) -> Option<String> {
Some(format!("{}-imaginary", cloud_id))
}
// no need to wait for imaginary, as it won't be used until the user logs in
async fn is_healthy(&self, _docker: &Docker, _cloud_id: &str) -> Result<bool> {
Ok(true)
}
async fn post_setup(
&self,
_docker: &Docker,
_cloud_id: &str,
_config: &HazeConfig,
) -> Result<Vec<String>> {
Ok(vec![
"occ config:system:set enabledPreviewProviders 0 --value='OC\\Preview\\Imaginary'"
.into(),
"occ config:system:set preview_imaginary_url --value='http://imaginary:9000'".into(),
])
}
}