Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Upgrade to abscissa v0.1.0-pre.2 (closes #236)
Browse files Browse the repository at this point in the history
This should be close to the final prerelease, and addresses a number of
issues:

- Better command-line option parsing UX
- Improved logging subsystem
- Eliminates many unnecessary dependencies
  • Loading branch information
tony-iqlusion committed Jun 18, 2019
1 parent 20172d9 commit 31d5c87
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 286 deletions.
160 changes: 22 additions & 138 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = [".", "tendermint-rs"]
circle-ci = { repository = "tendermint/kms" }

[dependencies.abscissa]
version = "0.1.0-pre.1"
version = "0.1.0-pre.2"
default-features = false
features = ["application", "signals", "secrets", "time"]

Expand Down
27 changes: 0 additions & 27 deletions src/commands/help.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/commands/keygen.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::keyring::SecretKeyEncoding;
use abscissa::Runnable;
use abscissa::{Command, Runnable};
use signatory::{ed25519, Encode};
use std::{env, process};

/// Options for the `keygen` command
#[derive(Debug, Default, Options)]
#[derive(Command, Debug, Default, Options)]
pub struct KeygenCommand {
#[options(free)]
#[options(free, help = "path where generated key should be created")]
output_paths: Vec<String>,
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl LedgerCommand {
}

/// `ledger init` subcommand
#[derive(Debug, Options)]
#[derive(Command, Debug, Options)]
pub struct InitCommand {
/// config file path
#[options(short = "c", long = "config")]
Expand Down
9 changes: 3 additions & 6 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Subcommands of the `tmkms` command-line application
mod help;
mod keygen;
mod start;
mod version;
Expand All @@ -13,19 +12,17 @@ mod ledger;
#[cfg(feature = "ledgertm")]
pub use self::ledger::LedgerCommand;

pub use self::{
help::HelpCommand, keygen::KeygenCommand, start::StartCommand, version::VersionCommand,
};
pub use self::{keygen::KeygenCommand, start::StartCommand, version::VersionCommand};
use crate::config::{KmsConfig, CONFIG_ENV_VAR, CONFIG_FILE_NAME};
use abscissa::{Command, Configurable, Runnable};
use abscissa::{Command, Configurable, Help, Runnable};
use std::{env, path::PathBuf};

/// Subcommands of the KMS command-line application
#[derive(Command, Debug, Options, Runnable)]
pub enum KmsCommand {
/// `help` subcommand
#[options(help = "show help for a command")]
Help(HelpCommand),
Help(Help<Self>),

/// `keygen` subcommand
#[options(help = "generate a new software signing key")]
Expand Down
20 changes: 10 additions & 10 deletions src/commands/start.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
//! Start the KMS
use crate::{chain, client::Client, config::ValidatorConfig, prelude::*};
use std::{
process,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
thread, time,
use abscissa::Command;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use std::{process, thread, time};

/// The `start` command
#[derive(Debug, Options)]
#[derive(Command, Debug, Options)]
pub struct StartCommand {
/// Path to configuration file
#[options(short = "c", long = "config")]
#[options(short = "c", long = "config", help = "path to tmkms.toml")]
pub config: Option<String>,

/// Print debugging information
#[options(short = "v", long = "verbose")]
#[options(short = "v", long = "verbose", help = "enable verbose debug logging")]
pub verbose: bool,
}

Expand Down
6 changes: 3 additions & 3 deletions src/commands/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#![allow(clippy::never_loop)]

use super::KmsCommand;
use abscissa::{Command as CommandTrait, Runnable};
use abscissa::{Command, Runnable};

/// The `version` subcommand
#[derive(Debug, Default, Options)]
#[derive(Command, Debug, Default, Options)]
pub struct VersionCommand {}

impl Runnable for VersionCommand {
/// Print version message
fn run(&self) {
KmsCommand::print_package_info();
println!("{} {}", KmsCommand::name(), KmsCommand::version());
}
}
10 changes: 6 additions & 4 deletions src/commands/yubihsm/detect.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use abscissa::Runnable;
//! Detect YubiHSM2s connected via USB
use abscissa::{Command, Runnable};
use std::process;
use yubihsm::connector::usb::Devices;

/// The `yubihsm detect` subcommand
#[derive(Debug, Default, Options)]
#[derive(Command, Debug, Default, Options)]
pub struct DetectCommand {
/// Path to configuration file
#[options(short = "c", long = "config")]
#[options(short = "c", long = "config", help = "path to tmkms.toml")]
pub config: Option<String>,

/// Print debugging information
#[options(short = "v", long = "verbose")]
#[options(short = "v", long = "verbose", help = "enable verbose debug logging")]
pub verbose: bool,
}

Expand Down
24 changes: 0 additions & 24 deletions src/commands/yubihsm/help.rs

This file was deleted.

14 changes: 10 additions & 4 deletions src/commands/yubihsm/keys/export.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Create encrypted backups of YubiHSM2 keys
use super::*;
use abscissa::{Command, Runnable};
use std::{fs::OpenOptions, io::Write, os::unix::fs::OpenOptionsExt, path::PathBuf, process};
Expand All @@ -7,19 +9,23 @@ use subtle_encoding::base64;
#[derive(Command, Debug, Default, Options)]
pub struct ExportCommand {
/// Path to configuration file
#[options(short = "c", long = "config")]
#[options(short = "c", long = "config", help = "path to tmkms.toml")]
pub config: Option<String>,

/// ID of the key to export
#[options(short = "i", long = "id")]
#[options(short = "i", long = "id", help = "key to export in encrypted form")]
pub key_id: u16,

/// ID of the wrap key to encrypt the exported key under
#[options(short = "w", long = "wrapkey")]
#[options(
short = "w",
long = "wrapkey",
help = "wrap key to encrypt exported key"
)]
pub wrap_key_id: Option<u16>,

/// Path to write the resulting file to
#[options(free)]
#[options(free, help = "path where ciphertext of exported key will be written")]
pub path: PathBuf,
}

Expand Down
30 changes: 22 additions & 8 deletions src/commands/yubihsm/keys/generate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Generate a new key within the YubiHSM2
use super::*;
use abscissa::{Command, Runnable};
use chrono::{SecondsFormat, Utc};
Expand All @@ -15,35 +17,47 @@ use tendermint::PublicKey;
#[derive(Command, Debug, Default, Options)]
pub struct GenerateCommand {
/// Path to configuration file
#[options(short = "c", long = "config")]
#[options(short = "c", long = "config", help = "path to tmkms.toml")]
pub config: Option<String>,

/// Label for generated key(s)
#[options(short = "l", long = "label")]
#[options(short = "l", long = "label", help = "label for generated key")]
pub label: Option<String>,

/// Bech32 prefix to use when displaying key
#[options(short = "p", long = "prefix")]
#[options(
short = "p",
long = "prefix",
help = "bech32 prefix to display generated key with"
)]
pub bech32_prefix: Option<String>,

/// Type of key to generate (default 'ed25519')
#[options(short = "t")]
#[options(short = "t", help = "type of key to generate (default: ed25519)")]
pub key_type: Option<String>,

/// Mark this key as non-exportable
#[options(no_short, long = "non-exportable")]
#[options(no_short, long = "non-exportable", help = "mark key as non-exportable")]
pub non_exportable: bool,

/// Create an encrypted backup of this key in the given file
#[options(short = "b", long = "backup")]
#[options(
short = "b",
long = "backup",
help = "path where encrypted backup should be written"
)]
pub backup_file: Option<PathBuf>,

/// Key ID of the wrap key to use when creating a backup
#[options(short = "w", long = "wrapkey")]
#[options(
short = "w",
long = "wrapkey",
help = "ID of wrap key to encrypt exported key"
)]
pub wrap_key_id: Option<yubihsm::object::Id>,

/// Key ID to generate
#[options(free)]
#[options(free, help = "key ID to generate")]
key_ids: Vec<u16>,
}

Expand Down
23 changes: 0 additions & 23 deletions src/commands/yubihsm/keys/help.rs

This file was deleted.

14 changes: 7 additions & 7 deletions src/commands/yubihsm/keys/import.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Import keys
//! Import keys either from encrypted backups or existing plaintext keys
use super::*;
use abscissa::{Command, Runnable};
Expand All @@ -12,27 +12,27 @@ use yubihsm::object;
#[derive(Command, Debug, Default, Options)]
pub struct ImportCommand {
/// Path to configuration file
#[options(short = "c", long = "config")]
#[options(short = "c", long = "config", help = "path to tmkms.toml")]
pub config: Option<String>,

/// ID of the key to import (if applicable)
#[options(short = "i", long = "id")]
#[options(short = "i", long = "id", help = "key ID to import")]
pub key_id: Option<u16>,

/// ID of the wrap key the original key was encrypted with
#[options(short = "w", long = "wrapkey")]
#[options(short = "w", long = "wrapkey", help = "wrap key to decrypt with")]
pub wrap_key_id: Option<u16>,

/// Type of key to import (either `wrap` or `priv_validator`, default `wrap`)
#[options(short = "t")]
#[options(short = "t", help = "type of key to import (wrap or priv_validator)")]
pub key_type: Option<String>,

/// Label for imported key (only applicable to `priv_validator` keys)
#[options(short = "l", long = "label")]
#[options(short = "l", long = "label", help = "label for priv_validator keys")]
pub label: Option<String>,

/// Path to the key to import
#[options(free)]
#[options(free, help = "path to key to import")]
pub path: PathBuf,
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/yubihsm/keys/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! List keys
//! List keys inside the YubiHSM2
use abscissa::{Command, Runnable};
use std::process;
Expand All @@ -8,7 +8,7 @@ use tendermint::PublicKey;
#[derive(Command, Debug, Default, Options)]
pub struct ListCommand {
/// Path to configuration file
#[options(short = "c", long = "config")]
#[options(short = "c", long = "config", help = "path to tmkms.toml")]
pub config: Option<String>,
}

Expand Down
10 changes: 5 additions & 5 deletions src/commands/yubihsm/keys/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! YubiHSM2 key management commands
mod export;
mod generate;
mod help;
mod import;
mod list;

use self::{
export::ExportCommand, generate::GenerateCommand, help::HelpCommand, import::ImportCommand,
list::ListCommand,
export::ExportCommand, generate::GenerateCommand, import::ImportCommand, list::ListCommand,
};
use abscissa::{Command, Runnable};
use abscissa::{Command, Help, Runnable};

/// Default key type to generate
pub const DEFAULT_KEY_TYPE: &str = "ed25519";
Expand All @@ -32,7 +32,7 @@ pub enum KeysCommand {
Generate(GenerateCommand),

#[options(help = "show help for the 'yubihsm keys' subcommand")]
Help(HelpCommand),
Help(Help<Self>),

#[options(help = "import validator signing key for the 'yubihsm keys' subcommand")]
Import(ImportCommand),
Expand Down
Loading

0 comments on commit 31d5c87

Please sign in to comment.