Module: SwitchCreds
- Defined in:
- lib/switchcreds.rb,
lib/switchcreds/version.rb
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.get_creds ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/switchcreds.rb', line 5 def self.get_creds # detect the OS and user to find the .aws directory if OS.mac? || OS.linux? $user = Dir.home[7, Dir.home.length].to_s elsif OS.windows? $user = Dir.home[9, Dir.home.length].to_s else puts "ERROR:".colorize(:red) + " Neither WINDOWS nor MAC OS detected.\n Unable to proceed." end dir = Dir.entries("/Users/#{$user}/.aws") creds = [] dir.each do |f| if f.length > 11 && f[0,12] == "credentials_" creds.push(f[12, f.length]) end end creds end |
.switch_creds ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/switchcreds.rb', line 24 def self.switch_creds creds = get_creds() puts "CHOOSE FROM BELOW:\n".colorize(:green) i = 0 creds.each do |o| puts "\t#{i}: #{o}" i += 1 end selection = STDIN.gets.chomp.to_i selection = creds[selection] IO.copy_stream("/Users/#{$user}/.aws/credentials_#{selection}", "/Users/#{$user}/.aws/credentials") 32.times { print "*".colorize(:green) } puts "\n* Using #{selection.upcase!.colorize(:red)} creds now *\n" 32.times { print "*".colorize(:green) } puts "\n" end |
Instance Method Details
#which_creds ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/switchcreds.rb', line 45 def which_creds creds = get_creds creds.each do |cred| if FileUtils.compare_file("/Users/#{$user}/.aws/credentials", "/Users/#{$user}/.aws/credentials_#{cred}") 32.times { print "*".colorize(:green) } puts "\n* You're using #{cred.upcase!.colorize(:red)} creds.*\n" 32.times { print "*".colorize(:green) } puts "\n" end end end |