Sha256: 7acab57a469de83e7bcb8d94d8c0bfd2c72226b136a095d48a3abed8a11e43c1

Contents?: true

Size: 677 Bytes

Versions: 2

Compression:

Stored size: 677 Bytes

Contents

require "securerandom"

module CloudRunner
  class SshKey
    attr_reader :type

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

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

    def private
      File.read(private_path)
    end

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

    private

    def generate
      `ssh-keygen -t '#{@type}' -f '#{@private_path}' -N ''`
      raise "Failed to generate ssh key" unless $? == 0
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cloud_runner-0.0.2 lib/cloud_runner/ssh_key.rb
cloud_runner-0.0.1 lib/cloud_runner/ssh_key.rb