use crate::{cert::CertificateAuthority, config::AppConfig};
use anyhow::Result;
use clap::Subcommand;
#[derive(Subcommand)]
pub enum CaCommands {
Install {
#[arg(short, long)]
yes: bool,
#[arg(short = 'n', long)]
dry_run: bool,
},
Uninstall {
#[arg(short, long)]
yes: bool,
#[arg(short = 'n', long)]
dry_run: bool,
},
Status,
}
pub struct CaHandler {
config: AppConfig,
}
impl CaHandler {
pub fn new(config: AppConfig) -> Self {
Self { config }
}
pub async fn handle(&self, command: &CaCommands) -> Result<()> {
let ca = CertificateAuthority::new(&self.config.tls.cert_dir).await?;
match command {
CaCommands::Install { yes, dry_run } => {
ca.install_root_certificate(*yes, *dry_run).await
}
CaCommands::Uninstall { yes, dry_run } => {
ca.remove_root_certificate(*yes, *dry_run).await
}
CaCommands::Status => ca.check_root_certificate_status().await,
}
}
}