From c89dd82d263286685dd97e97c2542a129f023b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Mon, 4 Jul 2022 10:24:02 +0000 Subject: [PATCH] enh: print_public_key: better formatter --- lib/perl/OVH/Bastion/ssh.inc | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/perl/OVH/Bastion/ssh.inc b/lib/perl/OVH/Bastion/ssh.inc index c2fed30..759bc71 100644 --- a/lib/perl/OVH/Bastion/ssh.inc +++ b/lib/perl/OVH/Bastion/ssh.inc @@ -760,24 +760,47 @@ sub print_public_key { } if ($key->{'info'}) { - osh_info(Term::ANSIColor::colored("info: " . $key->{'info'}, 'cyan')); + my $info = $key->{'info'}; + + # parse data from 'info' and print it nicely + my ($name) = $info =~ m{NAME="([^"]+)}; + osh_info(Term::ANSIColor::colored("name: " . $name, 'cyan')); + + my ($by) = $info =~ m{ADDED_BY=(\S+)}; + my ($when) = $info =~ m{DATETIME=(\S+)}; + my ($version) = $info =~ m{VERSION=(\S+)}; + my ($session) = $info =~ m{UNIQID=(\S+)}; + osh_info( + Term::ANSIColor::colored( + sprintf( + "info: added by %s at %s in session %s running v%s", + $by || '(?)', + $when || '(?)', + $session || '(?)', + $version || '(?)' + ), + 'cyan' + ) + ); } + if ($key->{'isPiv'}) { osh_info( Term::ANSIColor::colored( "PIV: " . "TouchPolicy=" . $key->{'pivInfo'}{'Yubikey'}{'TouchPolicy'} - . ", PinPolicy=" + . " PinPolicy=" . $key->{'pivInfo'}{'Yubikey'}{'PinPolicy'} - . ", SerialNo=" + . " SerialNo=" . $key->{'pivInfo'}{'Yubikey'}{'SerialNumber'} - . ", Firmware=" + . " Firmware=" . $key->{'pivInfo'}{'Yubikey'}{'FirmwareVersion'}, 'magenta' ) ); } + osh_info( sprintf( "%s%s (%s-%d) [%s]%s",