pub mod init;
#[cfg(feature = "ledger")]
pub mod ledger;
#[cfg(feature = "softsign")]
pub mod softsign;
pub mod start;
pub mod version;
#[cfg(feature = "yubihsm")]
pub mod yubihsm;
#[cfg(feature = "ledger")]
pub use self::ledger::LedgerCommand;
#[cfg(feature = "softsign")]
pub use self::softsign::SoftsignCommand;
#[cfg(feature = "yubihsm")]
pub use self::yubihsm::YubihsmCommand;
pub use self::{init::InitCommand, start::StartCommand, version::VersionCommand};
use crate::config::{KmsConfig, CONFIG_ENV_VAR, CONFIG_FILE_NAME};
use abscissa_core::{Command, Configurable, Runnable};
use clap::Parser;
use std::{env, path::PathBuf};
#[derive(Command, Debug, Parser, Runnable)]
pub enum KmsCommand {
Init(InitCommand),
#[cfg(feature = "ledger")]
#[clap(subcommand)]
Ledger(LedgerCommand),
#[cfg(feature = "softsign")]
#[clap(subcommand)]
Softsign(SoftsignCommand),
Start(StartCommand),
Version(VersionCommand),
#[cfg(feature = "yubihsm")]
#[clap(subcommand)]
Yubihsm(YubihsmCommand),
}
impl KmsCommand {
pub fn verbose(&self) -> bool {
match self {
KmsCommand::Start(run) => run.verbose,
#[cfg(feature = "yubihsm")]
KmsCommand::Yubihsm(yubihsm) => yubihsm.verbose(),
_ => false,
}
}
}
impl Configurable<KmsConfig> for KmsCommand {
fn config_path(&self) -> Option<PathBuf> {
let config = match self {
KmsCommand::Start(start) => start.config.as_ref(),
#[cfg(feature = "yubihsm")]
KmsCommand::Yubihsm(yubihsm) => yubihsm.config_path(),
#[cfg(feature = "ledger")]
KmsCommand::Ledger(ledger) => ledger.config_path(),
_ => return None,
};
let path = config
.cloned()
.or_else(|| env::var(CONFIG_ENV_VAR).ok().map(PathBuf::from))
.unwrap_or_else(|| PathBuf::from(CONFIG_FILE_NAME));
Some(path)
}
}