Class: Sym::App::Commands::PasswordProtectKey

Inherits:
BaseCommand show all
Defined in:
lib/sym/app/commands/password_protect_key.rb

Constant Summary

Constants included from Sym

DESCRIPTION, VERSION

Instance Method Summary collapse

Methods included from Sym

config, default_key, default_key?, default_key_file

Constructor Details

This class inherits a constructor from Sym::App::Commands::BaseCommand

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sym/app/commands/password_protect_key.rb', line 12

def execute
  retries ||= 0
  raise Sym::Errors::NoPrivateKeyFound.new("Unable to resolve private key from argument '#{opts[:key]}'") if self.key.nil?

  the_key = self.key

  if opts[:password]
     encrypted_key, password = encrypt_with_password(the_key)
     add_password_to_the_cache(encrypted_key, password)
     the_key = encrypted_key
   end

  add_to_keychain_if_needed(the_key)

  the_key
rescue Sym::Errors::PasswordsDontMatch, Sym::Errors::PasswordTooShort => e
  stderr.puts e.message.bold
  retry if (retries += 1) < 3
end