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
87 def initialize(key_data, is_new, original_key, passphrase = nil)
88   @type          = key_data.type
89   @private_key   = key_data.private_key
90   @encrypted_key = is_new ? key_data.encrypted_private_key : original_key
91   @public_key    = key_data.public_key
92   @ssh_key       = key_data.ssh_public_key
93   @passphrase    = passphrase
94 end
render(type, key_base = 'id') click to toggle source
    # File lib/core/util/ssh.rb
136 def self.render(type, key_base = 'id')
137   "#{key_base}_#{type.downcase}"
138 end

Public Instance Methods

private_key_file(key_path = nil, key_base = 'id') click to toggle source
    # File lib/core/util/ssh.rb
 98 def private_key_file(key_path = nil, key_base = 'id')
 99   key_path = SSH.key_path if key_path.nil?
100   key_name = render(key_base)
101 
102   File.join(key_path, "#{key_name}")
103 end
public_key_file(key_path = nil, key_base = 'id') click to toggle source
    # File lib/core/util/ssh.rb
105 def public_key_file(key_path = nil, key_base = 'id')
106   private_key_file(key_path, key_base) + '.pub'
107 end
render(key_base = 'id') click to toggle source
    # File lib/core/util/ssh.rb
132 def render(key_base = 'id')
133   self.class.render(type, key_base)
134 end
store(key_path = nil, key_base = 'id', secure = true) click to toggle source
    # File lib/core/util/ssh.rb
111 def store(key_path = nil, key_base = 'id', secure = true)
112   private_key_file = private_key_file(key_path, key_base)
113   public_key_file  = public_key_file(key_path, key_base)
114 
115   if secure
116     private_success = Disk.write(private_key_file, encrypted_key)
117   else
118     private_success = Disk.write(private_key_file, private_key)
119   end
120   FileUtils.chmod(0600, private_key_file) if private_success
121 
122   public_success = Disk.write(public_key_file, ssh_key)
123 
124   if private_success && public_success
125     return { :private_key => private_key_file, :public_key => public_key_file }
126   end
127   false
128 end