Class: Mihari::Services::AlertProxy
- Inherits:
-
Object
- Object
- Mihari::Services::AlertProxy
- Defined in:
- lib/mihari/services/proxies.rb
Overview
Alert proxy
Instance Attribute Summary collapse
- #data ⇒ Hash readonly
- #errors ⇒ Array? readonly
Instance Method Summary collapse
- #[](key) ⇒ Object
- #artifacts ⇒ Array<Mihari::Models::Artifact>
- #errors? ⇒ Boolean
-
#initialize(**data) ⇒ AlertProxy
constructor
Initialize.
- #rule ⇒ Mihari::Rule
- #rule_id ⇒ String
- #source ⇒ String?
- #validate! ⇒ Object
Constructor Details
#initialize(**data) ⇒ AlertProxy
Initialize
20 21 22 23 24 25 26 27 |
# File 'lib/mihari/services/proxies.rb', line 20 def initialize(**data) super() @data = data.deep_symbolize_keys @errors = nil validate! end |
Instance Attribute Details
#data ⇒ Hash (readonly)
10 11 12 |
# File 'lib/mihari/services/proxies.rb', line 10 def data @data end |
#errors ⇒ Array? (readonly)
13 14 15 |
# File 'lib/mihari/services/proxies.rb', line 13 def errors @errors end |
Instance Method Details
#[](key) ⇒ Object
48 49 50 |
# File 'lib/mihari/services/proxies.rb', line 48 def [](key) data key.to_sym end |
#artifacts ⇒ Array<Mihari::Models::Artifact>
62 63 64 65 66 67 68 69 |
# File 'lib/mihari/services/proxies.rb', line 62 def artifacts @artifacts ||= data[:artifacts].map do |data| artifact = Models::Artifact.new(data:) artifact.rule_id = rule_id artifact.source = source artifact end.uniq(&:data).select(&:valid?) end |
#errors? ⇒ Boolean
32 33 34 35 36 |
# File 'lib/mihari/services/proxies.rb', line 32 def errors? return false if errors.nil? !errors.empty? end |
#rule ⇒ Mihari::Rule
81 82 83 84 85 86 |
# File 'lib/mihari/services/proxies.rb', line 81 def rule @rule ||= lambda do data = Mihari::Models::Rule.find(rule_id).data Rule.new(**data) end.call end |
#rule_id ⇒ String
55 56 57 |
# File 'lib/mihari/services/proxies.rb', line 55 def rule_id @rule_id ||= data[:rule_id] end |
#source ⇒ String?
74 75 76 |
# File 'lib/mihari/services/proxies.rb', line 74 def source @source ||= data[:source] end |
#validate! ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/mihari/services/proxies.rb', line 38 def validate! contract = Schemas::AlertContract.new result = contract.call(data) @data = result.to_h @errors = result.errors raise ValidationError.new("Validation failed", errors) if errors? end |