Class: Heroswitch::Credentials
- Inherits:
-
Object
- Object
- Heroswitch::Credentials
- Defined in:
- lib/heroswitch/credentials.rb
Constant Summary collapse
- HEROKU_HOME =
File.join ENV["HOME"], ".heroku"
- CREDENTIALS_FILE =
"credentials"
Class Method Summary collapse
- .list_credentials ⇒ Object
- .print_reminder(account) ⇒ Object
- .show_credentials ⇒ Object
- .switch(account) ⇒ Object
Class Method Details
.list_credentials ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/heroswitch/credentials.rb', line 21 def self.list_credentials puts "\nYou have credentials files for the following accounts in\n" puts "#{HEROKU_HOME}\n\n" Dir[HEROKU_HOME+"/*."+CREDENTIALS_FILE].each do |file| puts " #{(File.basename file).gsub(/\.#{CREDENTIALS_FILE}/, "")}" end puts "\n" end |
.print_reminder(account) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/heroswitch/credentials.rb', line 42 def self.print_reminder(account) puts "\n \\033[31mRemember to add an entry in your ~/.ssh/config file like:\\033[0m\n Host \\033[33m\#{account}\\033[0m.heroku.com\n HostName heroku.com\n User git\n IdentityFile ~/.ssh/path/to/\#{account}/account/private_key.identity\n IdentitiesOnly yes\n\n \\033[31mAlso, use \\033[33m\#{account}.heroku.com\\033[31m when setting up your heroku remote in git:\\033[0m\n $ git remote add heroku git@\\033[33m\#{account}.heroku.com\\033[0m:MyApp.git\n\n OUT\nend\n".gsub(/^ /,'') |
.show_credentials ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/heroswitch/credentials.rb', line 8 def self.show_credentials credentials_path = File.join HEROKU_HOME, CREDENTIALS_FILE if File.exists? credentials_path credentials = `cat #{credentials_path}`.split "\n" puts "\nYour active Heroku credentials are:\n\n" puts credentials.first puts '*' * credentials.last.size puts "\n" else puts "ERROR: Heroku credentials not found!" end end |
.switch(account) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/heroswitch/credentials.rb', line 30 def self.switch(account) account_path = File.join HEROKU_HOME, account + '.' + CREDENTIALS_FILE credentials_path = File.join HEROKU_HOME, CREDENTIALS_FILE puts "\nSwitching to the \"#{account}\" Heroku account..." if File.exists? account_path FileUtils.cp(account_path, credentials_path) print_reminder account else puts "ERROR: Heroku account credentials do not exist!" end end |