]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
fixed bugs with add-user: skip keys we can't understand, don't die if gpg can't be...
authorelijah <elijah@riseup.net>
Thu, 30 Oct 2014 00:53:57 +0000 (17:53 -0700)
committerelijah <elijah@riseup.net>
Thu, 30 Oct 2014 00:53:57 +0000 (17:53 -0700)
lib/leap_cli/commands/user.rb

index a1b4c4370c6e9ebc408c55851d11d5057cc660af..6c33878fe07265a2d6a8e307b18e4cac14bf608f 100644 (file)
@@ -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|