opgpcard: Add a parameter '--key-only' to the ssh command.
This outputs only one line, containing the ssh public key string, which is useful in scripts (e.g. in CI).
This commit is contained in:
parent
8b9e921db7
commit
c460904925
2 changed files with 22 additions and 8 deletions
|
@ -22,6 +22,9 @@ pub struct SshCommand {
|
||||||
help = "Identifier of the card to use"
|
help = "Identifier of the card to use"
|
||||||
)]
|
)]
|
||||||
pub ident: Option<String>,
|
pub ident: Option<String>,
|
||||||
|
|
||||||
|
#[clap(long, help = "Only print the ssh public key")]
|
||||||
|
pub key_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_ssh(
|
pub fn print_ssh(
|
||||||
|
@ -31,6 +34,8 @@ pub fn print_ssh(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut output = output::Ssh::default();
|
let mut output = output::Ssh::default();
|
||||||
|
|
||||||
|
output.key_only(command.key_only);
|
||||||
|
|
||||||
let ident = command.ident;
|
let ident = command.ident;
|
||||||
|
|
||||||
let backend = pick_card_for_reading(ident)?;
|
let backend = pick_card_for_reading(ident)?;
|
||||||
|
|
|
@ -8,12 +8,17 @@ use crate::{OutputBuilder, OutputFormat, OutputVariant, OutputVersion};
|
||||||
|
|
||||||
#[derive(Debug, Default, Serialize)]
|
#[derive(Debug, Default, Serialize)]
|
||||||
pub struct Ssh {
|
pub struct Ssh {
|
||||||
|
key_only: bool, // only print ssh public key, in text mode
|
||||||
ident: String,
|
ident: String,
|
||||||
authentication_key_fingerprint: Option<String>,
|
authentication_key_fingerprint: Option<String>,
|
||||||
ssh_public_key: Option<String>,
|
ssh_public_key: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ssh {
|
impl Ssh {
|
||||||
|
pub fn key_only(&mut self, ssh_key_only: bool) {
|
||||||
|
self.key_only = ssh_key_only;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ident(&mut self, ident: String) {
|
pub fn ident(&mut self, ident: String) {
|
||||||
self.ident = ident;
|
self.ident = ident;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +32,7 @@ impl Ssh {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text(&self) -> Result<String, OpgpCardError> {
|
fn text(&self) -> Result<String, OpgpCardError> {
|
||||||
|
if !self.key_only {
|
||||||
let mut s = format!("OpenPGP card {}\n\n", self.ident);
|
let mut s = format!("OpenPGP card {}\n\n", self.ident);
|
||||||
|
|
||||||
if let Some(fp) = &self.authentication_key_fingerprint {
|
if let Some(fp) = &self.authentication_key_fingerprint {
|
||||||
|
@ -37,6 +43,9 @@ impl Ssh {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(s)
|
Ok(s)
|
||||||
|
} else {
|
||||||
|
Ok(self.ssh_public_key.clone().unwrap_or("".to_string()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn v1(&self) -> Result<SshV0, OpgpCardError> {
|
fn v1(&self) -> Result<SshV0, OpgpCardError> {
|
||||||
|
|
Loading…
Reference in a new issue