Class: Heroswitch::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/heroswitch/credentials.rb

Constant Summary collapse

HEROKU_HOME =
File.join ENV["HOME"], ".heroku"
CREDENTIALS_FILE =
"credentials"

Class Method Summary collapse

Class Method Details

.list_credentialsObject



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


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()
  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_credentialsObject



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()
   = File.join HEROKU_HOME,  + '.' + CREDENTIALS_FILE
  credentials_path = File.join HEROKU_HOME, CREDENTIALS_FILE
  puts "\nSwitching to the \"#{account}\" Heroku account..."
  if File.exists? 
    FileUtils.cp(, credentials_path)
    print_reminder 
  else
    puts "ERROR: Heroku account credentials do not exist!"
  end
end