diff --git a/bin/dunitrust-server/src/cli.rs b/bin/dunitrust-server/src/cli.rs index eaf19610002b9078647a2a47b2df7d3c017f4834..77117928f5a60a2a5ea4a6a0e256574741ad0cb7 100644 --- a/bin/dunitrust-server/src/cli.rs +++ b/bin/dunitrust-server/src/cli.rs @@ -21,7 +21,8 @@ use durs_core::commands::modules::{DisableOpt, EnableOpt, ListModulesOpt}; use durs_core::commands::reset::ResetOpt; use durs_core::commands::start::StartOpt; use durs_core::commands::{ - DursCommand, DursCommandEnum, DursCoreCommand, DursCoreOptions, ExecutableModuleCommand, + CommandNeedKeypairs, DursCommand, DursCommandEnum, DursCoreCommand, DursCoreOptions, + ExecutableModuleCommand, }; use durs_core::errors::DursCoreError; use durs_core::DursCore; @@ -62,6 +63,8 @@ pub struct DursCliOpt { profile_name: Option<String>, } +impl CommandNeedKeypairs for DursCliOpt {} + impl ExecutableModuleCommand for DursCliOpt { /// Execute command fn execute_module_command(self, options: DursCoreOptions) -> Result<(), DursCoreError> { diff --git a/lib/core/core/src/commands/dbex.rs b/lib/core/core/src/commands/dbex.rs index f406bb754ed43e665dd45b2fbe37c6e651745dd9..b431c32e084b9371ad9113d1a073090e90e94968 100644 --- a/lib/core/core/src/commands/dbex.rs +++ b/lib/core/core/src/commands/dbex.rs @@ -15,7 +15,7 @@ //! Durs-core cli : dbex subcommands. -use crate::commands::DursExecutableCoreCommand; +use crate::commands::{CommandNeedKeypairs, DursExecutableCoreCommand}; use crate::dbex; use crate::errors::DursCoreError; use crate::DursCore; @@ -34,6 +34,8 @@ pub struct DbExOpt { pub subcommand: DbExSubCommand, } +impl CommandNeedKeypairs for DbExOpt {} + #[derive(StructOpt, Debug, Clone)] /// dbex subcommands pub enum DbExSubCommand { diff --git a/lib/core/core/src/commands/keys.rs b/lib/core/core/src/commands/keys.rs index c91a56d2db87b90662545dcf2ad8149683931e82..842eaaa0e499f69f2068c9f10f4804e8a8bc6331 100644 --- a/lib/core/core/src/commands/keys.rs +++ b/lib/core/core/src/commands/keys.rs @@ -15,7 +15,7 @@ //! Durs-core cli : keys subcommands. -use crate::commands::DursExecutableCoreCommand; +use crate::commands::{CommandNeedKeypairs, DursExecutableCoreCommand}; use crate::errors::DursCoreError; use crate::DursCore; use clap::arg_enum; @@ -36,6 +36,12 @@ pub struct KeysOpt { pub subcommand: KeysSubCommand, } +impl CommandNeedKeypairs for KeysOpt { + fn needs_keypairs(&self) -> bool { + true + } +} + #[derive(StructOpt, Debug, Clone, Copy)] /// keys subcommands pub enum KeysSubCommand { diff --git a/lib/core/core/src/commands/mod.rs b/lib/core/core/src/commands/mod.rs index d6949a82616660ece3534766c273905be874dc2d..324ca4663e71fb981b11b51a6f84a9d4dee0b69c 100644 --- a/lib/core/core/src/commands/mod.rs +++ b/lib/core/core/src/commands/mod.rs @@ -70,11 +70,19 @@ pub trait DursExecutableCoreCommand { } /// Executable module command -pub trait ExecutableModuleCommand { +pub trait ExecutableModuleCommand: CommandNeedKeypairs { /// Execute module command fn execute_module_command(self, options: DursCoreOptions) -> Result<(), DursCoreError>; } +/// Do this command use the keypairs +pub trait CommandNeedKeypairs { + /// Do this command use the keypairs + fn needs_keypairs(&self) -> bool { + false + } +} + /// Dunitrust command with options pub struct DursCommand<T: ExecutableModuleCommand> { /// Dunitrust core options @@ -149,6 +157,22 @@ pub enum DursCoreCommand { KeysOpt(KeysOpt), } +impl CommandNeedKeypairs for DursCoreCommand { + /// Do this command use the keypairs + fn needs_keypairs(&self) -> bool { + match self { + DursCoreCommand::EnableOpt(opt) => opt.needs_keypairs(), + DursCoreCommand::DisableOpt(opt) => opt.needs_keypairs(), + DursCoreCommand::ListModulesOpt(opt) => opt.needs_keypairs(), + DursCoreCommand::StartOpt(opt) => opt.needs_keypairs(), + DursCoreCommand::SyncOpt(opt) => opt.needs_keypairs(), + DursCoreCommand::ResetOpt(opt) => opt.needs_keypairs(), + DursCoreCommand::DbExOpt(opt) => opt.needs_keypairs(), + DursCoreCommand::KeysOpt(opt) => opt.needs_keypairs(), + } + } +} + /// InvalidInput #[derive(Debug, Copy, Clone)] pub struct InvalidInput(&'static str); diff --git a/lib/core/core/src/commands/modules.rs b/lib/core/core/src/commands/modules.rs index 27f553f1b12f3491048bffe31d33071dbcc9ddb9..5b08d1d5b4bc35e6c5ffbd2699e05559769c80c0 100644 --- a/lib/core/core/src/commands/modules.rs +++ b/lib/core/core/src/commands/modules.rs @@ -15,7 +15,7 @@ //! Durs-core cli : modules manager subcommands. -use crate::commands::DursExecutableCoreCommand; +use crate::commands::{CommandNeedKeypairs, DursExecutableCoreCommand}; use crate::errors::DursCoreError; use crate::DursCore; use durs_conf::{ChangeGlobalConf, DuRsConf}; @@ -31,6 +31,8 @@ pub struct EnableOpt { pub module_name: ModuleName, } +impl CommandNeedKeypairs for EnableOpt {} + impl DursExecutableCoreCommand for EnableOpt { #[inline] fn execute(self, mut durs_core: DursCore<DuRsConf>) -> Result<(), DursCoreError> { @@ -51,6 +53,8 @@ pub struct DisableOpt { pub module_name: ModuleName, } +impl CommandNeedKeypairs for DisableOpt {} + impl DursExecutableCoreCommand for DisableOpt { #[inline] fn execute(self, mut durs_core: DursCore<DuRsConf>) -> Result<(), DursCoreError> { @@ -99,3 +103,5 @@ impl ListModulesOpt { filters } } + +impl CommandNeedKeypairs for ListModulesOpt {} diff --git a/lib/core/core/src/commands/reset.rs b/lib/core/core/src/commands/reset.rs index 528cf531b73519a19d8fd42285dee49d24e04789..4dc34ae8965ba490e9cd6f895722eb6d3f672129 100644 --- a/lib/core/core/src/commands/reset.rs +++ b/lib/core/core/src/commands/reset.rs @@ -16,7 +16,7 @@ //! Durs-core cli : reset subcommand. use super::InvalidInput; -use crate::commands::DursExecutableCoreCommand; +use crate::commands::{CommandNeedKeypairs, DursExecutableCoreCommand}; use crate::errors::DursCoreError; use crate::DursCore; use durs_conf::DuRsConf; @@ -54,6 +54,15 @@ pub struct ResetOpt { pub reset_type: ResetType, } +impl CommandNeedKeypairs for ResetOpt { + fn needs_keypairs(&self) -> bool { + match self.reset_type { + ResetType::All | ResetType::Conf => true, + ResetType::Datas => false, + } + } +} + impl DursExecutableCoreCommand for ResetOpt { fn execute(self, durs_core: DursCore<DuRsConf>) -> Result<(), DursCoreError> { let profile_path = durs_core.soft_meta_datas.profile_path; diff --git a/lib/core/core/src/commands/start.rs b/lib/core/core/src/commands/start.rs index d5e35432e60b6cc4add6f141f5767621c0375f8a..ea3ee1b8af0230353f07c83ccaa6779eae77c19b 100644 --- a/lib/core/core/src/commands/start.rs +++ b/lib/core/core/src/commands/start.rs @@ -15,7 +15,15 @@ //! Durs-core cli : start subcommands. +use crate::commands::CommandNeedKeypairs; + #[derive(StructOpt, Debug, Copy, Clone)] #[structopt(name = "start", setting(structopt::clap::AppSettings::ColoredHelp))] /// start durs server pub struct StartOpt {} + +impl CommandNeedKeypairs for StartOpt { + fn needs_keypairs(&self) -> bool { + true + } +} diff --git a/lib/core/network/cli/sync.rs b/lib/core/network/cli/sync.rs index 46a10e2be24ed04d0e731c443608b9569492d30e..08dc2349a1a64e9a540ac7f68e1155a3de8f7869 100644 --- a/lib/core/network/cli/sync.rs +++ b/lib/core/network/cli/sync.rs @@ -47,3 +47,10 @@ pub struct SyncOpt { #[structopt(short = "u", long = "unsafe", hidden = true)] pub unsafe_mode: bool, } + +impl SyncOpt { + /// Do this command use the keypairs + pub fn needs_keypairs(&self) -> bool { + true + } +}