mihari 7.0.5 → 7.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -37,9 +37,9 @@ module Mihari
37
37
  class IntegrityError < Error; end
38
38
 
39
39
  #
40
- # HTTP status code error
40
+ # HTTP status error
41
41
  #
42
- class StatusCodeError < ::HTTP::Error
42
+ class StatusError < ::HTTP::Error
43
43
  # @return [Integer]
44
44
  attr_reader :status_code
45
45
 
data/lib/mihari/http.rb CHANGED
@@ -11,7 +11,7 @@ module Mihari
11
11
  def wrap_response(response)
12
12
  return response if response.status.success?
13
13
 
14
- raise StatusCodeError.new(
14
+ raise StatusError.new(
15
15
  "Unsuccessful response code returned: #{response.code}",
16
16
  response.code,
17
17
  response.body.to_s
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
- # NOTE: separate parallel execution and logging
192
- # because the logger does not work along with Parallel
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "7.0.5"
4
+ VERSION = "7.1.1"
5
5
  end
@@ -36,7 +36,7 @@ module Mihari
36
36
 
37
37
  failure = result.failure
38
38
  case failure
39
- when Mihari::StatusCodeError
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