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:
parent
4ce3d45e64
commit
e40b2438fc
4 changed files with 84 additions and 0 deletions
|
|
@ -42,6 +42,7 @@ Additionally, you can use the following options when starting an instance:
|
||||||
- `onlyoffice` setup an onlyoffice document server
|
- `onlyoffice` setup an onlyoffice document server
|
||||||
- `push` setup [client push](https://github.com/nextcloud/notify_push)
|
- `push` setup [client push](https://github.com/nextcloud/notify_push)
|
||||||
- `smb`: setup a samba server for external storage use
|
- `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
|
#### Run tests in a new instance
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ use std::io::stdout;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use termion::cursor;
|
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<()> {
|
pub async fn pull_image(docker: &Docker, image: &str) -> Result<()> {
|
||||||
if let Err(_) = docker.inspect_image(image).await {
|
if let Err(_) = docker.inspect_image(image).await {
|
||||||
println!("Pulling image {}", image);
|
println!("Pulling image {}", image);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
mod kaspersky;
|
||||||
mod ldap;
|
mod ldap;
|
||||||
mod objectstore;
|
mod objectstore;
|
||||||
mod onlyoffice;
|
mod onlyoffice;
|
||||||
|
|
@ -5,6 +6,7 @@ mod push;
|
||||||
mod smb;
|
mod smb;
|
||||||
|
|
||||||
use crate::config::HazeConfig;
|
use crate::config::HazeConfig;
|
||||||
|
use crate::service::kaspersky::Kaspersky;
|
||||||
pub use crate::service::ldap::{LDAPAdmin, LDAP};
|
pub use crate::service::ldap::{LDAPAdmin, LDAP};
|
||||||
pub use crate::service::objectstore::ObjectStore;
|
pub use crate::service::objectstore::ObjectStore;
|
||||||
pub use crate::service::onlyoffice::OnlyOffice;
|
pub use crate::service::onlyoffice::OnlyOffice;
|
||||||
|
|
@ -69,6 +71,7 @@ pub enum Service {
|
||||||
OnlyOffice(OnlyOffice),
|
OnlyOffice(OnlyOffice),
|
||||||
Push(NotifyPush),
|
Push(NotifyPush),
|
||||||
Smb(Smb),
|
Smb(Smb),
|
||||||
|
Kaspersky(Kaspersky),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
|
|
@ -80,6 +83,7 @@ impl Service {
|
||||||
"onlyoffice" => Some(&[Service::OnlyOffice(OnlyOffice)]),
|
"onlyoffice" => Some(&[Service::OnlyOffice(OnlyOffice)]),
|
||||||
"push" => Some(&[Service::Push(NotifyPush)]),
|
"push" => Some(&[Service::Push(NotifyPush)]),
|
||||||
"smb" => Some(&[Service::Smb(Smb)]),
|
"smb" => Some(&[Service::Smb(Smb)]),
|
||||||
|
"kaspersky" => Some(&[Service::Kaspersky(Kaspersky)]),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
75
src/service/kaspersky.rs
Normal file
75
src/service/kaspersky.rs
Normal 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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue