#![allow(unknown_lints, renamed_and_removed_lints, never_loop)]
use abscissa::{Callable, LoadConfig};
use std::path::PathBuf;
mod help;
mod keygen;
mod start;
mod version;
#[cfg(feature = "yubihsm")]
mod yubihsm;
#[cfg(feature = "yubihsm")]
pub use self::yubihsm::YubihsmCommand;
pub use self::{
help::HelpCommand, keygen::KeygenCommand, start::StartCommand, version::VersionCommand,
};
use config::{KmsConfig, CONFIG_FILE_NAME};
#[derive(Debug, Options)]
pub enum KmsCommand {
#[options(help = "show help for a command")]
Help(HelpCommand),
#[options(help = "generate a new software signing key")]
Keygen(KeygenCommand),
#[options(help = "start the KMS application")]
Start(StartCommand),
#[options(help = "display version information")]
Version(VersionCommand),
#[cfg(feature = "yubihsm")]
#[options(help = "subcommands for YubiHSM2")]
Yubihsm(YubihsmCommand),
}
impl_command!(KmsCommand);
impl KmsCommand {
pub fn verbose(&self) -> bool {
match self {
KmsCommand::Start(run) => run.verbose,
#[cfg(feature = "yubihsm")]
KmsCommand::Yubihsm(yubihsm) => yubihsm.verbose(),
_ => false,
}
}
}
impl LoadConfig<KmsConfig> for KmsCommand {
fn config_path(&self) -> Option<PathBuf> {
let config = match self {
KmsCommand::Start(run) => run.config.as_ref().map(|s| s.as_ref()),
#[cfg(feature = "yubihsm")]
KmsCommand::Yubihsm(yubihsm) => yubihsm.config_path(),
_ => return None,
};
Some(PathBuf::from(config.unwrap_or(CONFIG_FILE_NAME)))
}
}
impl Callable for KmsCommand {
fn call(&self) {
match self {
KmsCommand::Help(help) => help.call(),
KmsCommand::Keygen(keygen) => keygen.call(),
KmsCommand::Start(run) => run.call(),
KmsCommand::Version(version) => version.call(),
#[cfg(feature = "yubihsm")]
KmsCommand::Yubihsm(yubihsm) => yubihsm.call(),
}
}
}