Files
husk-milter/src/cli/cli_args.rs
T
Malte Meiboom 7688e6c5a2 Add signkey create
- Add a CLI command for creating a new signing key.
2026-06-19 12:27:43 +02:00

259 lines
5.4 KiB
Rust

use clap::Parser;
use clap::Subcommand;
#[derive(Parser, Debug)]
#[clap(
name = "Husk milter",
about = "Encrypting milter.",
arg_required_else_help = true,
)]
pub struct CliArgs {
#[clap(
long, short,
global = true,
help = "Configuration file.",
)]
pub config: Option<String>,
#[clap(
long,
global = true,
help = "Certificate store (SEQUOIA_HOME).",
)]
pub home: Option<String>,
#[clap(subcommand)]
pub subcommand: HuskSubcommands,
}
// Subcommands Level 1
#[derive(Debug, Subcommand)]
pub enum HuskSubcommands {
Daemon(DaemonCommand),
Introducer(IntroducerCommand),
Locals(LocalsCommand),
Signkey(SignkeyCommand),
}
// Daemon subcommands
#[derive(Parser, Debug)]
#[clap(
name = "daemon",
about = "Manage milter daemon.",
subcommand_required = true,
arg_required_else_help = true,
disable_colored_help = true,
disable_version_flag = true,
)]
pub struct DaemonCommand {
#[clap(subcommand)]
pub subcommand: DaemonSubcommand,
}
#[derive(Debug, Subcommand)]
pub enum DaemonSubcommand {
Start,
Stop,
Status
}
// Introducer subcommands
#[derive(Parser, Debug)]
#[clap(
name = "introducer",
about = "Manage introducers.",
subcommand_required = true,
arg_required_else_help = true,
disable_colored_help = true,
disable_version_flag = true,
)]
pub struct IntroducerCommand {
#[clap(subcommand)]
pub subcommand: IntroducerSubcommand,
}
#[derive(Debug, Subcommand)]
pub enum IntroducerSubcommand {
Add(IntroducerAddCommand),
Remove(IntroducerRemoveCommand),
#[clap(
about = "List introducers."
)]
List
}
#[derive(Parser, Debug)]
#[clap(
name = "introducer",
about = "Add introducers.",
)]
pub struct IntroducerAddCommand {
#[clap(
long = "cert",
help = "Certificate to declare as introducer.",
conflicts_with = "cert_file",
value_name = "FINGERPRINT",
)]
pub cert: Option<String>,
#[clap(
long = "cert-file",
help = "Import certificate from <FILE> and declare it as introducer.",
value_name = "FILE",
conflicts_with = "cert"
)]
pub cert_file: Option<String>,
#[clap(
long = "domains",
help = "Domains this certificate introduces.",
required = true,
num_args = 1..,
value_delimiter = ' '
)]
pub domains: Vec<String>,
}
#[derive(Parser, Debug)]
#[clap(
name = "introducer",
about = "Remove introducers.",
)]
pub struct IntroducerRemoveCommand {
#[clap(
long = "cert",
help = "Certificate to be removed as introducer.",
value_name = "FINGERPRINT",
)]
pub cert: String,
#[clap(
long = "demote",
help = "Remove introducing capabilities, but keep certificate authenticated.",
default_value_t = false,
)]
pub demote: bool,
}
// Local subcommands
#[derive(Parser, Debug)]
#[clap(
name = "local",
about = "Manage manually added certificates.",
subcommand_required = true,
arg_required_else_help = true,
disable_colored_help = true,
disable_version_flag = true,
)]
pub struct LocalsCommand {
#[clap(subcommand)]
pub subcommand: LocalsSubcommand,
}
#[derive(Debug, Subcommand)]
pub enum LocalsSubcommand {
Add(LocalsAddCommand),
Remove(LocalsRemoveCommand),
#[clap(
about = "List locals."
)]
List
}
#[derive(Parser, Debug)]
#[clap(
name = "locals_add",
about = "Add an authenticated certificate.",
)]
pub struct LocalsAddCommand {
#[clap(
long,
help = "Import a certificate from <FILE>.",
value_name = "FILE",
)]
pub cert_file: String,
}
#[derive(Parser, Debug)]
#[clap(
name = "locals_remove",
about = "Disable a Certificate.",
)]
pub struct LocalsRemoveCommand {
#[clap(
long = "cert",
help = "Certificate to be removed.",
value_name = "FINGERPRINT",
)]
pub cert: String,
}
// Signkey subcommands
#[derive(Parser, Debug)]
#[clap(
name = "signkey",
about = "Manage the signing key.",
subcommand_required = true,
arg_required_else_help = true,
disable_colored_help = true,
disable_version_flag = true,
)]
pub struct SignkeyCommand {
#[clap(subcommand)]
pub subcommand: SignkeySubcommand,
}
#[derive(Debug, Subcommand)]
pub enum SignkeySubcommand {
Set(SignkeySetCommand),
Create(SignkeyCreateCommand),
#[clap(
about = "Show the fingerprint of the signing key."
)]
Show,
#[clap(
about = "Print the certificate of the signing key."
)]
Dump,
}
#[derive(Parser, Debug)]
#[clap(
about = "Set a new signing key.",
)]
pub struct SignkeySetCommand {
#[clap(
long,
help = "Load a new signing key from <FILE>.",
value_name = "FILE",
conflicts_with = "cert"
)]
pub cert_file: Option<String>,
#[clap(
long = "cert",
help = "Certificate to declare as signing key.",
conflicts_with = "cert_file",
value_name = "FINGERPRINT",
)]
pub cert: Option<String>,
}
#[derive(Parser, Debug)]
#[clap(
about = "Create a new signing key.",
)]
pub struct SignkeyCreateCommand {
#[clap(
long,
help = "Set the userid of the new key.",
value_name = "USERID",
default_value = "Husk signing key",
)]
pub userid: String,
}