Top Level Namespace

Defined Under Namespace

Modules: RubyDig Classes: Account, Array, Auth, Cli, Config, Console, Hash, Info, Proxy, Rotator, Ssh, Ssm, Store

Constant Summary collapse

DEFAULT_KEY_AGE =
90

Instance Method Summary collapse

Instance Method Details

#act_accObject



67
68
69
70
71
72
73
74
# File 'lib/sty/functions.rb', line 67

def act_acc
  act_acc = ENV['AWS_ACTIVE_ACCOUNT']
  unless act_acc
    puts red('ERROR! AWS_ACTIVE_ACCOUNT variable is not set. Is your session authenticated ?')
    exit 1
  end
  act_acc
end

#cache_file(path, identity) ⇒ Object



45
46
47
# File 'lib/sty/functions.rb', line 45

def cache_file(path, identity)
  "#{dir}/auth-cache/#{path.join('-')}-#{identity}.yaml"
end

#colorize(string, color_code) ⇒ Object



9
10
11
# File 'lib/sty/functions.rb', line 9

def colorize(string, color_code)
  "\e[#{color_code}m#{string}\e[0m"
end

#deep_find(obj, value, result = {}, path = []) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/sty/functions.rb', line 84

def deep_find(obj, value, result = {}, path = [])
  if obj.is_a?(Hash)
    obj.each do |k,v|
      deep_find(v, value, result, path + [k])
    end
    return result
  else
    m = matches(obj, value)
    result[to_fqn(path)] = m if m
  end
end

#dirObject



41
42
43
# File 'lib/sty/functions.rb', line 41

def dir
  @dir = @dir || sty_home
end

#dump(hash, file) ⇒ Object



53
54
55
56
57
# File 'lib/sty/functions.rb', line 53

def dump(hash, file)
  File.open("#{dir}/#{file}.yaml", 'w') do |f|
    f.write(Psych.dump(hash))
  end
end

#green(string) ⇒ Object



17
18
19
# File 'lib/sty/functions.rb', line 17

def green(string)
  colorize(string, 32)
end

#magenta(string) ⇒ Object



25
26
27
# File 'lib/sty/functions.rb', line 25

def magenta(string)
  colorize(string, 35)
end

#matches(container, value) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/sty/functions.rb', line 76

def matches(container, value)
  container = container.to_s
  if /#{value}/i =~ container.to_s
    match = $&
    container.split(match).insert(1,white(match)).join
  end
end

#red(string) ⇒ Object



13
14
15
# File 'lib/sty/functions.rb', line 13

def red(string)
  colorize(string, 31)
end

#regionObject



63
64
65
# File 'lib/sty/functions.rb', line 63

def region
  ENV['AWS_REGION'] || DEFAULT_REGION
end

#remained_minutesObject



59
60
61
# File 'lib/sty/functions.rb', line 59

def remained_minutes
  ((Time.parse(ENV['AWS_SESSION_EXPIRY']) - Time.now) / 60).to_i
end

#sty_homeObject



4
5
6
7
# File 'lib/sty/functions.rb', line 4

def sty_home
  home = File.expand_path('~')
  "#{home}/.sty"
end

#to_fqn(path) ⇒ Object



37
38
39
# File 'lib/sty/functions.rb', line 37

def to_fqn(path)
  path.join('/')
end

#to_path(fqn) ⇒ Object



33
34
35
# File 'lib/sty/functions.rb', line 33

def to_path(fqn)
  [fqn].flatten.map { |a| a.split("/") }.flatten
end

#white(string) ⇒ Object



29
30
31
# File 'lib/sty/functions.rb', line 29

def white(string)
  colorize(string, 97)
end

#yaml(file) ⇒ Object



49
50
51
# File 'lib/sty/functions.rb', line 49

def yaml(file)
  Psych.load_file("#{dir}/#{file}.yaml")
end

#yellow(string) ⇒ Object



21
22
23
# File 'lib/sty/functions.rb', line 21

def yellow(string)
  colorize(string, 33)
end