class Heroku::Command::Keys

manage authentication keys

Public Instance Methods

add() click to toggle source

keys:add [KEY]

add a key for the current user

if no KEY is specified, will try to find ~/.ssh/id_[rd]sa.pub

# File lib/heroku/command/keys.rb, line 34
def add
  if keyfile = args.first
    display "Uploading SSH public key #{keyfile}"
    heroku.add_key(File.read(keyfile))
  else
    # make sure we have credentials
    Heroku::Auth.get_credentials
    Heroku::Auth.associate_or_generate_ssh_key
  end
end
clear() click to toggle source

keys:clear

remove all authentication keys from the current user

# File lib/heroku/command/keys.rb, line 58
def clear
  heroku.remove_all_keys
  display "All keys removed."
end
index() click to toggle source

keys

display keys for the current user

-l, --long # display extended information for each key

# File lib/heroku/command/keys.rb, line 15
def index
  long = options[:long]
  keys = heroku.keys
  if keys.empty?
    display "No keys for #{heroku.user}"
  else
    display "=== #{keys.size} key#{'s' if keys.size > 1} for #{heroku.user}"
    keys.each do |key|
      display long ? key.strip : format_key_for_display(key)
    end
  end
end
remove() click to toggle source

keys:remove KEY

remove a key from the current user

# File lib/heroku/command/keys.rb, line 49
def remove
  heroku.remove_key(args.first)
  display "Key #{args.first} removed."
end

Protected Instance Methods

format_key_for_display(key) click to toggle source
# File lib/heroku/command/keys.rb, line 64
def format_key_for_display(key)
  type, hex, local = key.strip.split(%r\s/)
  [type, hex[0,10] + '...' + hex[-10,10], local].join(' ')
end