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

add kaspersky service

This commit is contained in:
Robin Appelman 2021-11-08 17:42:41 +01:00
commit e40b2438fc
4 changed files with 84 additions and 0 deletions

View file

@ -42,6 +42,7 @@ Additionally, you can use the following options when starting an instance:
- `onlyoffice` setup an onlyoffice document server
- `push` setup [client push](https://github.com/nextcloud/notify_push)
- `smb`: setup a samba server for external storage use
- `kaspersky`: setup a kaspersky scan engine server. (Requires [manually setting up the image](https://github.com/icewind1991/kaspersky-docker))
#### Run tests in a new instance

View file

@ -8,6 +8,10 @@ use std::io::stdout;
use std::io::Write;
use termion::cursor;
pub async fn image_exists(docker: &Docker, image: &str) -> bool {
docker.inspect_image(image).await.is_ok()
}
pub async fn pull_image(docker: &Docker, image: &str) -> Result<()> {
if let Err(_) = docker.inspect_image(image).await {
println!("Pulling image {}", image);

View file

@ -1,3 +1,4 @@
mod kaspersky;
mod ldap;
mod objectstore;
mod onlyoffice;
@ -5,6 +6,7 @@ mod push;
mod smb;
use crate::config::HazeConfig;
use crate::service::kaspersky::Kaspersky;
pub use crate::service::ldap::{LDAPAdmin, LDAP};
pub use crate::service::objectstore::ObjectStore;
pub use crate::service::onlyoffice::OnlyOffice;
@ -69,6 +71,7 @@ pub enum Service {
OnlyOffice(OnlyOffice),
Push(NotifyPush),
Smb(Smb),
Kaspersky(Kaspersky),
}
impl Service {
@ -80,6 +83,7 @@ impl Service {
"onlyoffice" => Some(&[Service::OnlyOffice(OnlyOffice)]),
"push" => Some(&[Service::Push(NotifyPush)]),
"smb" => Some(&[Service::Smb(Smb)]),
"kaspersky" => Some(&[Service::Kaspersky(Kaspersky)]),
_ => None,
}
}

75
src/service/kaspersky.rs Normal file
View file

@ -0,0 +1,75 @@
use crate::config::HazeConfig;
use crate::image::{image_exists, pull_image};
use crate::service::ServiceTrait;
use crate::Result;
use bollard::container::{Config, CreateContainerOptions, NetworkingConfig};
use bollard::models::{EndpointSettings, HostConfig};
use bollard::Docker;
use color_eyre::eyre::eyre;
use maplit::hashmap;
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Kaspersky;
#[async_trait::async_trait]
impl ServiceTrait for Kaspersky {
fn name(&self) -> &str {
"kaspersky"
}
fn env(&self) -> &[&str] {
&[]
}
async fn spawn(
&self,
docker: &Docker,
cloud_id: &str,
network: &str,
_config: &HazeConfig,
) -> Result<String> {
let image = "kaspersky";
if !image_exists(docker, image).await {
eyre!("You need to manually create the 'kaspersky' image");
}
pull_image(docker, image).await?;
let options = Some(CreateContainerOptions {
name: self.container_name(cloud_id),
});
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?.id;
docker.start_container::<String>(&id, None).await?;
Ok(id)
}
async fn is_healthy(&self, _docker: &Docker, _cloud_id: &str) -> Result<bool> {
Ok(true)
}
fn container_name(&self, cloud_id: &str) -> String {
format!("{}-kaspersky", cloud_id)
}
fn apps(&self) -> &'static [&'static str] {
&["files_antivirus"]
}
}