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

support clamav socket

This commit is contained in:
Robin Appelman 2025-06-16 18:48:11 +02:00
commit 200921a74c
4 changed files with 111 additions and 27 deletions

View file

@ -234,3 +234,79 @@ impl ServiceTrait for Clam {
])
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ClamSocket;
#[async_trait::async_trait]
impl ServiceTrait for ClamSocket {
fn name(&self) -> &str {
"clamav-socket"
}
async fn spawn(
&self,
docker: &Docker,
cloud_id: &str,
network: &str,
_config: &HazeConfig,
_options: &CloudOptions,
) -> Result<Vec<String>> {
let image = "clamav/clamav";
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(vec![id])
}
fn container_name(&self, cloud_id: &str) -> Option<String> {
Some(format!("{}-{}", cloud_id, self.name()))
}
fn apps(&self) -> &'static [&'static str] {
&["files_antivirus"]
}
async fn post_setup(
&self,
_docker: &Docker,
_cloud_id: &str,
_config: &HazeConfig,
) -> Result<Vec<String>> {
Ok(vec![
"occ config:app:set files_antivirus av_mode --value=socket".into(),
"occ config:app:set files_antivirus av_socket --value=tcp://clamav-socket:3310".into(),
])
}
}