class Nucleon::Util::SSH::Keypair

Attributes

encrypted_key[R]
passphrase[R]
private_key[R]
public_key[R]
ssh_key[R]
type[R]

Public Class Methods

new(key_data, is_new, original_key, passphrase = nil) click to toggle source
# File lib/core/util/ssh.rb, line 83
def initialize(key_data, is_new, original_key, passphrase = nil)
  @type          = key_data.type
  @private_key   = key_data.private_key
  @encrypted_key = is_new ? key_data.encrypted_private_key : original_key
  @public_key    = key_data.public_key
  @ssh_key       = key_data.ssh_public_key
  @passphrase    = passphrase
end
render(type, key_base = 'id') click to toggle source
# File lib/core/util/ssh.rb, line 132
def self.render(type, key_base = 'id')
  "#{key_base}_#{type.downcase}"  
end

Public Instance Methods

private_key_file(key_path = nil, key_base = 'id') click to toggle source
# File lib/core/util/ssh.rb, line 94
def private_key_file(key_path = nil, key_base = 'id')
  key_path = SSH.key_path if key_path.nil?
  key_name = render(key_base)
  
  File.join(key_path, "#{key_name}")  
end
public_key_file(key_path = nil, key_base = 'id') click to toggle source
# File lib/core/util/ssh.rb, line 101
def public_key_file(key_path = nil, key_base = 'id')
  private_key_file(key_path, key_base) + '.pub'  
end
render(key_base = 'id') click to toggle source
# File lib/core/util/ssh.rb, line 128
def render(key_base = 'id')
  self.class.render(type, key_base)
end
store(key_path = nil, key_base = 'id', secure = true) click to toggle source
# File lib/core/util/ssh.rb, line 107
def store(key_path = nil, key_base = 'id', secure = true)
  private_key_file = private_key_file(key_path, key_base)
  public_key_file  = public_key_file(key_path, key_base)
  
  if secure
    private_success = Disk.write(private_key_file, encrypted_key)
  else
    private_success = Disk.write(private_key_file, private_key)  
  end
  FileUtils.chmod(0600, private_key_file) if private_success
  
  public_success = Disk.write(public_key_file, ssh_key)
  
  if private_success && public_success
    return { :private_key => private_key_file, :public_key => public_key_file }
  end
  false
end