mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
add dav option
This commit is contained in:
parent
d98ebf937d
commit
b49b08554e
3 changed files with 97 additions and 0 deletions
|
|
@ -66,6 +66,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
|
||||
- `dav`: setup a WebDAV server for external storage use
|
||||
- `kaspersky`: setup a kaspersky scan engine server in http mode. (Requires [manually setting up the image](https://github.com/icewind1991/kaspersky-docker))
|
||||
- `kaspersky-icap`: setup a kaspersky scan engine server in ICAP mode.
|
||||
- `clamav-icap`: setup a clam av scanner in ICAP mode.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
mod clam;
|
||||
mod dav;
|
||||
mod kaspersky;
|
||||
mod ldap;
|
||||
mod objectstore;
|
||||
|
|
@ -9,6 +10,7 @@ mod smb;
|
|||
|
||||
use crate::config::HazeConfig;
|
||||
pub use crate::service::clam::ClamIcap;
|
||||
use crate::service::dav::Dav;
|
||||
use crate::service::kaspersky::{Kaspersky, KasperskyIcap};
|
||||
pub use crate::service::ldap::{Ldap, LdapAdmin};
|
||||
pub use crate::service::objectstore::ObjectStore;
|
||||
|
|
@ -149,6 +151,7 @@ pub enum Service {
|
|||
Office(Office),
|
||||
Push(NotifyPush),
|
||||
Smb(Smb),
|
||||
Dav(Dav),
|
||||
Kaspersky(Kaspersky),
|
||||
KasperskyIcap(KasperskyIcap),
|
||||
ClamIcap(ClamIcap),
|
||||
|
|
@ -166,6 +169,7 @@ impl Service {
|
|||
"office" => Some(&[Service::Office(Office)]),
|
||||
"push" => Some(&[Service::Push(NotifyPush)]),
|
||||
"smb" => Some(&[Service::Smb(Smb)]),
|
||||
"dav" => Some(&[Service::Dav(Dav)]),
|
||||
"kaspersky" => Some(&[Service::Kaspersky(Kaspersky)]),
|
||||
"kaspersky-icap" => Some(&[Service::KasperskyIcap(KasperskyIcap)]),
|
||||
"clamav-icap" => Some(&[Service::ClamIcap(ClamIcap)]),
|
||||
|
|
|
|||
92
src/service/dav.rs
Normal file
92
src/service/dav.rs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
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 Dav;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceTrait for Dav {
|
||||
fn name(&self) -> &str {
|
||||
"dav"
|
||||
}
|
||||
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<String> {
|
||||
let image = "ugeek/webdav:amd64";
|
||||
pull_image(docker, image).await?;
|
||||
let options = Some(CreateContainerOptions {
|
||||
name: self.container_name(cloud_id),
|
||||
..CreateContainerOptions::default()
|
||||
});
|
||||
let config = Config {
|
||||
image: Some(image),
|
||||
host_config: Some(HostConfig {
|
||||
network_mode: Some(network.to_string()),
|
||||
..Default::default()
|
||||
}),
|
||||
env: Some(vec!["USERNAME=test", "PASSWORD=test"]),
|
||||
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(id)
|
||||
}
|
||||
|
||||
fn container_name(&self, cloud_id: &str) -> String {
|
||||
format!("{}-dav", cloud_id)
|
||||
}
|
||||
|
||||
fn apps(&self) -> &'static [&'static str] {
|
||||
&["files_external"]
|
||||
}
|
||||
|
||||
// no need to wait for dav, 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 files_external:create dav dav password::password".into(),
|
||||
"occ files_external:config 1 host dav".into(),
|
||||
"occ files_external:config 1 user test".into(),
|
||||
"occ files_external:config 1 password test".into(),
|
||||
])
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue