| 1 |
//! Command-line parser for `sq pki lookup`. |
| 2 |
|
| 3 |
use clap::Parser; |
| 4 |
|
| 5 |
use crate::cli::examples; |
| 6 |
use examples::Action; |
| 7 |
use examples::Actions; |
| 8 |
|
| 9 |
use super::CertificationNetworkArg; |
| 10 |
use super::GossipArg; |
| 11 |
use super::RequiredTrustAmountArg; |
| 12 |
use super::ShowPathsArg; |
| 13 |
use super::UnusableArg; |
| 14 |
|
| 15 |
use crate::cli::types::userid_designator; |
| 16 |
use crate::cli::types::UserIDDesignators; |
| 17 |
|
| 18 |
/// Lookup the certificates associated with a User ID |
| 19 |
/// |
| 20 |
/// Identifies authenticated bindings (User ID and certificate |
| 21 |
/// pairs) where the User ID matches the specified User ID. |
| 22 |
/// |
| 23 |
/// An error is return if no binding could be authenticated to the |
| 24 |
/// specified level (by default: fully authenticated, i.e., a trust |
| 25 |
/// amount of 120). |
| 26 |
/// |
| 27 |
/// If a binding could be partially authenticated (i.e., its trust |
| 28 |
/// amount is greater than 0), then the binding is displayed, even |
| 29 |
/// if the trust is below the specified threshold. |
| 30 |
#[derive(Parser, Debug)] |
| 31 |
#[clap( |
| 32 |
name = "lookup", |
| 33 |
after_help = EXAMPLES, |
| 34 |
)] |
| 35 |
pub struct Command { |
| 36 |
#[command(flatten)] |
| 37 |
pub userid: UserIDDesignators< |
| 38 |
userid_designator::PlainByArgs, |
| 39 |
userid_designator::OneValueNoLinting, |
| 40 |
Documentation>, |
| 41 |
|
| 42 |
#[command(flatten)] |
| 43 |
pub show_paths: ShowPathsArg, |
| 44 |
|
| 45 |
#[command(flatten)] |
| 46 |
pub gossip: GossipArg, |
| 47 |
|
| 48 |
#[command(flatten)] |
| 49 |
pub unusable: UnusableArg, |
| 50 |
|
| 51 |
#[command(flatten)] |
| 52 |
pub certification_network: CertificationNetworkArg, |
| 53 |
|
| 54 |
#[command(flatten)] |
| 55 |
pub trust_amount: RequiredTrustAmountArg, |
| 56 |
} |
| 57 |
|
| 58 |
/// Documentation for the user ID designators. |
| 59 |
#[derive(Debug, Clone)] |
| 60 |
pub struct Documentation(()); |
| 61 |
|
| 62 |
impl userid_designator::Documentation for Documentation { |
| 63 |
fn help(typ: userid_designator::UserIDDesignatorType, |
| 64 |
_plain: bool, |
| 65 |
semantics: userid_designator::UserIDDesignatorSemantics) |
| 66 |
-> (&'static str, Option<&'static str>) |
| 67 |
{ |
| 68 |
use userid_designator::UserIDDesignatorType::*; |
| 69 |
match (typ, semantics) { |
| 70 |
(UserID, _) => { |
| 71 |
("\ |
| 72 |
Find certificates that can be authenticated for the specified user ID", |
| 73 |
Some("\ |
| 74 |
Find certificates that can be authenticated for the specified user ID |
| 75 |
|
| 76 |
The specified user ID does not need to be self signed.")) |
| 77 |
} |
| 78 |
(Email, _) => { |
| 79 |
("\ |
| 80 |
Find certificates that can be authenticated for the specified email \ |
| 81 |
address", |
| 82 |
Some("\ |
| 83 |
Find certificates that can be authenticated for the specified email \ |
| 84 |
address |
| 85 |
|
| 86 |
A certificate is returned if a user ID with the specified email \ |
| 87 |
address can be authenticated for that certificate. |
| 88 |
|
| 89 |
To search for a certificate with a user ID containing just \ |
| 90 |
the specified email address, use `--userid <EMAIL>`.")) |
| 91 |
} |
| 92 |
(Name, _) => { |
| 93 |
("\ |
| 94 |
Find certificates that can be authenticated for the specified display \ |
| 95 |
name", |
| 96 |
Some("\ |
| 97 |
Find certificates that can be authenticated for the specified display \ |
| 98 |
name |
| 99 |
|
| 100 |
A certificate is returned if a user ID with the specified display \ |
| 101 |
name can be authenticated for that certificate. |
| 102 |
|
| 103 |
To search for a certificate with a user ID containing just \ |
| 104 |
the specified display name, use `--userid NAME`.")) |
| 105 |
} |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
const EXAMPLES: Actions = Actions { |
| 111 |
actions: &[ |
| 112 |
// Link Alice's certificate. |
| 113 |
Action::setup().command(&[ |
| 114 |
"sq", "pki", "link", "add", |
| 115 |
"--cert", "EB28F26E2739A4870ECC47726F0073F60FD0CBF0", |
| 116 |
"--all", |
| 117 |
]).build(), |
| 118 |
|
| 119 |
Action::example().comment( |
| 120 |
"Lookup certificates that can be authenticated for the given user ID.", |
| 121 |
).command(&[ |
| 122 |
"sq", "pki", "lookup", |
| 123 |
"--userid", "Alice <[email protected]>" |
| 124 |
]).build(), |
| 125 |
|
| 126 |
Action::example().comment( |
| 127 |
"Lookup certificates that have a user ID with the specified email \ |
| 128 |
address, and that user ID can be authenticated.", |
| 129 |
).command(&[ |
| 130 |
"sq", "pki", "lookup", |
| 131 |
"--email", "[email protected]", |
| 132 |
]).build(), |
| 133 |
], |
| 134 |
}; |
| 135 |
test_examples!(sq_pki_lookup, EXAMPLES); |