Module: Ronin::Cache

Defined in:
lib/ronin/cache.rb

Class Method Summary collapse

Class Method Details

.cache_config(config) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/ronin/cache.rb', line 23

def cache_config(config)
  Ronin::Log.info("Caching configuration items from etcd (#{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}) to #{Ronin::Config[:cache_path]}/config.json.")

  File.open("#{Ronin::Config[:cache_path]}/config.json", "w") do |f|
    f.write(config.to_json)
  end
end

.cache_run_list(run_list) ⇒ Object



43
44
45
46
47
48
# File 'lib/ronin/cache.rb', line 43

def cache_run_list(run_list)
  Ronin::Log.info("Caching run_list from etcd (#{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}) to #{Ronin::Config[:cache_path]}/run_list.json.")
  File.open("#{Ronin::Config[:cache_path]}/run_list.json", "w") do |f|
    f.write(run_list.to_json)
  end
end

.load_cached_configObject



32
33
34
35
36
37
38
39
40
# File 'lib/ronin/cache.rb', line 32

def load_cached_config
  if File.exist?("#{Ronin::Config[:cache_path]}/config.json")
    Ronin::Log.info("Loading cached configuration items from #{Ronin::Config[:cache_path]}/config.json.")
    @config = JSON.parse(IO.read("#{Ronin::Config[:cache_path]}/config.json"))
    return @config
  else
    abort("Connection refused by etcd host #{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}, and no cached config found at (#{Ronin::Config[:cache_path]}/config.json)")
  end
end

.load_cached_run_listObject



51
52
53
54
55
56
57
58
59
# File 'lib/ronin/cache.rb', line 51

def load_cached_run_list
  if File.exist?("#{Ronin::Config[:cache_path]}/run_list.json")
    Ronin::Log.info("Loading cached run list items from #{Ronin::Config[:cache_path]}/run_list.json.")
    @run_list = JSON.parse(IO.read("#{Ronin::Config[:cache_path]}/run_list.json"))
    return @run_list
  else
    abort("Connection refused by etcd host #{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}, and no cached run list found at (#{Ronin::Config[:cache_path]}/run_list.json)")
  end
end