Add filters to sq pki link list.

- Fixes #210.
This commit is contained in:
Justus Winter 2024-10-22 11:11:25 +02:00
parent d4a8d862ee
commit d76a856f0b
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 38 additions and 3 deletions

View File

@ -9,6 +9,7 @@ use crate::cli::types::UserIDDesignators;
use crate::cli::types::userid_designator;
use crate::cli::types::Expiration;
use crate::cli::types::TrustAmount;
use crate::cli::types::cert_designator::*;
#[derive(Parser, Debug)]
#[clap(
@ -620,6 +621,11 @@ retracted.
after_help = LIST_EXAMPLES,
)]
pub struct ListCommand {
#[command(flatten)]
pub certs: CertDesignators<CertUserIDEmailDomainGrepArgs,
NoPrefix,
OptionalValue>,
#[clap(
long = "ca",
required = false,
@ -649,6 +655,14 @@ with the email address alice@example.org.",
"sq", "pki", "link", "list",
],
}),
Action::Example(Example {
comment: "List all links in the example.org domain.",
command: &[
"sq", "pki", "link", "list",
"--domain=example.org",
],
}),
],
};
test_examples!(sq_pki_link_list, LIST_EXAMPLES);

View File

@ -1,10 +1,13 @@
use std::time::Duration;
use std::{
sync::Arc,
time::Duration,
};
use sequoia_openpgp as openpgp;
use openpgp::Result;
use sequoia_cert_store as cert_store;
use cert_store::Store;
use cert_store::{LazyCert, Store};
use crate::Sq;
use crate::commands::active_certification;
@ -179,7 +182,24 @@ pub fn list(sq: Sq, c: link::ListCommand)
let cert_store = sq.cert_store_or_else()?;
let mut dirty = false;
for cert in cert_store.certs() {
let (certs, errors) = if c.certs.is_empty() {
(cert_store.certs(), Vec::new())
} else {
let (c, e) = sq.resolve_certs(&c.certs, 0)?;
(Box::new(c.into_iter().map(|c| Arc::new(LazyCert::from(c))))
as Box<dyn Iterator<Item=Arc<LazyCert<'_>>>>,
e)
};
for error in errors.iter() {
crate::print_error_chain(error);
}
if ! errors.is_empty() {
return Err(anyhow::anyhow!("Failed to resolve certificates"));
}
for cert in certs {
let cert = if let Ok(cert) = cert.to_cert() {
cert
} else {
@ -206,6 +226,7 @@ pub fn list(sq: Sq, c: link::ListCommand)
.unwrap_or((0, sequoia_wot::FULLY_TRUSTED as u8));
if c.ca && depth == 0 {
// Only show CAs.
continue;
}