43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
//! introducer add subcommand
|
|
|
|
use anyhow::Result;
|
|
use sequoia_cert_store::Store;
|
|
use sequoia_openpgp::cert::ValidCert;
|
|
use sequoia_openpgp::{Fingerprint, KeyHandle};
|
|
|
|
use crate::cli::cli_args::IntroducerAddCommand;
|
|
use crate::commands::CommandError;
|
|
use crate::config::HuskConfigContainer;
|
|
use crate::types::husk_context::HuskContext;
|
|
use crate::types::introducer::Introducer;
|
|
|
|
pub async fn dispatch(cmd: IntroducerAddCommand, config: HuskConfigContainer) -> Result<()> {
|
|
println!("add");
|
|
println!(" {:?}", cmd.cert);
|
|
println!(" {:?}", cmd.domains);
|
|
|
|
let context = HuskContext::new(&config.into())?;
|
|
let policy = &context.policy;
|
|
let cert_store = &context.cert_store;
|
|
|
|
// Get the certificate
|
|
let fpr = Fingerprint::from_hex(&cmd.cert)?;
|
|
let certs = cert_store.lookup_by_cert(&KeyHandle::try_from(&fpr)?)
|
|
.map_err(|_| CommandError::CertNotFound(fpr.clone()))?;
|
|
|
|
let certs: Vec<ValidCert> = certs.iter()
|
|
.filter_map(|c|
|
|
c.with_policy(policy, None).ok()
|
|
)
|
|
.collect();
|
|
|
|
if let Some(cert) = certs.first() {
|
|
Introducer::create(&context, cert, cmd.domains)?;
|
|
} else {
|
|
return Err(CommandError::CertNotUsable(fpr).into());
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|