use crate::cloud::CloudOptions; use crate::config::HazeConfig; use crate::image::pull_image; use crate::service::{split_cmnd, ServiceTrait}; use crate::Result; use bollard::models::{ContainerCreateBody, EndpointSettings, HostConfig, NetworkingConfig}; use bollard::query_parameters::CreateContainerOptions; use bollard::Docker; use maplit::hashmap; use miette::IntoDiagnostic; #[derive(Debug, Clone, Eq, PartialEq)] pub struct Smb; #[async_trait::async_trait] impl ServiceTrait for Smb { fn name(&self) -> &str { "smb" } async fn spawn( &self, docker: &Docker, cloud_id: &str, network: &str, _config: &HazeConfig, _options: &CloudOptions, ) -> Result> { let image = "ghcr.io/servercontainers/samba:smbd-only-a3.18.0-s4.18.2-r0"; pull_image(docker, image).await?; let options = Some(CreateContainerOptions { name: self.container_name(cloud_id), ..CreateContainerOptions::default() }); let config = ContainerCreateBody { image: Some(image.into()), host_config: Some(HostConfig { network_mode: Some(network.to_string()), ..Default::default() }), env: Some(vec![ "ACCOUNT_test=test".into(), "UID_test=1000".into(), "SAMBA_VOLUME_CONFIG_test=[test]; path=/tmp; valid users = test; guest ok = no; read only = no; browseable = yes".into(), ]), labels: Some(hashmap! { "haze-type".into() => self.name().into(), "haze-cloud-id".into() => cloud_id.into(), }), networking_config: Some(NetworkingConfig { endpoints_config: Some(hashmap! { network.into() => 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(&id, None).await.into_diagnostic()?; Ok(vec![id]) } fn container_name(&self, cloud_id: &str) -> Option { Some(format!("{}-smb", cloud_id)) } fn apps(&self) -> &'static [&'static str] { &["files_external"] } async fn post_setup( &self, _docker: &Docker, _cloud_id: &str, _config: &HazeConfig, ) -> Result>> { Ok(vec![ split_cmnd("occ files_external:create smb smb password::password"), split_cmnd("occ files_external:config 1 host smb"), split_cmnd("occ files_external:config 1 user test"), split_cmnd("occ files_external:config 1 password test"), split_cmnd("occ files_external:config 1 share test"), ]) } }