mihari 7.0.2 → 7.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 184d0084b9ab68c359ddaa10436a2a6172fa09e71f0cc4492af57a1afcf924d8
4
- data.tar.gz: 035620673b2351bd6c70a837c7e73f36819e320a868298b6e9a07271759bf6ed
3
+ metadata.gz: a5859aa404d85ccc45008979195ace2c4104cc86336b65afacbeece226c7def5
4
+ data.tar.gz: 75f6687159420d8f0d7b5f2f13fbab7f523881ad55a66574a7a9ec612cf720ae
5
5
  SHA512:
6
- metadata.gz: 8f16c21d9475313b8d6ef81cd12fe79c18964552f27633aa2c23fd530c92f9eece651af02fc51b3059f4e57acd6a7c5080607f2822488d26d56a0945c97c424b
7
- data.tar.gz: 25640e747ea9113d294dcb910574d7958d0883187e03f0fa891f809b1bc997722bc9af48299685d4f67d51562a6a9d6cdbec0eb499d6e1afb38410e38a7c1936
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.2"
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