Skip to content

Commit

Permalink
add an --auto flag for automated key creation and upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ddollar committed Aug 2, 2010
1 parent 1f6ca7c commit 5a15c73
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -22,6 +22,19 @@ To add accounts:
IdentityFile /PATH/TO/PRIVATE/KEY
IdentitiesOnly yes

Or you can choose a fully-automated approach:

$ heroku accounts:add work --auto
Enter your Heroku credentials.
Email: work@example.org
Password: ******
Generating new SSH key
Generating public/private rsa key pair.
Your identification has been saved in ~/.ssh/identity.heroku.work.
Your public key has been saved in ~/.ssh/identity.heroku.work.pub.
Adding entry to ~/.ssh/config
Adding public key to Heroku account: work@example.org

To switch an app to a different account:

# in project root
Expand Down
36 changes: 29 additions & 7 deletions lib/heroku/command/accounts.rb
Expand Up @@ -25,13 +25,31 @@ def add
:password => password
)

display ""
display "Add the following to your ~/.ssh/config"
display ""
display "Host heroku.#{name}"
display " HostName heroku.com"
display " IdentityFile /PATH/TO/PRIVATE/KEY"
display " IdentitiesOnly yes"
if extract_option("--auto") then
display "Generating new SSH key"
system %{ ssh-keygen -t rsa -f #{account_ssh_key(name)} -N "" }

display "Adding entry to ~/.ssh/config"
File.open(File.expand_path("~/.ssh/config"), "a") do |file|
file.puts
file.puts "Host heroku.#{name}"
file.puts " HostName heroku.com"
file.puts " IdentityFile #{account_ssh_key(name)}"
file.puts " IdentitiesOnly yes"
end

display "Adding public key to Heroku account: #{username}"
client = Heroku::Client.new(username, password)
client.add_key(File.read(File.expand_path(account_ssh_key(name) + ".pub")))
else
display ""
display "Add the following to your ~/.ssh/config"
display ""
display "Host heroku.#{name}"
display " HostName heroku.com"
display " IdentityFile /PATH/TO/PRIVATE/KEY"
display " IdentitiesOnly yes"
end
end

def remove
Expand Down Expand Up @@ -92,6 +110,10 @@ def account_exists?(name)
account_names.include?(name)
end

def account_ssh_key(name)
"~/.ssh/identity.heroku.#{name}"
end

def read_account(name)
YAML::load_file(account_file(name))
end
Expand Down

0 comments on commit 5a15c73

Please sign in to comment.