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