class RHC::Commands::Sshkey

Public Instance Methods

add(name, key) click to toggle source
# File lib/rhc/commands/sshkey.rb, line 42
def add(name, key)
  type, content, comment = ssh_key_triple_for(key)

  # validate the user input before sending it to the server
  begin
    Net::SSH::KeyFactory.load_data_public_key "#{type} #{content}"
  rescue NotImplementedError, OpenSSL::PKey::PKeyError, Net::SSH::Exception => e
    debug e.inspect
    if options.confirm
      warn 'The key you are uploading is not recognized.  You may not be able to authenticate to your application through Git or SSH.'
    else
      raise ::RHC::KeyDataInvalidException.new("File '#{key}' does not appear to be a recognizable key file (#{e}). You may specify the '--confirm' flag to add the key anyway.")
    end
  end

  rest_client.add_key(name, content, type)
  results { say "SSH key #{key} has been added as '#{name}'" }

  0
end
list() click to toggle source
# File lib/rhc/commands/sshkey.rb, line 15
def list
  results do
    result = rest_client.sshkeys.inject('') do |r, key|
      r += format(key, erb)
    end

    say result
  end

  0
end
remove(name) click to toggle source
# File lib/rhc/commands/sshkey.rb, line 67
def remove(name)
  rest_client.delete_key(name)
  results { say "SSH key '#{name}' has been removed" }

  0
end
show(name) click to toggle source
# File lib/rhc/commands/sshkey.rb, line 30
def show(name)
  key = rest_client.find_key(name)
  say format(key, erb)

  0
end