module EhcHardenStore
EhcHardenStore — per-channel last harden scan and numbered issues. Public: load_scan, save_scan, find_issue Depends: RabbotDb Tests: test/lib/ehc_harden_test.rb
Constants
- KEY
- PLUGIN
Public Instance Methods
Source
# File lib/ehc_harden_store.rb, line 41 def find_issue(network:, channel:, issue_id:, store: RabbotDb) data = load_scan(network: network, channel: channel, store: store) id = issue_id.to_i Array(data["issues"]).find { |row| row["id"].to_i == id } end
Source
# File lib/ehc_harden_store.rb, line 18 def load_scan(network:, channel:, store: RabbotDb) data = store.get_plugin_json( plugin: PLUGIN, key: KEY, network: network, channel: channel, default: nil ) normalize(data) end
Source
# File lib/ehc_harden_store.rb, line 47 def normalize(raw, now: Time.now.utc) data = raw.is_a?(Hash) ? raw : {} issues = Array(data["issues"] || data[:issues]).map { |row| normalize_issue(row) } { "target" => (data["target"] || data[:target]).to_s, "label" => (data["label"] || data[:label]).to_s, "scanned_at" => (data["scanned_at"] || data[:scanned_at]).to_s.strip.empty? ? now.utc.iso8601 : (data["scanned_at"] || data[:scanned_at]).to_s, "issues" => issues } end
Source
# File lib/ehc_harden_store.rb, line 58 def normalize_issue(raw) row = raw.is_a?(Hash) ? raw : {} { "id" => (row["id"] || row[:id]).to_i, "code" => (row["code"] || row[:code]).to_s, "title" => (row["title"] || row[:title]).to_s, "summary" => (row["summary"] || row[:summary]).to_s, "severity" => (row["severity"] || row[:severity]).to_s, "detail_lines" => Array(row["detail_lines"] || row[:detail_lines]).map(&:to_s).reject(&:empty?) } end
Source
# File lib/ehc_harden_store.rb, line 29 def save_scan(network:, channel:, scan:, store: RabbotDb, now: Time.now.utc) payload = normalize(scan, now: now) store.set_plugin_json( plugin: PLUGIN, key: KEY, network: network, channel: channel, value: payload ) payload end