1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

command help

This commit is contained in:
Robin Appelman 2025-09-01 18:17:06 +02:00
commit f928547ac2
6 changed files with 350 additions and 106 deletions

View file

@ -42,6 +42,7 @@ use std::iter::empty;
use std::net::IpAddr;
use std::str::FromStr;
use std::time::Duration;
use strum::{Display, EnumIter, EnumMessage, EnumString, IntoStaticStr};
use tokio::time::{sleep, timeout};
#[async_trait::async_trait]
@ -192,6 +193,78 @@ impl ServiceTrait for RedisTls {
}
}
#[derive(
Copy, Clone, Debug, PartialEq, EnumString, EnumMessage, EnumIter, IntoStaticStr, Display,
)]
#[strum(serialize_all = "kebab-case")]
pub enum ServiceType {
/// S3 Primary storage and external storage
S3,
/// S3 multi-object store Primary storage and external storage
S3m,
/// S3 multi-bucket Primary storage and external storage
S3mb,
/// Azure Primary storage and external storage
Azure,
/// Ldap user backend
Ldap,
/// OnlyOffice
OnlyOffice,
/// Libre office online
Office,
/// notify_push
Push,
/// Smb external storage
Smb,
/// Database sharding
#[strum(serialize = "sharding", serialize = "sharded")]
Sharding,
/// Database sharding migration
#[strum(serialize = "sharding-migrate", serialize = "sharded-migrate")]
ShardingMigrate,
/// Database sharding migration, with the shards unset
#[strum(
serialize = "sharding-migrate-unset",
serialize = "sharded-migrate-unset"
)]
ShardingMigrateUnset,
/// Database sharding with a single shard
SingleShard,
/// WebDav external storage
Dav,
/// Sftp external storage
Sftp,
/// ownCloud instance for migration
Oc,
/// Imaginary for preview generation
Imaginary,
/// Kaspersky antivirus in http mode
Kaspersky,
/// Kaspersky antivirus in icap mode
KasperskyIcap,
/// Kaspersky antivirus in local binary
#[strum(serialize = "clamav", serialize = "clam")]
ClamAv,
/// Kaspersky antivirus in external socket mode
#[strum(serialize = "clamav-external", serialize = "clam-external")]
ClamAvExternal,
/// Kaspersky antivirus in local socket mode
#[strum(serialize = "clamav-socket", serialize = "clam-socket")]
ClamAvSocket,
/// Kaspersky antivirus in icap mode
#[strum(serialize = "clamav-icap", serialize = "clam-icap")]
ClamAvIcap,
/// Kaspersky antivirus in icap mode with TLS
#[strum(serialize = "clamav-icap-tls", serialize = "clam-icap-tls")]
ClamAvIcapTls,
/// Mail server
Mail,
/// External redis instance
Redis,
/// External redis instance with TLS
RedisTls,
}
#[enum_dispatch]
#[derive(Clone, Eq, PartialEq, Debug)]
pub enum Service {
@ -224,52 +297,46 @@ pub enum Service {
impl Service {
pub fn from_type(presets: &[Preset], ty: &str) -> Option<Vec<Self>> {
match ty {
"s3" => Some(vec![Service::ObjectStore(ObjectStore::S3)]),
"s3m" => Some(vec![Service::ObjectStore(ObjectStore::S3m)]),
"s3mb" => Some(vec![Service::ObjectStore(ObjectStore::S3mb)]),
"azure" => Some(vec![Service::ObjectStore(ObjectStore::Azure)]),
"ldap" => Some(vec![Service::Ldap(Ldap), Service::LdapAdmin(LdapAdmin)]),
"onlyoffice" => Some(vec![Service::OnlyOffice(OnlyOffice)]),
"office" => Some(vec![Service::Office(Office)]),
"push" => Some(vec![Service::Push(NotifyPush)]),
"smb" => Some(vec![Service::Smb(Smb)]),
"sharded" => Some(vec![Service::Sharding(Sharding)]),
"sharding" => Some(vec![Service::Sharding(Sharding)]),
"single-shard" => Some(vec![Service::SingleShard(SingleShard)]),
"singleshard" => Some(vec![Service::SingleShard(SingleShard)]),
"sharded-migrate" => Some(vec![Service::ShardingMigrate(ShardingMigrate)]),
"sharding-migrate" => Some(vec![Service::ShardingMigrate(ShardingMigrate)]),
"sharded-migrate-unset" => {
Some(vec![Service::ShardingMigrateUnset(ShardingMigrateUnset)])
if let Ok(ty) = ServiceType::from_str(ty) {
match ty {
ServiceType::S3 => Some(vec![Service::ObjectStore(ObjectStore::S3)]),
ServiceType::S3m => Some(vec![Service::ObjectStore(ObjectStore::S3m)]),
ServiceType::S3mb => Some(vec![Service::ObjectStore(ObjectStore::S3mb)]),
ServiceType::Azure => Some(vec![Service::ObjectStore(ObjectStore::Azure)]),
ServiceType::Ldap => Some(vec![Service::Ldap(Ldap), Service::LdapAdmin(LdapAdmin)]),
ServiceType::OnlyOffice => Some(vec![Service::OnlyOffice(OnlyOffice)]),
ServiceType::Office => Some(vec![Service::Office(Office)]),
ServiceType::Push => Some(vec![Service::Push(NotifyPush)]),
ServiceType::Smb => Some(vec![Service::Smb(Smb)]),
ServiceType::Sharding => Some(vec![Service::Sharding(Sharding)]),
ServiceType::SingleShard => Some(vec![Service::SingleShard(SingleShard)]),
ServiceType::ShardingMigrate => {
Some(vec![Service::ShardingMigrate(ShardingMigrate)])
}
ServiceType::ShardingMigrateUnset => {
Some(vec![Service::ShardingMigrateUnset(ShardingMigrateUnset)])
}
ServiceType::Dav => Some(vec![Service::Dav(Dav)]),
ServiceType::Sftp => Some(vec![Service::Sftp(Sftp)]),
ServiceType::Oc => Some(vec![Service::Oc(Oc)]),
ServiceType::Imaginary => Some(vec![Service::Imaginary(Imaginary)]),
ServiceType::Kaspersky => Some(vec![Service::Kaspersky(Kaspersky)]),
ServiceType::KasperskyIcap => Some(vec![Service::KasperskyIcap(KasperskyIcap)]),
ServiceType::ClamAv => Some(vec![Service::Clam(Clam)]),
ServiceType::ClamAvExternal => Some(vec![Service::ClamSocket(ClamSocket)]),
ServiceType::ClamAvSocket => Some(vec![Service::ClamSocket(ClamSocket)]),
ServiceType::ClamAvIcap => Some(vec![Service::ClamIcap(ClamIcap)]),
ServiceType::ClamAvIcapTls => Some(vec![Service::ClamIcapTls(ClamIcapTls)]),
ServiceType::Mail => Some(vec![Service::Mail(Mail)]),
ServiceType::Redis => Some(vec![Service::Redis(Redis)]),
ServiceType::RedisTls => Some(vec![Service::RedisTls(RedisTls)]),
}
"sharding-migrate-unset" => {
Some(vec![Service::ShardingMigrateUnset(ShardingMigrateUnset)])
}
"dav" => Some(vec![Service::Dav(Dav)]),
"sftp" => Some(vec![Service::Sftp(Sftp)]),
"oc" => Some(vec![Service::Oc(Oc)]),
"imaginary" => Some(vec![Service::Imaginary(Imaginary)]),
"kaspersky" => Some(vec![Service::Kaspersky(Kaspersky)]),
"kaspersky-icap" => Some(vec![Service::KasperskyIcap(KasperskyIcap)]),
"clamav" => Some(vec![Service::Clam(Clam)]),
"clamav-external" => Some(vec![Service::ClamSocket(ClamSocket)]),
"clamav-socket" => Some(vec![Service::ClamSocket(ClamSocket)]),
"clamav-icap" => Some(vec![Service::ClamIcap(ClamIcap)]),
"clamav-icap-tls" => Some(vec![Service::ClamIcapTls(ClamIcapTls)]),
"clam" => Some(vec![Service::Clam(Clam)]),
"clam-external" => Some(vec![Service::ClamSocket(ClamSocket)]),
"clam-socket" => Some(vec![Service::ClamSocket(ClamSocket)]),
"clam-icap" => Some(vec![Service::ClamIcap(ClamIcap)]),
"clam-icap-tls" => Some(vec![Service::ClamIcapTls(ClamIcapTls)]),
"mail" => Some(vec![Service::Mail(Mail)]),
"redis" => Some(vec![Service::Redis(Redis)]),
"redis-tls" => Some(vec![Service::RedisTls(RedisTls)]),
_ => presets
} else {
presets
.iter()
.find_map(|preset| (preset.name == ty).then(|| PresetService(preset.name.clone())))
.map(Service::Preset)
.map(|service| vec![service]),
.map(|service| vec![service])
}
}