Module: Ronin::Etcd
- Defined in:
- lib/ronin/etcd.rb
Class Method Summary collapse
Class Method Details
.get_config ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ronin/etcd.rb', line 75 def get_config @config = {} Ronin::Config[:etcd_keys].each do |key| key = @hostname if key == 'node' @payload = Ronin::Etcd.get_key('config', key) if @payload == :down Ronin::Log.warn("Connection refused by etcd host #{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}, loading config from cache (#{Ronin::Config[:cache_path]}/config.json)") return Ronin::Cache.load_cached_config else @parsed_payload = JSON.parse(@payload) @config = @config.merge(@parsed_payload) end end if Ronin::Config[:config_from_etcd] and Ronin::Config[:cache_etcd_data] Ronin::Cache.cache_config(@config) end return @config end |
.get_key(type, key) ⇒ Object
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ronin/etcd.rb', line 28 def get_key(type, key) # Will add error handling... one day. @path = "/v2/keys/ronin/#{type}/#{key}" @http = Net::HTTP.new(Ronin::Config[:etcd_host], Ronin::Config[:etcd_port]) @http.read_timeout = Ronin::Config[:etcd_read_timeout] @http.open_timeout = Ronin::Config[:etcd_conn_timeout] if Ronin::Config[:etcd_use_ssl] @http.use_ssl = true unless Ronin::Config[:etcd_ssl_cert] = '' @http.verify_mode = OpenSSL::SSL::VERIFY_PEER store = OpenSSL::X509::Store.new store.add_cert(OpenSSL::X509::Certificate.new(File.read(Ronin::Config[:etcd_ssl_ca_cert]))) @http.cert_store = store @http.key = OpenSSL::PKey::RSA.new(File.read(Ronin::Config[:etcd_ssl_cert])) @http.cert = OpenSSL::X509::Certificate.new(File.read(Ronin::Config[:etcd_ssl_key])) end else @http.use_ssl = false end @request = Net::HTTP::Get.new(@path) begin @result = @http.request(@request) rescue Exception => e if Ronin::Config[:cache_etcd_data] return :down else abort("Connection refused by etcd host #{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}, exiting...") end end unless @result.kind_of?(Net::HTTPSuccess) if @result.code == 404 Ronin::Log.info("Key http://#{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}#{@path} not found, returning an empty set.") return "{}" else Ronin::Log.info("Got status #{@result.code} querying http://#{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}#{@path}, returning an empty set.") return "{}" end end return JSON.parse(@result.body)['node']['value'] end |
.get_run_list ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ronin/etcd.rb', line 100 def get_run_list @run_list = [] Ronin::Config[:etcd_keys].each do |key| key = @hostname if key == 'node' @payload = Ronin::Etcd.get_key('run_list', key) if @payload == :down Ronin::Log.warn("Connection refused by etcd host #{Ronin::Config[:etcd_host]}:#{Ronin::Config[:etcd_port]}, loading run_list from cache (#{Ronin::Config[:cache_path]}/run_list.json)") return Ronin::Cache.load_cached_run_list else @parsed_payload = JSON.parse(@payload)['artifacts'] @run_list += @parsed_payload unless @parsed_payload.nil? end if Ronin::Config[:config_from_etcd] and Ronin::Config[:cache_etcd_data] Ronin::Cache.cache_run_list(@run_list.uniq) end end return @run_list.uniq end |