class AwsSshKey::Key

Public Class Methods

new(key_path:, key_name:, aws_region:, role: nil, tags: {}) click to toggle source
# File lib/aws_ssh_key.rb, line 10
def initialize(key_path:, key_name:, aws_region:, role: nil, tags: {})
  @key_path = key_path
  @key_name = key_name
  @aws_region = aws_region
  @tags = tags

  @secure_parameter_ssh_key_public = "#{key_path}/ssh_key/#{key_name}/public"
  @secure_parameter_ssh_key_private = "#{key_path}/ssh_key/#{key_name}/private"

  @public_key = nil
  @role_to_assume = role
end

Public Instance Methods

generate_key() click to toggle source
# File lib/aws_ssh_key.rb, line 39
def generate_key
  AwsSshKey::KeyMaker.make_key(@key_name)
end
get_remote_public_key() click to toggle source
# File lib/aws_ssh_key.rb, line 35
def get_remote_public_key
  AwsSshKey::SecureParameter.get_parameter(@secure_parameter_ssh_key_public, @aws_region, @role_to_assume)
end
load() click to toggle source
# File lib/aws_ssh_key.rb, line 23
def load
  if @public_key.nil?
    @public_key = get_remote_public_key
  end
  if @public_key.nil?
    key_pair = generate_key
    put_remote_key_pair(key_pair)
    @public_key = key_pair
  end
  @key
end
put_remote_key_pair(key_pair) click to toggle source
# File lib/aws_ssh_key.rb, line 43
def put_remote_key_pair(key_pair)
  AwsSshKey::SecureParameter.put_parameter(@secure_parameter_ssh_key_public, key_pair[:public], @aws_region, @role_to_assume, @tags)
  AwsSshKey::SecureParameter.put_parameter(@secure_parameter_ssh_key_private, key_pair[:private], @aws_region, @role_to_assume, @tags)
  key_pair[:public]
end
write(folder) click to toggle source
# File lib/aws_ssh_key.rb, line 49
def write(folder)
  FileUtils.mkpath folder
  File.open("#{folder}/#{@key_name}.pub", 'w') {|f| f.write(@public_key) }
end