lib/leap_cli/commands/user.rb in leap_cli-1.5.6 vs lib/leap_cli/commands/user.rb in leap_cli-1.6.2
- old
+ new
@@ -1,6 +1,5 @@
-require 'gpgme'
#
# perhaps we want to verify that the key files are actually the key files we expect.
# we could use 'file' for this:
#
@@ -73,12 +72,14 @@
end
if `which ssh-add`.strip.any?
`ssh-add -L 2> /dev/null`.split("\n").compact.each do |line|
key = SshKey.load(line)
- key.comment = 'ssh-agent'
- ssh_keys << key unless ssh_keys.include?(key)
+ if key
+ key.comment = 'ssh-agent'
+ ssh_keys << key unless ssh_keys.include?(key)
+ end
end
end
ssh_keys.compact!
assert! ssh_keys.any?, 'Sorry, could not find any SSH public key for you. Have you run ssh-keygen?'
@@ -96,16 +97,23 @@
#
# let the the user choose among the gpg public keys that we encounter, or just pick the key if there is only one.
#
def pick_pgp_key
+ begin
+ return unless `which gpg`.strip.any?
+ require 'gpgme'
+ rescue LoadError
+ return
+ end
+
secret_keys = GPGME::Key.find(:secret)
if secret_keys.empty?
log "Skipping OpenPGP setup because I could not find any OpenPGP keys for you"
return nil
end
- assert_bin! 'gpg'
+ secret_keys.select!{|key| !key.expired}
if secret_keys.length > 1
key_index = numbered_choice_menu('Choose your OpenPGP public key', secret_keys) do |key, i|
key_info = key.to_s.split("\n")[0..1].map{|line| line.sub(/^\s*(sec|uid)\s*/,'')}.join(' -- ')
say("#{i+1}. #{key_info}")
\ No newline at end of file