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

add dav option

This commit is contained in:
Robin Appelman 2023-06-22 16:55:20 +02:00
commit b49b08554e
3 changed files with 97 additions and 0 deletions

92
src/service/dav.rs Normal file
View 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(),
])
}
}