mihari 7.0.5 → 7.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/README.md +2 -1
- data/Rakefile +39 -1
- data/lib/mihari/analyzers/base.rb +8 -10
- data/lib/mihari/cli/application.rb +19 -4
- data/lib/mihari/commands/alert.rb +41 -6
- data/lib/mihari/commands/artifact.rb +41 -6
- data/lib/mihari/commands/config.rb +1 -1
- data/lib/mihari/commands/rule.rb +42 -7
- data/lib/mihari/commands/search.rb +1 -1
- data/lib/mihari/commands/tag.rb +39 -4
- data/lib/mihari/concerns/retriable.rb +2 -2
- data/lib/mihari/data_type.rb +3 -3
- data/lib/mihari/database.rb +1 -1
- data/lib/mihari/emitters/base.rb +5 -1
- data/lib/mihari/emitters/webhook.rb +15 -53
- data/lib/mihari/enrichers/base.rb +7 -1
- data/lib/mihari/errors.rb +2 -2
- data/lib/mihari/http.rb +1 -1
- data/lib/mihari/rule.rb +2 -14
- data/lib/mihari/services/renderer.rb +31 -0
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/endpoints/ip_addresses.rb +1 -1
- data/lib/mihari/web/public/assets/{index-geliIfjB.js → index-U5u7qHZZ.js} +18 -18
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari/web/public/redoc-static.html +28 -28
- data/lib/mihari.rb +12 -0
- data/mihari.gemspec +5 -2
- data/mkdocs.yml +1 -1
- data/test.json.jbuilder +7 -0
- metadata +51 -7
@@ -19,17 +19,23 @@ module Mihari
|
|
19
19
|
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
20
20
|
end
|
21
21
|
|
22
|
+
#
|
23
|
+
# @param [Mihari::Models::Artifact] value
|
22
24
|
#
|
23
25
|
# @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
|
24
26
|
#
|
25
27
|
def result(value)
|
26
|
-
Try[StandardError] do
|
28
|
+
result = Try[StandardError] do
|
27
29
|
retry_on_error(
|
28
30
|
times: retry_times,
|
29
31
|
interval: retry_interval,
|
30
32
|
exponential_backoff: retry_exponential_backoff
|
31
33
|
) { call value }
|
32
34
|
end.to_result
|
35
|
+
|
36
|
+
Mihari.logger.warn("Enricher:#{self.class.class_key} failed: #{result.failure}") if result.failure?
|
37
|
+
|
38
|
+
result
|
33
39
|
end
|
34
40
|
|
35
41
|
class << self
|
data/lib/mihari/errors.rb
CHANGED
data/lib/mihari/http.rb
CHANGED
data/lib/mihari/rule.rb
CHANGED
@@ -188,20 +188,8 @@ module Mihari
|
|
188
188
|
def bulk_emit
|
189
189
|
return [] if enriched_artifacts.empty?
|
190
190
|
|
191
|
-
|
192
|
-
|
193
|
-
results = Parallel.map(emitters) { |emitter| emitter.result enriched_artifacts }
|
194
|
-
results.zip(emitters).map do |result_and_emitter|
|
195
|
-
result, emitter = result_and_emitter
|
196
|
-
|
197
|
-
case result
|
198
|
-
when Success
|
199
|
-
Mihari.logger.info "Emission by #{emitter.class} succeed"
|
200
|
-
else
|
201
|
-
Mihari.logger.info "Emission by #{emitter.class} failed: #{result.failure}"
|
202
|
-
end
|
203
|
-
|
204
|
-
result.value_or nil
|
191
|
+
Parallel.map(emitters) do |emitter|
|
192
|
+
emitter.result(enriched_artifacts).value_or nil
|
205
193
|
end.compact
|
206
194
|
end
|
207
195
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "tilt/jbuilder"
|
2
|
+
|
3
|
+
module Mihari
|
4
|
+
module Services
|
5
|
+
#
|
6
|
+
# Jbuilder based JSON renderer
|
7
|
+
#
|
8
|
+
class JbuilderRenderer < Service
|
9
|
+
attr_reader :template
|
10
|
+
|
11
|
+
#
|
12
|
+
# @param [String] template
|
13
|
+
# @param [Hash] params
|
14
|
+
#
|
15
|
+
# @return [String]
|
16
|
+
#
|
17
|
+
def call(template, params = {})
|
18
|
+
@template = template
|
19
|
+
|
20
|
+
jbuilder_template = Tilt::JbuilderTemplate.new { template_string }
|
21
|
+
jbuilder_template.render(nil, params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def template_string
|
25
|
+
return File.read(template) if Pathname(template).exist?
|
26
|
+
|
27
|
+
template
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/mihari/version.rb
CHANGED
@@ -36,7 +36,7 @@ module Mihari
|
|
36
36
|
|
37
37
|
failure = result.failure
|
38
38
|
case failure
|
39
|
-
when Mihari::
|
39
|
+
when Mihari::StatusError
|
40
40
|
error!({ message: "IP:#{ip} not found" }, failure.status_code) if failure.status_code == 404
|
41
41
|
error!({ message: "IP format invalid" }, failure.status_code) if failure.status_code == 422
|
42
42
|
end
|