mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
add sftp support
This commit is contained in:
parent
378ddd6f3d
commit
2168a07e7c
3 changed files with 98 additions and 0 deletions
|
|
@ -67,6 +67,7 @@ Additionally, you can use the following options when starting an instance:
|
|||
- `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
|
||||
- `sftp`: setup a SFTP 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.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ mod objectstore;
|
|||
mod office;
|
||||
mod onlyoffice;
|
||||
mod push;
|
||||
mod sftp;
|
||||
mod smb;
|
||||
|
||||
use crate::config::HazeConfig;
|
||||
|
|
@ -17,6 +18,7 @@ pub use crate::service::objectstore::ObjectStore;
|
|||
pub use crate::service::office::Office;
|
||||
pub use crate::service::onlyoffice::OnlyOffice;
|
||||
pub use crate::service::push::NotifyPush;
|
||||
use crate::service::sftp::Sftp;
|
||||
use crate::service::smb::Smb;
|
||||
use bollard::models::ContainerState;
|
||||
use bollard::Docker;
|
||||
|
|
@ -152,6 +154,7 @@ pub enum Service {
|
|||
Push(NotifyPush),
|
||||
Smb(Smb),
|
||||
Dav(Dav),
|
||||
Sftp(Sftp),
|
||||
Kaspersky(Kaspersky),
|
||||
KasperskyIcap(KasperskyIcap),
|
||||
ClamIcap(ClamIcap),
|
||||
|
|
@ -170,6 +173,7 @@ impl Service {
|
|||
"push" => Some(&[Service::Push(NotifyPush)]),
|
||||
"smb" => Some(&[Service::Smb(Smb)]),
|
||||
"dav" => Some(&[Service::Dav(Dav)]),
|
||||
"sftp" => Some(&[Service::Sftp(Sftp)]),
|
||||
"kaspersky" => Some(&[Service::Kaspersky(Kaspersky)]),
|
||||
"kaspersky-icap" => Some(&[Service::KasperskyIcap(KasperskyIcap)]),
|
||||
"clamav-icap" => Some(&[Service::ClamIcap(ClamIcap)]),
|
||||
|
|
|
|||
93
src/service/sftp.rs
Normal file
93
src/service/sftp.rs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
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 Sftp;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ServiceTrait for Sftp {
|
||||
fn name(&self) -> &str {
|
||||
"sftp"
|
||||
}
|
||||
|
||||
async fn spawn(
|
||||
&self,
|
||||
docker: &Docker,
|
||||
cloud_id: &str,
|
||||
network: &str,
|
||||
_config: &HazeConfig,
|
||||
) -> Result<String> {
|
||||
let image = "atmoz/sftp:alpine";
|
||||
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()
|
||||
}),
|
||||
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()
|
||||
}
|
||||
},
|
||||
}),
|
||||
cmd: Some(vec!["test:test:::data"]),
|
||||
..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!("{}-sftp", 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 sftp sftp password::password".into(),
|
||||
"occ files_external:config 1 host sftp".into(),
|
||||
"occ files_external:config 1 user test".into(),
|
||||
"occ files_external:config 1 root data".into(),
|
||||
"occ files_external:config 1 password test".into(),
|
||||
])
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue