Class: Secrets::App::Commands::GenerateKey

Inherits:
Command
  • Object
show all
Includes:
Secrets
Defined in:
lib/secrets/app/commands/generate_key.rb

Constant Summary

Constants included from Secrets

VERSION

Instance Attribute Summary

Attributes inherited from Command

#cli

Instance Method Summary collapse

Methods included from Secrets

included

Methods inherited from Command

inherited, #initialize, #key, #opts

Constructor Details

This class inherits a constructor from Secrets::App::Commands::Command

Instance Method Details

#runObject



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

def run
  retries         ||= 0
  new_private_key = self.class.create_private_key

  if opts[:password]
    handler = Secrets::App::PasswordHandler.new(opts).create
    new_private_key = encr_password(new_private_key, handler.password)
  end

  clipboard_copy(new_private_key) if opts[:copy]

  if opts[:keychain] && Secrets::App.is_osx?
    Secrets::App::KeyChain.new(opts[:keychain]).add(new_private_key)
  end

  new_private_key
rescue Secrets::Errors::PasswordsDontMatch, Secrets::Errors::PasswordTooShort => e
  STDERR.puts e.message.bold
  retry if (retries += 1) < 3
end