mihari 8.0.0 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75cc81f17196e45d76732a65800c54416d73c2b86751ee3745f7d02d9e938b59
4
- data.tar.gz: 0300cb460d5cecae999c095967dbb6c2827fe59b0404becdb287f9df07a6ef8d
3
+ metadata.gz: d3d454e8ac560ec2d1b7463dfdc686e69fc033da82e318f9479ba14f72194c49
4
+ data.tar.gz: d2f191e78eb2180a9062d885fd527f5e55c70fa70a5e9f8f910b15a50d57d6a2
5
5
  SHA512:
6
- metadata.gz: aa653f50889b81341aa06a2d4bbab8c5bfb83bfb2adc60bbbba88933b24fe61503e52de6f5f8b082f5af7f697b249d206e545257def2603a6d0ab76fed090047
7
- data.tar.gz: 1737d85fb2322b49cc5b0a47ea3ad8a3cb723cfa8e7c793f57dd8747472e4509c8282c81148e454ef81f70fa55d6bc037d596ffe538f40fab98b8a1661feda25
6
+ metadata.gz: 723186046c14e4532c3662280264a51fb7a5966173d7010c50d6537a8b96304b6ff7f7f24d9686d1773fe8f13ceaba09d7d33c0265e286b58c9d18f3849645b8
7
+ data.tar.gz: 8a9f7001f3edb2a4035178c810ff5a12cf2cf913533f853e778c8d15ef4e74edfaef4d1b9061ab406d824406e7abd9eba94adb2e45da6c9b963a5d029123d322
data/lib/mihari/actor.rb CHANGED
@@ -63,7 +63,7 @@ module Mihari
63
63
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
64
64
  end
65
65
 
66
- def result(...)
66
+ def get_result(...)
67
67
  Try[StandardError] do
68
68
  retry_on_error(times: retry_times, interval: retry_interval, exponential_backoff: retry_exponential_backoff) do
69
69
  call(...)
@@ -77,7 +77,7 @@ module Mihari
77
77
  normalized_artifacts
78
78
  end
79
79
 
80
- def result(...)
80
+ def get_result(...)
81
81
  result = Try[StandardError] do
82
82
  retry_on_error(
83
83
  times: retry_times,
@@ -91,7 +91,7 @@ module Mihari
91
91
  # @param [Integer] id
92
92
  #
93
93
  def get(id)
94
- value = Services::AlertGetter.result(id).value!
94
+ value = Services::AlertGetter.get_result(id).value!
95
95
  data = Entities::Alert.represent(value)
96
96
  puts JSON.pretty_generate(data.as_json)
97
97
  end
@@ -71,7 +71,7 @@ module Mihari
71
71
  # @param [Integer] id
72
72
  #
73
73
  def get(id)
74
- value = Services::ArtifactGetter.result(id).value!
74
+ value = Services::ArtifactGetter.get_result(id).value!
75
75
  data = Entities::Artifact.represent(value)
76
76
  puts JSON.pretty_generate(data.as_json)
77
77
  end
@@ -116,7 +116,7 @@ module Mihari
116
116
  desc "get ID", "Get a rule"
117
117
  around :with_db_connection
118
118
  def get(id)
119
- value = Services::RuleGetter.result(id).value!
119
+ value = Services::RuleGetter.get_result(id).value!
120
120
  data = Entities::Rule.represent(value)
121
121
  puts JSON.pretty_generate(data.as_json)
122
122
  end
@@ -44,7 +44,7 @@ module Mihari
44
44
  #
45
45
  # @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
46
46
  #
47
- def result(artifacts)
47
+ def get_result(artifacts)
48
48
  result = Try[StandardError] do
49
49
  retry_on_error(
50
50
  times: retry_times,
@@ -29,7 +29,7 @@ module Mihari
29
29
  #
30
30
  # @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
31
31
  #
32
- def result(artifact)
32
+ def get_result(artifact)
33
33
  return unless callable?(artifact)
34
34
 
35
35
  result = Try[StandardError] do
@@ -191,7 +191,7 @@ module Mihari
191
191
  # NOTE: doing parallel with ActiveRecord objects is troublesome (e.g. connection issue, etc.)
192
192
  # so converting the object to an OpenStruct object
193
193
  s = struct
194
- results = Parallel.map(enrichers) { |enricher| enricher.result s }
194
+ results = Parallel.map(enrichers) { |enricher| enricher.get_result s }
195
195
  enriched = results.compact.map { |result| result.value_or(nil) }.compact
196
196
 
197
197
  self.dns_records = enriched.map(&:dns_records).flatten.compact
@@ -18,7 +18,7 @@ module Mihari
18
18
  # @return [Array<Mihari::Port>]
19
19
  #
20
20
  def build_by_ip(ip, enricher: Enrichers::Shodan.new)
21
- enricher.result(ip).fmap do |res|
21
+ enricher.get_result(ip).fmap do |res|
22
22
  (res&.ports || []).map { |port| new(port:) }
23
23
  end.value_or []
24
24
  end
data/lib/mihari/rule.rb CHANGED
@@ -191,8 +191,8 @@ module Mihari
191
191
  return [] if enriched_artifacts.empty?
192
192
 
193
193
  [].tap do |out|
194
- out << serial_emitters.map { |emitter| emitter.result(enriched_artifacts).value_or(nil) }
195
- out << Parallel.map(parallel_emitters) { |emitter| emitter.result(enriched_artifacts).value_or(nil) }
194
+ out << serial_emitters.map { |emitter| emitter.get_result(enriched_artifacts).value_or(nil) }
195
+ out << Parallel.map(parallel_emitters) { |emitter| emitter.get_result(enriched_artifacts).value_or(nil) }
196
196
  end.flatten.compact
197
197
  end
198
198
 
@@ -349,8 +349,8 @@ module Mihari
349
349
  # @return [Array<Dry::Monads::Result::Success<Array<Mihari::Models::Artifact>>, Dry::Monads::Result::Failure>]
350
350
  def analyzer_results
351
351
  [].tap do |out|
352
- out << Parallel.map(parallel_analyzers, &:result)
353
- out << serial_analyzers.map(&:result)
352
+ out << Parallel.map(parallel_analyzers, &:get_result)
353
+ out << serial_analyzers.map(&:get_result)
354
354
  end.flatten
355
355
  end
356
356
 
@@ -11,7 +11,7 @@ module Mihari
11
11
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
12
12
  end
13
13
 
14
- def result(...)
14
+ def get_result(...)
15
15
  Try[StandardError] { call(...) }.to_result
16
16
  end
17
17
 
@@ -20,8 +20,8 @@ module Mihari
20
20
  new.call(...)
21
21
  end
22
22
 
23
- def result(...)
24
- new.result(...)
23
+ def get_result(...)
24
+ new.get_result(...)
25
25
  end
26
26
  end
27
27
  end
@@ -22,6 +22,8 @@ module Mihari
22
22
  # @param [Hash] d
23
23
  #
24
24
  def from_dynamic!(d)
25
+ return nil if d.nil?
26
+
25
27
  d = Types::Hash[d]
26
28
  new(
27
29
  asn: d.fetch("asn")
@@ -102,8 +104,8 @@ module Mihari
102
104
  attribute :location, Location
103
105
 
104
106
  # @!attribute [r] autonomous_system
105
- # @return [AutonomousSystem]
106
- attribute :autonomous_system, AutonomousSystem
107
+ # @return [AutonomousSystem, nil]
108
+ attribute :autonomous_system, AutonomousSystem.optional
107
109
 
108
110
  # @!attribute [r] metadata
109
111
  # @return [Hash]
@@ -127,7 +129,7 @@ module Mihari
127
129
  Models::Artifact.new(
128
130
  data: ip,
129
131
  metadata:,
130
- autonomous_system: autonomous_system.as,
132
+ autonomous_system: autonomous_system&.as,
131
133
  geolocation: location.geolocation,
132
134
  ports:
133
135
  )
@@ -142,7 +144,7 @@ module Mihari
142
144
  new(
143
145
  ip: d.fetch("ip"),
144
146
  location: Location.from_dynamic!(d.fetch("location")),
145
- autonomous_system: AutonomousSystem.from_dynamic!(d.fetch("autonomous_system")),
147
+ autonomous_system: AutonomousSystem.from_dynamic!(d["autonomous_system"]),
146
148
  metadata: d,
147
149
  services: d.fetch("services", []).map { |x| Service.from_dynamic!(x) }
148
150
  )
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "8.0.0"
4
+ VERSION = "8.0.2"
5
5
  end
@@ -41,7 +41,7 @@ module Mihari
41
41
  end
42
42
  get "/:id" do
43
43
  id = params[:id].to_i
44
- result = Services::AlertGetter.result(id)
44
+ result = Services::AlertGetter.get_result(id)
45
45
  return present(result.value!, with: Entities::Alert) if result.success?
46
46
 
47
47
  case result.failure
@@ -61,7 +61,7 @@ module Mihari
61
61
  end
62
62
  delete "/:id" do
63
63
  id = params["id"].to_i
64
- result = Services::AlertDestroyer.result(id)
64
+ result = Services::AlertDestroyer.get_result(id)
65
65
  return if result.success?
66
66
 
67
67
  case result.failure
@@ -86,7 +86,7 @@ module Mihari
86
86
  post "/" do
87
87
  status 201
88
88
 
89
- result = Services::AlertCreator.result(params)
89
+ result = Services::AlertCreator.get_result(params)
90
90
  return present(result.value!, with: Entities::Alert) if result.success?
91
91
 
92
92
  case result.failure
@@ -41,7 +41,7 @@ module Mihari
41
41
  end
42
42
  get "/:id" do
43
43
  id = params[:id].to_i
44
- result = Services::ArtifactGetter.result(id)
44
+ result = Services::ArtifactGetter.get_result(id)
45
45
  return present(result.value!, with: Entities::Artifact) if result.success?
46
46
 
47
47
  case result.failure
@@ -98,7 +98,7 @@ module Mihari
98
98
  status 204
99
99
 
100
100
  id = params["id"].to_i
101
- result = Services::ArtifactDestroyer.result(id)
101
+ result = Services::ArtifactDestroyer.get_result(id)
102
102
  return if result.success?
103
103
 
104
104
  case result.failure
@@ -21,7 +21,7 @@ module Mihari
21
21
  end
22
22
  get "/:ip", requirements: {ip: %r{[^/]+}} do
23
23
  ip = params[:ip].to_s
24
- result = Services::IPGetter.result(ip)
24
+ result = Services::IPGetter.get_result(ip)
25
25
  if result.success?
26
26
  value = result.value!
27
27
  return present(
@@ -59,7 +59,7 @@ module Mihari
59
59
  end
60
60
  get "/:id" do
61
61
  id = params[:id].to_s
62
- result = Services::RuleGetter.result(params[:id].to_s)
62
+ result = Services::RuleGetter.get_result(params[:id].to_s)
63
63
  return present(result.value!, with: Entities::Rule) if result.success?
64
64
 
65
65
  case result.failure
@@ -120,7 +120,7 @@ module Mihari
120
120
 
121
121
  yaml = params[:yaml].to_s
122
122
 
123
- result = RuleCreateUpdater.result(yaml, overwrite: false)
123
+ result = RuleCreateUpdater.get_result(yaml, overwrite: false)
124
124
  return present(result.value!.model, with: Entities::Rule) if result.success?
125
125
 
126
126
  failure = result.failure
@@ -151,7 +151,7 @@ module Mihari
151
151
 
152
152
  yaml = params[:yaml].to_s
153
153
 
154
- result = RuleCreateUpdater.result(yaml, overwrite: true)
154
+ result = RuleCreateUpdater.get_result(yaml, overwrite: true)
155
155
  return present(result.value!.model, with: Entities::Rule) if result.success?
156
156
 
157
157
  failure = result.failure
@@ -178,7 +178,7 @@ module Mihari
178
178
  status 204
179
179
 
180
180
  id = params[:id].to_s
181
- result = Services::RuleDestroyer.result(id)
181
+ result = Services::RuleDestroyer.get_result(id)
182
182
  return if result.success?
183
183
 
184
184
  case result.failure
@@ -43,7 +43,7 @@ module Mihari
43
43
  status 204
44
44
 
45
45
  id = params[:id].to_i
46
- result = Services::TagDestroyer.result(id)
46
+ result = Services::TagDestroyer.get_result(id)
47
47
  return if result.success?
48
48
 
49
49
  case result.failure