rusty_vault 0.2.1

RustyVault is a powerful identity-based secrets management software, providing features such as cryptographic key management, encryption as a service, public key cryptography, certificates management, identity credentials management and so forth. RustyVault's RESTful API is designed to be fully compatible with Hashicorp Vault.
Documentation
use clap::{Parser, Subcommand};
use sysexits::ExitCode;

use super::{
    operator_init,
    operator_seal,
    operator_unseal,
};

use crate::{EXIT_CODE_INSUFFICIENT_PARAMS, cli::command::CommandExecutor};

#[derive(Parser)]
#[command(
    author,
    version,
    about = "Perform operator-specific tasks",
    long_about = r#"This command groups subcommands for operators interacting with RustyVault.
Most users will not need to interact with these commands.

Initialize a new RustyVault server:

  $ rvault operator init

Unseals the RustyVault server:

  $ rvault operator unseal

Seals the RustyVault server:

  $ rvault operator seal"#
)]
pub struct Operator {
    #[command(subcommand)]
    command: Option<Commands>,
}

#[derive(Subcommand)]
pub enum Commands {
    Init(operator_init::Init),
    Seal(operator_seal::Seal),
    Unseal(operator_unseal::Unseal),
}

impl Commands {
    pub fn execute(&mut self) -> ExitCode {
        return match self {
            Commands::Init(init) => init.execute(),
            Commands::Seal(seal) => seal.execute(),
            Commands::Unseal(unseal) => unseal.execute(),
        }
    }
}

impl Operator {
    #[inline]
    pub fn execute(&mut self) -> ExitCode {
        if let Some(ref mut cmd) = &mut self.command {
            return cmd.execute();
        }

        EXIT_CODE_INSUFFICIENT_PARAMS
    }
}