1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
mod keygen;
mod start;
mod version;
#[cfg(feature = "yubihsm")]
mod yubihsm;
#[cfg(feature = "yubihsm")]
pub use self::yubihsm::YubihsmCommand;
#[cfg(feature = "ledgertm")]
mod ledger;
#[cfg(feature = "ledgertm")]
pub use self::ledger::LedgerCommand;
pub use self::{keygen::KeygenCommand, start::StartCommand, version::VersionCommand};
use crate::config::{KmsConfig, CONFIG_ENV_VAR, CONFIG_FILE_NAME};
use abscissa::{Command, Configurable, Help, Runnable};
use std::{env, path::PathBuf};
#[derive(Command, Debug, Options, Runnable)]
pub enum KmsCommand {
#[options(help = "show help for a command")]
Help(Help<Self>),
#[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),
#[cfg(feature = "ledgertm")]
#[options(help = "subcommands for Ledger")]
Ledger(LedgerCommand),
}
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(run) => run.config.as_ref(),
#[cfg(feature = "yubihsm")]
KmsCommand::Yubihsm(yubihsm) => yubihsm.config_path(),
#[cfg(feature = "ledgertm")]
KmsCommand::Ledger(ledger) => ledger.config_path(),
_ => return None,
};
let path = PathBuf::from(
config
.cloned()
.or_else(|| env::var(CONFIG_ENV_VAR).ok())
.unwrap_or_else(|| CONFIG_FILE_NAME.to_owned()),
);
Some(path)
}
}