aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2014-10-29 17:53:57 -0700
committerelijah <elijah@riseup.net>2014-10-29 17:53:57 -0700
commit6157137a044d210b8a75250df46658d71374d8e0 (patch)
tree5d7fe618bb1f40b7ec952ad792301b876fc1e094
parent04299749fcd7ce47de5c7da0afca3658169dd0ee (diff)
downloadleap_cli-6157137a044d210b8a75250df46658d71374d8e0.tar.gz
leap_cli-6157137a044d210b8a75250df46658d71374d8e0.tar.bz2
fixed bugs with add-user: skip keys we can't understand, don't die if gpg can't be loaded.
-rw-r--r--lib/leap_cli/commands/user.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/leap_cli/commands/user.rb b/lib/leap_cli/commands/user.rb
index a1b4c43..6c33878 100644
--- a/lib/leap_cli/commands/user.rb
+++ b/lib/leap_cli/commands/user.rb
@@ -1,4 +1,3 @@
-autoload :GPGME, 'gpgme'
#
# perhaps we want to verify that the key files are actually the key files we expect.
@@ -75,8 +74,10 @@ module LeapCli
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!
@@ -98,13 +99,20 @@ module LeapCli
# 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|