Module: SwitchCreds

Defined in:
lib/switchcreds.rb,
lib/switchcreds/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_credsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/switchcreds.rb', line 5

def self.get_creds
  # detect the OS and user to find the .aws directory
  if OS.mac?
    $user = Dir.home[7, Dir.home.length].to_s
  elsif OS.windows?
    $user = Dir.home[9, Dir.home.length].to_s
  # when OS.linux?
    # TODO: build out Linux implentation (other OSs too?)
  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_credsObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/switchcreds.rb', line 26

def self.switch_creds
  creds = get_creds()
  puts "
==========================================================================================================================================================
==      ===  ====  ====  ==    ==        ====     ===  ====  =======        ====    =========  ====  ====  ==  ====  ==    ====     ===  ====  ===      ==
=  ====  ==  ====  ====  ===  ======  ======  ===  ==  ====  ==========  ======  ==  ========  ====  ====  ==  ====  ===  ====  ===  ==  ====  ==  ====  =
=  ====  ==  ====  ====  ===  ======  =====  ========  ====  ==========  =====  ====  =======  ====  ====  ==  ====  ===  ===  ========  ====  ==  ====  =
==  =======  ====  ====  ===  ======  =====  ========  ====  ==========  =====  ====  =======  ====  ====  ==  ====  ===  ===  ========  ====  =======  ==
====  =====   ==    ==  ====  ======  =====  ========        ==========  =====  ====  =======   ==    ==  ===        ===  ===  ========        ======  ===
======  ====  ==    ==  ====  ======  =====  ========  ====  ==========  =====  ====  ========  ==    ==  ===  ====  ===  ===  ========  ====  =====  ====
=  ====  ===  ==    ==  ====  ======  =====  ========  ====  ==========  =====  ====  ========  ==    ==  ===  ====  ===  ===  ========  ====  ===========
=  ====  ====    ==    =====  ======  ======  ===  ==  ====  ==========  ======  ==  ==========    ==    ====  ====  ===  ====  ===  ==  ====  =====  ====
==      ======  ====  =====    =====  =======     ===  ====  ==========  =======    ============  ====  =====  ====  ==    ====     ===  ====  =====  ====
==========================================================================================================================================================
\n".colorize(:blue)

  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_credsObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/switchcreds.rb', line 59

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