class RHC::Commands::Sshkey

Public Instance Methods

add(name, key) click to toggle source
# File lib/rhc/commands/sshkey.rb, line 36
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 13
def list
  keys = rest_client.sshkeys.each{ |key| paragraph{ display_key(key) } }

  success "You have #{keys.length} SSH keys associated with your account."

  0
end
remove(name) click to toggle source
# File lib/rhc/commands/sshkey.rb, line 61
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 24
def show(name)
  key = rest_client.find_key(name)
  display_key(key)

  0
end