Class: CloudRunner::SshKey

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_runner/ssh_key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = "rsa", private_path = nil) ⇒ SshKey

Returns a new instance of SshKey.



7
8
9
10
# File 'lib/cloud_runner/ssh_key.rb', line 7

def initialize(type="rsa", private_path=nil)
  raise "Type must be specified" unless @type = type
  @private_path = private_path
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/cloud_runner/ssh_key.rb', line 5

def type
  @type
end

Instance Method Details

#privateObject



16
17
18
# File 'lib/cloud_runner/ssh_key.rb', line 16

def private
  File.read(private_path)
end

#private_pathObject



20
21
22
23
24
25
26
# File 'lib/cloud_runner/ssh_key.rb', line 20

def private_path
  unless @private_path
    @private_path = "/tmp/ssh-key-#{SecureRandom.hex}"
    generate
  end
  @private_path
end

#publicObject



12
13
14
# File 'lib/cloud_runner/ssh_key.rb', line 12

def public
  File.read("#{private_path}.pub")
end