mihari 7.0.3 → 7.0.4

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: a5bc182d0f1c5e1ecfb08cd72d083c30a5775ea2890795dc812357da493ffb63
4
- data.tar.gz: 87fe1706c56301184b79f02d1d8be0b2deeb5591b8cfd76c3bea6d1a12005311
3
+ metadata.gz: a5859aa404d85ccc45008979195ace2c4104cc86336b65afacbeece226c7def5
4
+ data.tar.gz: 75f6687159420d8f0d7b5f2f13fbab7f523881ad55a66574a7a9ec612cf720ae
5
5
  SHA512:
6
- metadata.gz: 543e6850571451e862e95db1697482c39e796783728ddcb48dca6008b0a29e10bbe75dfabb4512dcf0b9c4ff6d31168138bc6285c2ff7131a82a2e61d5353ab1
7
- data.tar.gz: fc4e7fe111efa45d68a7b106cc61b5312f5c5be62fdc662e4daf2d3e466054deaf66eac08217f35680fbab0688eaad7642dc1a17df4bcf385b7b61c38eb31906
6
+ metadata.gz: 9db820d33af592d9b2953a01e745ce05c3a297a6cbefb409e147fd90ab5d02070722abbba18b3f282bf9abcc1cc85f50d2579ab2774ea26074d74b6aea8d6073
7
+ data.tar.gz: 8218aaf062e8ecad9cf01f58188de497ffba135ce42269e7ff87b82d49cf96c0a46c0aa273e752da1f97b288ffead8569fa00c8d6452701273e9694bcf4dba74
@@ -34,8 +34,6 @@ module Mihari
34
34
  return if Pathname(path).exist? && !(yes? warning)
35
35
 
36
36
  Services::RuleInitializer.call(path)
37
-
38
- puts "A new rule file has been initialized: #{path}."
39
37
  end
40
38
 
41
39
  desc "list [QUERY]", "List/search rules"
data/lib/mihari/rule.rb CHANGED
@@ -231,7 +231,7 @@ module Mihari
231
231
  #
232
232
  def diff?
233
233
  model = Mihari::Models::Rule.find(id)
234
- model.data != data.deep_stringify_keys
234
+ model.data != diff_comparable_data
235
235
  rescue ActiveRecord::RecordNotFound
236
236
  false
237
237
  end
@@ -272,6 +272,18 @@ module Mihari
272
272
 
273
273
  private
274
274
 
275
+ #
276
+ # @return [Hash]
277
+ #
278
+ def diff_comparable_data
279
+ # data is serialized as JSON so dates (created_on & updated_on) are stringified in there
280
+ # thus dates & (hash) keys have to be stringified when comparing
281
+ data.deep_dup.tap do |data|
282
+ data[:created_on] = data[:created_on].to_s
283
+ data[:updated_on] = data[:updated_on].to_s
284
+ end.deep_stringify_keys
285
+ end
286
+
275
287
  #
276
288
  # Check whether a value is a falsepositive value or not
277
289
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "7.0.3"
4
+ VERSION = "7.0.4"
5
5
  end
@@ -8,13 +8,16 @@ module Mihari
8
8
  #
9
9
  class IPAddresses < Grape::API
10
10
  namespace :ip_addresses do
11
- desc "Get an IP address", {
11
+ desc "Get IP address data", {
12
12
  success: Entities::IPAddress,
13
- failure: [{ code: 404, model: Entities::ErrorMessage }],
14
- summary: "Get an IP address"
13
+ failure: [
14
+ { code: 404, model: Entities::ErrorMessage },
15
+ { code: 422, model: Entities::ErrorMessage }
16
+ ],
17
+ summary: "Get IP address data"
15
18
  }
16
19
  params do
17
- requires :ip, type: String, regexp: /\A[0-9.]+\z/
20
+ requires :ip, type: String
18
21
  end
19
22
  get "/:ip", requirements: { ip: %r{[^/]+} } do
20
23
  ip = params[:ip].to_s
@@ -34,7 +37,8 @@ module Mihari
34
37
  failure = result.failure
35
38
  case failure
36
39
  when Mihari::StatusCodeError
37
- error!({ message: "ID:#{id} not found" }, 404) if failure.status_code == 404
40
+ error!({ message: "IP:#{ip} not found" }, failure.status_code) if failure.status_code == 404
41
+ error!({ message: "IP format invalid" }, failure.status_code) if failure.status_code == 422
38
42
  end
39
43
  raise failure
40
44
  end
@@ -17,7 +17,10 @@ module Mihari
17
17
  def call(yaml, overwrite: true)
18
18
  rule = Rule.from_yaml(yaml)
19
19
 
20
- raise IntegrityError, "ID:#{rule.id} is already registered" if rule.exists? && !overwrite
20
+ # To invoke ActiveRecord::RecordNotFound
21
+ Models::Rule.find(rule.id) if overwrite
22
+
23
+ raise IntegrityError, "ID:#{rule.id} already registered" if rule.exists? && !overwrite
21
24
 
22
25
  rule.update_or_create
23
26
  rule
@@ -141,13 +144,11 @@ module Mihari
141
144
  summary: "Update a rule"
142
145
  }
143
146
  params do
144
- requires :id, type: String, documentation: { param_type: "body" }
145
147
  requires :yaml, type: String, documentation: { param_type: "body" }
146
148
  end
147
149
  put "/" do
148
150
  status 201
149
151
 
150
- id = params[:id].to_s
151
152
  yaml = params[:yaml].to_s
152
153
 
153
154
  result = RuleCreateUpdater.result(yaml, overwrite: true)
@@ -156,11 +157,11 @@ module Mihari
156
157
  failure = result.failure
157
158
  case failure
158
159
  when ActiveRecord::RecordNotFound
159
- error!({ message: "ID:#{id} not found" }, 404)
160
+ error!({ message: "Rule not found" }, 404)
160
161
  when Psych::SyntaxError
161
162
  error!({ message: failure.message }, 422)
162
163
  when ValidationError
163
- error!({ message: "Rule format is invalid", detail: failure.errors.to_h }, 422)
164
+ error!({ message: "Rule format invalid", detail: failure.errors.to_h }, 422)
164
165
  end
165
166
  raise failure
166
167
  end
@@ -9,8 +9,6 @@ module Mihari
9
9
  class CaptureExceptions < Sentry::Rack::CaptureExceptions
10
10
  include Concerns::ErrorUnwrappable
11
11
 
12
- private
13
-
14
12
  def capture_exception(exception, env)
15
13
  unwrapped = unwrap_error(exception)
16
14
  Mihari.logger.error unwrapped