From 39c3961666d989c63ab3e541dd3c23633ebee01a Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sat, 27 Jan 2024 17:06:32 +0900 Subject: [PATCH] refactor: simplify RuboCop & Standard config --- .rubocop.yml | 4 -- .standard.yml | 4 -- lib/mihari.rb | 2 +- lib/mihari/analyzers/base.rb | 2 +- lib/mihari/analyzers/binaryedge.rb | 10 ++-- lib/mihari/analyzers/censys.rb | 12 ++--- lib/mihari/analyzers/circl.rb | 4 +- lib/mihari/analyzers/crtsh.rb | 6 +-- lib/mihari/analyzers/dnstwister.rb | 4 +- lib/mihari/analyzers/feed.rb | 30 +++++------- lib/mihari/analyzers/fofa.rb | 12 ++--- lib/mihari/analyzers/greynoise.rb | 10 ++-- lib/mihari/analyzers/hunterhow.rb | 8 ++-- lib/mihari/analyzers/onyphe.rb | 10 ++-- lib/mihari/analyzers/otx.rb | 4 +- lib/mihari/analyzers/passivetotal.rb | 6 +-- lib/mihari/analyzers/pulsedive.rb | 6 +-- lib/mihari/analyzers/securitytrails.rb | 8 ++-- lib/mihari/analyzers/shodan.rb | 10 ++-- lib/mihari/analyzers/urlscan.rb | 10 ++-- lib/mihari/analyzers/virustotal.rb | 8 ++-- .../analyzers/virustotal_intelligence.rb | 10 ++-- lib/mihari/analyzers/zoomeye.rb | 10 ++-- lib/mihari/cli/application.rb | 2 +- lib/mihari/clients/base.rb | 10 ++-- lib/mihari/clients/binaryedge.rb | 12 ++--- lib/mihari/clients/censys.rb | 8 ++-- lib/mihari/clients/circl.rb | 4 +- lib/mihari/clients/crtsh.rb | 4 +- lib/mihari/clients/dnstwister.rb | 2 +- lib/mihari/clients/fofa.rb | 8 ++-- lib/mihari/clients/google_public_dns.rb | 4 +- lib/mihari/clients/greynoise.rb | 8 ++-- lib/mihari/clients/hunterhow.rb | 20 ++++---- lib/mihari/clients/misp.rb | 2 +- lib/mihari/clients/mmdb.rb | 2 +- lib/mihari/clients/onyphe.rb | 8 ++-- lib/mihari/clients/otx.rb | 2 +- lib/mihari/clients/passivetotal.rb | 10 ++-- lib/mihari/clients/publsedive.rb | 6 +-- lib/mihari/clients/securitytrails.rb | 12 ++--- lib/mihari/clients/shodan.rb | 12 ++--- lib/mihari/clients/shodan_internet_db.rb | 2 +- lib/mihari/clients/the_hive.rb | 4 +- lib/mihari/clients/urlscan.rb | 8 ++-- lib/mihari/clients/virustotal.rb | 8 ++-- lib/mihari/clients/zoomeye.rb | 24 +++++----- lib/mihari/commands/alert.rb | 2 +- lib/mihari/commands/artifact.rb | 2 +- lib/mihari/commands/rule.rb | 2 +- lib/mihari/commands/tag.rb | 2 +- lib/mihari/concerns/configurable.rb | 2 +- lib/mihari/concerns/retriable.rb | 2 +- lib/mihari/constants.rb | 4 +- lib/mihari/emitters/base.rb | 2 +- lib/mihari/emitters/database.rb | 2 +- lib/mihari/emitters/misp.rb | 8 ++-- lib/mihari/emitters/slack.rb | 18 +++---- lib/mihari/emitters/the_hive.rb | 4 +- lib/mihari/emitters/webhook.rb | 8 ++-- lib/mihari/enrichers/base.rb | 2 +- lib/mihari/enrichers/google_public_dns.rb | 2 +- lib/mihari/enrichers/mmdb.rb | 2 +- lib/mihari/enrichers/shodan.rb | 6 +-- lib/mihari/enrichers/whois.rb | 4 +- lib/mihari/entities/alert.rb | 12 ++--- lib/mihari/entities/artifact.rb | 34 ++++++------- lib/mihari/entities/autonomous_system.rb | 2 +- lib/mihari/entities/config.rb | 8 ++-- lib/mihari/entities/cpe.rb | 4 +- lib/mihari/entities/dns.rb | 6 +-- lib/mihari/entities/geolocation.rb | 6 +-- lib/mihari/entities/ip_address.rb | 6 +-- lib/mihari/entities/messages.rb | 6 +-- lib/mihari/entities/pagination.rb | 6 +-- lib/mihari/entities/port.rb | 4 +- lib/mihari/entities/reverse_dns.rb | 4 +- lib/mihari/entities/rule.rb | 16 +++---- lib/mihari/entities/tag.rb | 6 +-- lib/mihari/entities/vulnerability.rb | 4 +- lib/mihari/entities/whois.rb | 14 +++--- lib/mihari/errors.rb | 2 +- lib/mihari/models/artifact.rb | 4 +- lib/mihari/models/port.rb | 2 +- lib/mihari/rule.rb | 24 ++++------ lib/mihari/services/feed.rb | 6 +-- lib/mihari/services/proxies.rb | 2 +- lib/mihari/services/renderer.rb | 2 + lib/mihari/services/searchers.rb | 2 +- lib/mihari/sidekiq/application.rb | 4 +- lib/mihari/structs/censys.rb | 8 ++-- lib/mihari/structs/google_public_dns.rb | 6 +-- lib/mihari/structs/greynoise.rb | 4 +- lib/mihari/structs/onyphe.rb | 6 +-- lib/mihari/structs/shodan.rb | 20 ++++---- lib/mihari/structs/urlscan.rb | 2 +- lib/mihari/structs/virustotal_intelligence.rb | 4 +- lib/mihari/web/api.rb | 2 +- lib/mihari/web/application.rb | 2 +- lib/mihari/web/endpoints/alerts.rb | 24 +++++----- lib/mihari/web/endpoints/artifacts.rb | 22 ++++----- lib/mihari/web/endpoints/ip_addresses.rb | 10 ++-- lib/mihari/web/endpoints/rules.rb | 48 +++++++++---------- lib/mihari/web/endpoints/tags.rb | 8 ++-- spec/analyzers/feed_spec.rb | 4 +- spec/analyzers/hunterhow_spec.rb | 2 +- spec/analyzers/zoomeye_spec.rb | 2 +- spec/cli/alert_spec.rb | 4 +- spec/cli/artifact_spec.rb | 2 +- spec/cli/rule_spec.rb | 2 +- spec/cli/tag_spec.rb | 2 +- spec/commands/search_spec.rb | 2 +- spec/concerns/error_unwrappable_spec.rb | 6 +-- spec/concerns/retriable_spec.rb | 2 +- spec/emitters/database_spec.rb | 2 +- spec/emitters/misp_spec.rb | 2 +- spec/emitters/slack_spec.rb | 2 +- spec/emitters/the_hive_spec.rb | 4 +- spec/emitters/webhook_spec.rb | 18 +++---- spec/factories/alerts.rb | 10 ++-- spec/factories/artifacts.rb | 8 ++-- spec/factories/rules.rb | 10 ++-- spec/fixtures/templates/test.json.jbuilder | 2 + spec/http_spec.rb | 12 ++--- spec/mihari_spec.rb | 4 +- spec/models/artifact_spec.rb | 4 +- spec/rule_spec.rb | 26 +++++----- spec/schemas/rule_spec.rb | 40 ++++++++-------- spec/services/feed_parser_spec.rb | 2 +- spec/support/httpbin.rb | 18 +++---- .../shared_contexts/sidekiq_context.rb | 8 ++-- spec/web/endpoints/alerts_spec.rb | 6 +-- spec/web/endpoints/rules_spec.rb | 8 ++-- 133 files changed, 499 insertions(+), 513 deletions(-) delete mode 100644 .standard.yml diff --git a/.rubocop.yml b/.rubocop.yml index e6c8f49f2..f01b44766 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,3 @@ -Style/HashSyntax: - EnforcedShorthandSyntax: either -Style/StringLiterals: - EnforcedStyle: double_quotes Metrics/BlockLength: Max: 150 Exclude: diff --git a/.standard.yml b/.standard.yml deleted file mode 100644 index 8aad730b1..000000000 --- a/.standard.yml +++ /dev/null @@ -1,4 +0,0 @@ -ignore: - - "**/*": - - Layout/SpaceInsideHashLiteralBraces - - Style/RescueStandardError diff --git a/lib/mihari.rb b/lib/mihari.rb index 5d56e226f..4b1ff774e 100644 --- a/lib/mihari.rb +++ b/lib/mihari.rb @@ -160,7 +160,7 @@ def sidekiq? # def puma? !Puma.stats.nil? - rescue StandardError + rescue false end diff --git a/lib/mihari/analyzers/base.rb b/lib/mihari/analyzers/base.rb index 4d41a218f..edc8cd642 100644 --- a/lib/mihari/analyzers/base.rb +++ b/lib/mihari/analyzers/base.rb @@ -14,7 +14,7 @@ class Base < Actor # @param [Hash, nil] options # def initialize(query, options: nil) - super(options: options) + super(options:) @query = query end diff --git a/lib/mihari/analyzers/binaryedge.rb b/lib/mihari/analyzers/binaryedge.rb index c6bb4be59..9f03665ce 100644 --- a/lib/mihari/analyzers/binaryedge.rb +++ b/lib/mihari/analyzers/binaryedge.rb @@ -15,13 +15,13 @@ class BinaryEdge < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(query, options: options) + super(query, options:) @api_key = api_key || Mihari.config.binaryedge_api_key end def artifacts - client.search_with_pagination(query, pagination_limit: pagination_limit).map(&:artifacts).flatten + client.search_with_pagination(query, pagination_limit:).map(&:artifacts).flatten end private @@ -32,9 +32,9 @@ def artifacts # def client Clients::BinaryEdge.new( - api_key: api_key, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + pagination_interval:, + timeout: ) end end diff --git a/lib/mihari/analyzers/censys.rb b/lib/mihari/analyzers/censys.rb index 5b7296a45..acabe2a5b 100644 --- a/lib/mihari/analyzers/censys.rb +++ b/lib/mihari/analyzers/censys.rb @@ -19,7 +19,7 @@ class Censys < Base # @param [String, nil] secret # def initialize(query, options: nil, id: nil, secret: nil) - super(query, options: options) + super(query, options:) @id = id || Mihari.config.censys_id @secret = secret || Mihari.config.censys_secret @@ -29,7 +29,7 @@ def initialize(query, options: nil, id: nil, secret: nil) # @return [Array] # def artifacts - client.search_with_pagination(query, pagination_limit: pagination_limit).map do |res| + client.search_with_pagination(query, pagination_limit:).map do |res| res.result.artifacts end.flatten.uniq(&:data) end @@ -48,10 +48,10 @@ def configured? # def client Clients::Censys.new( - id: id, - secret: secret, - pagination_interval: pagination_interval, - timeout: timeout + id:, + secret:, + pagination_interval:, + timeout: ) end diff --git a/lib/mihari/analyzers/circl.rb b/lib/mihari/analyzers/circl.rb index 613708473..fff5ee6a0 100644 --- a/lib/mihari/analyzers/circl.rb +++ b/lib/mihari/analyzers/circl.rb @@ -24,7 +24,7 @@ class CIRCL < Base # @param [String, nil] password # def initialize(query, options: nil, username: nil, password: nil) - super(refang(query), options: options) + super(refang(query), options:) @type = DataType.type(query) @@ -50,7 +50,7 @@ def configured? private def client - Clients::CIRCL.new(username: username, password: password, timeout: timeout) + Clients::CIRCL.new(username:, password:, timeout:) end def username? diff --git a/lib/mihari/analyzers/crtsh.rb b/lib/mihari/analyzers/crtsh.rb index f58a0eb94..10531cf9b 100644 --- a/lib/mihari/analyzers/crtsh.rb +++ b/lib/mihari/analyzers/crtsh.rb @@ -19,7 +19,7 @@ class Crtsh < Base # @param [String, nil] match # def initialize(query, options: nil, exclude_expired: true, match: nil) - super(query, options: options) + super(query, options:) @exclude_expired = exclude_expired @match = match @@ -27,7 +27,7 @@ def initialize(query, options: nil, exclude_expired: true, match: nil) def artifacts exclude = exclude_expired ? "expired" : nil - client.search(query, exclude: exclude, match: match).map do |result| + client.search(query, exclude:, match:).map do |result| values = result["name_value"].to_s.lines.map(&:chomp).reject { |value| value.starts_with?("*.") } values.map { |value| Models::Artifact.new(data: value, metadata: result) } end.flatten @@ -39,7 +39,7 @@ def artifacts # @return [Mihari::Clients::Crtsh] # def client - Mihari::Clients::Crtsh.new(timeout: timeout) + Mihari::Clients::Crtsh.new(timeout:) end end end diff --git a/lib/mihari/analyzers/dnstwister.rb b/lib/mihari/analyzers/dnstwister.rb index 207a8ce2d..9108d9f08 100644 --- a/lib/mihari/analyzers/dnstwister.rb +++ b/lib/mihari/analyzers/dnstwister.rb @@ -16,7 +16,7 @@ class DNSTwister < Base # @param [Hash, nil] options # def initialize(query, options: nil) - super(refang(query), options: options) + super(refang(query), options:) @type = DataType.type(query) end @@ -40,7 +40,7 @@ def valid_type? end def client - Clients::DNSTwister.new(timeout: timeout) + Clients::DNSTwister.new(timeout:) end # diff --git a/lib/mihari/analyzers/feed.rb b/lib/mihari/analyzers/feed.rb index b77b17377..dd1a40521 100644 --- a/lib/mihari/analyzers/feed.rb +++ b/lib/mihari/analyzers/feed.rb @@ -28,30 +28,24 @@ class Feed < Base attr_reader :query # - # @param [String] query + # @param [String] url # @param [Hash, nil] options - # @param [String] method - # @param [Hash, nil] headers - # @param [Hash, nil] params - # @param [Hash, nil] json - # @param [form, nil] form - # @param [String] selector + # @param [Hash] params # - # @param [Object] url - def initialize(url, options: nil, method: "GET", headers: nil, params: nil, json: nil, form: nil, selector: "") - super(url, options: options) - - @method = method - @headers = headers || {} - @params = params - @json = json - @form = form - @selector = selector + def initialize(url, options: nil, **params) + super(url, options:) + + @method = params[:method] || "GET" + @headers = params[:headers] || {} + @params = params[:params] + @json = params[:json] + @form = params[:form] + @selector = params[:selector] || "" end def artifacts data = Services::FeedReader.call( - url, headers: headers, method: method, params: params, json: json, form: form, timeout: timeout + url, headers:, method:, params:, json:, form:, timeout: ) Services::FeedParser.call(data, selector) end diff --git a/lib/mihari/analyzers/fofa.rb b/lib/mihari/analyzers/fofa.rb index 1b59898e0..baa2c7456 100644 --- a/lib/mihari/analyzers/fofa.rb +++ b/lib/mihari/analyzers/fofa.rb @@ -19,14 +19,14 @@ class Fofa < Base # @param [String, nil] email # def initialize(query, options: nil, api_key: nil, email: nil) - super(query, options: options) + super(query, options:) @api_key = api_key || Mihari.config.fofa_api_key @email = email || Mihari.config.fofa_email end def artifacts - client.search_with_pagination(query, pagination_limit: pagination_limit).map do |res| + client.search_with_pagination(query, pagination_limit:).map do |res| (res.results || []).map { |result| result[1] } end.flatten.compact end @@ -46,10 +46,10 @@ def email? # def client Clients::Fofa.new( - api_key: api_key, - email: email, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + email:, + pagination_interval:, + timeout: ) end end diff --git a/lib/mihari/analyzers/greynoise.rb b/lib/mihari/analyzers/greynoise.rb index ad72ae385..fc6bcce35 100644 --- a/lib/mihari/analyzers/greynoise.rb +++ b/lib/mihari/analyzers/greynoise.rb @@ -15,7 +15,7 @@ class GreyNoise < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(query, options: options) + super(query, options:) @api_key = api_key || Mihari.config.greynoise_api_key end @@ -23,7 +23,7 @@ def initialize(query, options: nil, api_key: nil) def artifacts client.gnql_search_with_pagination( query, - pagination_limit: pagination_limit + pagination_limit: ).map(&:artifacts).flatten end @@ -31,9 +31,9 @@ def artifacts def client Clients::GreyNoise.new( - api_key: api_key, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + pagination_interval:, + timeout: ) end end diff --git a/lib/mihari/analyzers/hunterhow.rb b/lib/mihari/analyzers/hunterhow.rb index 870c6c95b..a114cf575 100644 --- a/lib/mihari/analyzers/hunterhow.rb +++ b/lib/mihari/analyzers/hunterhow.rb @@ -23,7 +23,7 @@ class HunterHow < Base # @param [String, nil] api_key # def initialize(query, start_time: nil, end_time: nil, options: nil, api_key: nil) - super(query, options: options) + super(query, options:) @api_key = api_key || Mihari.config.hunterhow_api_key @@ -48,9 +48,9 @@ def artifacts def client Clients::HunterHow.new( - api_key: api_key, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + pagination_interval:, + timeout: ) end end diff --git a/lib/mihari/analyzers/onyphe.rb b/lib/mihari/analyzers/onyphe.rb index 293971814..88170eed9 100644 --- a/lib/mihari/analyzers/onyphe.rb +++ b/lib/mihari/analyzers/onyphe.rb @@ -17,7 +17,7 @@ class Onyphe < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(query, options: options) + super(query, options:) @api_key = api_key || Mihari.config.onyphe_api_key end @@ -25,7 +25,7 @@ def initialize(query, options: nil, api_key: nil) def artifacts client.datascan_with_pagination( query, - pagination_limit: pagination_limit + pagination_limit: ).map(&:artifacts).flatten end @@ -33,9 +33,9 @@ def artifacts def client Clients::Onyphe.new( - api_key: api_key, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + pagination_interval:, + timeout: ) end end diff --git a/lib/mihari/analyzers/otx.rb b/lib/mihari/analyzers/otx.rb index c38d2ee87..021c40f90 100644 --- a/lib/mihari/analyzers/otx.rb +++ b/lib/mihari/analyzers/otx.rb @@ -20,7 +20,7 @@ class OTX < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(refang(query), options: options) + super(refang(query), options:) @type = DataType.type(query) @@ -41,7 +41,7 @@ def artifacts private def client - Mihari::Clients::OTX.new(api_key: api_key, timeout: timeout) + Mihari::Clients::OTX.new(api_key:, timeout:) end # diff --git a/lib/mihari/analyzers/passivetotal.rb b/lib/mihari/analyzers/passivetotal.rb index 6ab806859..4c77c7e1c 100644 --- a/lib/mihari/analyzers/passivetotal.rb +++ b/lib/mihari/analyzers/passivetotal.rb @@ -24,7 +24,7 @@ class PassiveTotal < Base # @param [String, nil] username # def initialize(query, options: nil, api_key: nil, username: nil) - super(refang(query), options: options) + super(refang(query), options:) @type = DataType.type(query) @@ -69,7 +69,7 @@ def reverse_whois_search res = client.reverse_whois_search(query) (res["results"] || []).map do |result| data = result["domain"] - Models::Artifact.new(data: data, metadata: result) + Models::Artifact.new(data:, metadata: result) end end @@ -82,7 +82,7 @@ def ssl_search end def client - Clients::PassiveTotal.new(username: username, api_key: api_key, timeout: timeout) + Clients::PassiveTotal.new(username:, api_key:, timeout:) end # diff --git a/lib/mihari/analyzers/pulsedive.rb b/lib/mihari/analyzers/pulsedive.rb index 543217009..604652379 100644 --- a/lib/mihari/analyzers/pulsedive.rb +++ b/lib/mihari/analyzers/pulsedive.rb @@ -20,7 +20,7 @@ class Pulsedive < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(refang(query), options: options) + super(refang(query), options:) @type = DataType.type(query) @@ -38,7 +38,7 @@ def artifacts nil else data = property["value"] - Models::Artifact.new(data: data, metadata: property) + Models::Artifact.new(data:, metadata: property) end end end @@ -46,7 +46,7 @@ def artifacts private def client - @client ||= Clients::PulseDive.new(api_key: api_key, timeout: timeout) + @client ||= Clients::PulseDive.new(api_key:, timeout:) end # diff --git a/lib/mihari/analyzers/securitytrails.rb b/lib/mihari/analyzers/securitytrails.rb index ede843c8d..31ab81b65 100644 --- a/lib/mihari/analyzers/securitytrails.rb +++ b/lib/mihari/analyzers/securitytrails.rb @@ -23,7 +23,7 @@ class SecurityTrails < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(refang(query), options: options) + super(refang(query), options:) @type = DataType.type(query) @@ -66,7 +66,7 @@ def ip_search res = client.ip_search(query) (res["records"] || []).filter_map do |record| data = record["hostname"] - Models::Artifact.new(data: data, metadata: record) + Models::Artifact.new(data:, metadata: record) end end @@ -74,12 +74,12 @@ def mail_search res = client.mail_search(query) (res["records"] || []).filter_map do |record| data = record["hostname"] - Models::Artifact.new(data: data, metadata: record) + Models::Artifact.new(data:, metadata: record) end end def client - Clients::SecurityTrails.new(api_key: api_key, timeout: timeout) + Clients::SecurityTrails.new(api_key:, timeout:) end # diff --git a/lib/mihari/analyzers/shodan.rb b/lib/mihari/analyzers/shodan.rb index b1870dad5..dfa94183c 100644 --- a/lib/mihari/analyzers/shodan.rb +++ b/lib/mihari/analyzers/shodan.rb @@ -15,7 +15,7 @@ class Shodan < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(query, options: options) + super(query, options:) @api_key = api_key || Mihari.config.shodan_api_key end @@ -23,7 +23,7 @@ def initialize(query, options: nil, api_key: nil) def artifacts client.search_with_pagination( query, - pagination_limit: pagination_limit + pagination_limit: ).map(&:artifacts).flatten.uniq(&:data) end @@ -34,9 +34,9 @@ def artifacts # def client Clients::Shodan.new( - api_key: api_key, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + pagination_interval:, + timeout: ) end end diff --git a/lib/mihari/analyzers/urlscan.rb b/lib/mihari/analyzers/urlscan.rb index 27d06f00c..8b40d38f1 100644 --- a/lib/mihari/analyzers/urlscan.rb +++ b/lib/mihari/analyzers/urlscan.rb @@ -21,7 +21,7 @@ class Urlscan < Base # @param [Array] allowed_data_types # def initialize(query, options: nil, api_key: nil, allowed_data_types: SUPPORTED_DATA_TYPES) - super(query, options: options) + super(query, options:) @api_key = api_key || Mihari.config.urlscan_api_key @allowed_data_types = allowed_data_types @@ -33,7 +33,7 @@ def initialize(query, options: nil, api_key: nil, allowed_data_types: SUPPORTED_ def artifacts # @type [Array] - artifacts = client.search_with_pagination(query, pagination_limit: pagination_limit).map(&:artifacts).flatten + artifacts = client.search_with_pagination(query, pagination_limit:).map(&:artifacts).flatten artifacts.select { |artifact| allowed_data_types.include? artifact.data_type } end @@ -41,9 +41,9 @@ def artifacts def client Clients::Urlscan.new( - api_key: api_key, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + pagination_interval:, + timeout: ) end diff --git a/lib/mihari/analyzers/virustotal.rb b/lib/mihari/analyzers/virustotal.rb index c020f4c2f..904402297 100644 --- a/lib/mihari/analyzers/virustotal.rb +++ b/lib/mihari/analyzers/virustotal.rb @@ -20,7 +20,7 @@ class VirusTotal < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(refang(query), options: options) + super(refang(query), options:) @type = DataType.type(query) @@ -50,7 +50,7 @@ def key_aliases private def client - Clients::VirusTotal.new(api_key: api_key) + Clients::VirusTotal.new(api_key:) end # @@ -73,7 +73,7 @@ def domain_search data = res["data"] || [] data.filter_map do |item| data = item.dig("attributes", "ip_address") - data.nil? ? nil : Models::Artifact.new(data: data, metadata: item) + data.nil? ? nil : Models::Artifact.new(data:, metadata: item) end end @@ -88,7 +88,7 @@ def ip_search data = res["data"] || [] data.filter_map do |item| data = item.dig("attributes", "host_name") - Models::Artifact.new(data: data, metadata: item) + Models::Artifact.new(data:, metadata: item) end.uniq end end diff --git a/lib/mihari/analyzers/virustotal_intelligence.rb b/lib/mihari/analyzers/virustotal_intelligence.rb index e47b65353..040eac565 100644 --- a/lib/mihari/analyzers/virustotal_intelligence.rb +++ b/lib/mihari/analyzers/virustotal_intelligence.rb @@ -15,13 +15,13 @@ class VirusTotalIntelligence < Base # @param [String, nil] api_key # def initialize(query, options: nil, api_key: nil) - super(query, options: options) + super(query, options:) @api_key = api_key || Mihari.config.virustotal_api_key end def artifacts - client.intel_search_with_pagination(query, pagination_limit: pagination_limit).map(&:artifacts).flatten + client.intel_search_with_pagination(query, pagination_limit:).map(&:artifacts).flatten end class << self @@ -56,9 +56,9 @@ def configuration_keys # def client Clients::VirusTotal.new( - api_key: api_key, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + pagination_interval:, + timeout: ) end end diff --git a/lib/mihari/analyzers/zoomeye.rb b/lib/mihari/analyzers/zoomeye.rb index 545d5a261..b2c773f1b 100644 --- a/lib/mihari/analyzers/zoomeye.rb +++ b/lib/mihari/analyzers/zoomeye.rb @@ -19,7 +19,7 @@ class ZoomEye < Base # @param [String] type # def initialize(query, options: nil, api_key: nil, type: "host") - super(query, options: options) + super(query, options:) @type = type @api_key = api_key || Mihari.config.zoomeye_api_key @@ -53,9 +53,9 @@ def valid_type? def client Clients::ZoomEye.new( - api_key: api_key, - pagination_interval: pagination_interval, - timeout: timeout + api_key:, + pagination_interval:, + timeout: ) end @@ -74,7 +74,7 @@ def convert(res) if data.is_a?(Array) data.map { |d| Models::Artifact.new(data: d, metadata: match) } else - Models::Artifact.new(data: data, metadata: match) + Models::Artifact.new(data:, metadata: match) end end.flatten end diff --git a/lib/mihari/cli/application.rb b/lib/mihari/cli/application.rb index f772a6704..578c8c8cb 100644 --- a/lib/mihari/cli/application.rb +++ b/lib/mihari/cli/application.rb @@ -55,7 +55,7 @@ def error_to_detail(error) def safe_execute yield - rescue StandardError => e + rescue => e error = unwrap_error(e) # Raise error if it's a Thor::Error to follow Thor's manner diff --git a/lib/mihari/clients/base.rb b/lib/mihari/clients/base.rb index 2fc5f1047..5e942ffc6 100644 --- a/lib/mihari/clients/base.rb +++ b/lib/mihari/clients/base.rb @@ -41,7 +41,7 @@ def sleep_pagination_interval # @return [::HTTP::Client] # def http - @http ||= HTTP::Factory.build(headers: headers, timeout: timeout) + @http ||= HTTP::Factory.build(headers:, timeout:) end # @@ -60,7 +60,7 @@ def url_for(path) # @return [::HTTP::Response] # def get(path, params: nil) - http.get(url_for(path), params: params) + http.get(url_for(path), params:) end # @@ -70,7 +70,7 @@ def get(path, params: nil) # @return [Hash] # def get_json(path, params: nil) - res = get(path, params: params) + res = get(path, params:) JSON.parse res.body.to_s end @@ -81,7 +81,7 @@ def get_json(path, params: nil) # @return [::HTTP::Response] # def post(path, json: {}) - http.post(url_for(path), json: json) + http.post(url_for(path), json:) end # @@ -91,7 +91,7 @@ def post(path, json: {}) # @return [Hash] # def post_json(path, json: {}) - res = http.post(url_for(path), json: json) + res = http.post(url_for(path), json:) JSON.parse res.body.to_s end end diff --git a/lib/mihari/clients/binaryedge.rb b/lib/mihari/clients/binaryedge.rb index 0ff1a0509..c48ae4f5f 100644 --- a/lib/mihari/clients/binaryedge.rb +++ b/lib/mihari/clients/binaryedge.rb @@ -22,7 +22,7 @@ def initialize( ) headers["x-key"] = api_key - super(base_url, headers: headers, timeout: timeout, pagination_interval: pagination_interval) + super(base_url, headers:, timeout:, pagination_interval:) end # @@ -34,11 +34,11 @@ def initialize( # def search(query, page: 1, only_ips: nil) params = { - query: query, - page: page, - only_ips: only_ips + query:, + page:, + only_ips: }.compact - Structs::BinaryEdge::Response.from_dynamic! get_json("/v2/query/search", params: params) + Structs::BinaryEdge::Response.from_dynamic! get_json("/v2/query/search", params:) end # @@ -51,7 +51,7 @@ def search(query, page: 1, only_ips: nil) def search_with_pagination(query, only_ips: nil, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| - res = search(query, page: page, only_ips: only_ips) + res = search(query, page:, only_ips:) y.yield res diff --git a/lib/mihari/clients/censys.rb b/lib/mihari/clients/censys.rb index 07fbf2928..eafeef19a 100644 --- a/lib/mihari/clients/censys.rb +++ b/lib/mihari/clients/censys.rb @@ -29,7 +29,7 @@ def initialize( headers["authorization"] = "Basic #{Base64.strict_encode64("#{id}:#{secret}")}" - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) end # @@ -45,8 +45,8 @@ def initialize( # @return [Mihari::Structs::Censys::Response] # def search(query, per_page: nil, cursor: nil) - params = { q: query, per_page: per_page, cursor: cursor }.compact - Structs::Censys::Response.from_dynamic! get_json("/api/v2/hosts/search", params: params) + params = {q: query, per_page:, cursor:}.compact + Structs::Censys::Response.from_dynamic! get_json("/api/v2/hosts/search", params:) end # @@ -61,7 +61,7 @@ def search_with_pagination(query, per_page: nil, pagination_limit: Mihari.config Enumerator.new do |y| pagination_limit.times do - res = search(query, per_page: per_page, cursor: cursor) + res = search(query, per_page:, cursor:) y.yield res diff --git a/lib/mihari/clients/circl.rb b/lib/mihari/clients/circl.rb index 0321c88db..a3fc77d59 100644 --- a/lib/mihari/clients/circl.rb +++ b/lib/mihari/clients/circl.rb @@ -21,7 +21,7 @@ def initialize(base_url = "https://www.circl.lu", username:, password:, headers: headers["authorization"] = "Basic #{Base64.strict_encode64("#{username}:#{password}")}" - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # @@ -77,7 +77,7 @@ def ssl_cquery(query) # @param [Hash] params # def _get(path, params: {}) - res = get(path, params: params) + res = get(path, params:) body = res.body.to_s content_type = res["Content-Type"].to_s diff --git a/lib/mihari/clients/crtsh.rb b/lib/mihari/clients/crtsh.rb index 2546a6e96..e0fe1d069 100644 --- a/lib/mihari/clients/crtsh.rb +++ b/lib/mihari/clients/crtsh.rb @@ -12,7 +12,7 @@ class Crtsh < Base # @param [Integer, nil] timeout # def initialize(base_url = "https://crt.sh", headers: {}, timeout: nil) - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # @@ -25,7 +25,7 @@ def initialize(base_url = "https://crt.sh", headers: {}, timeout: nil) # @return [Array] # def search(identity, match: nil, exclude: nil) - get_json("/", params: { identity: identity, match: match, exclude: exclude, output: "json" }.compact) + get_json("/", params: {identity:, match:, exclude:, output: "json"}.compact) end end end diff --git a/lib/mihari/clients/dnstwister.rb b/lib/mihari/clients/dnstwister.rb index c86341380..0f4f8462e 100644 --- a/lib/mihari/clients/dnstwister.rb +++ b/lib/mihari/clients/dnstwister.rb @@ -12,7 +12,7 @@ class DNSTwister < Base # @param [Integer, nil] timeout # def initialize(base_url = "https://dnstwister.report", headers: {}, timeout: nil) - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # diff --git a/lib/mihari/clients/fofa.rb b/lib/mihari/clients/fofa.rb index 07700ccf1..387f5ff98 100644 --- a/lib/mihari/clients/fofa.rb +++ b/lib/mihari/clients/fofa.rb @@ -39,7 +39,7 @@ def initialize( @api_key = api_key @email = email - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) end # @@ -51,8 +51,8 @@ def initialize( # def search(query, page:, size: PAGE_SIZE) qbase64 = Base64.urlsafe_encode64(query) - params = { qbase64: qbase64, size: size, page: page, email: email, key: api_key }.compact - res = Structs::Fofa::Response.from_dynamic!(get_json("/api/v1/search/all", params: params)) + params = {qbase64:, size:, page:, email:, key: api_key}.compact + res = Structs::Fofa::Response.from_dynamic!(get_json("/api/v1/search/all", params:)) raise ResponseError, res.errmsg if res.error res @@ -68,7 +68,7 @@ def search(query, page:, size: PAGE_SIZE) def search_with_pagination(query, size: PAGE_SIZE, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| - res = search(query, page: page, size: size) + res = search(query, page:, size:) y.yield res diff --git a/lib/mihari/clients/google_public_dns.rb b/lib/mihari/clients/google_public_dns.rb index 34372c800..0905aab1d 100644 --- a/lib/mihari/clients/google_public_dns.rb +++ b/lib/mihari/clients/google_public_dns.rb @@ -12,7 +12,7 @@ class GooglePublicDNS < Base # @param [Integer, nil] timeout # def initialize(base_url = "https://dns.google", headers: {}, timeout: nil) - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # @@ -24,7 +24,7 @@ def initialize(base_url = "https://dns.google", headers: {}, timeout: nil) # def query_all(name) Structs::GooglePublicDNS::Response.from_dynamic! get_json("/resolve", - params: { name: name, type: "ALL" }) + params: {name:, type: "ALL"}) end end end diff --git a/lib/mihari/clients/greynoise.rb b/lib/mihari/clients/greynoise.rb index cf1303d06..51f0c8666 100644 --- a/lib/mihari/clients/greynoise.rb +++ b/lib/mihari/clients/greynoise.rb @@ -25,7 +25,7 @@ def initialize( raise(ArgumentError, "api_key is required") unless api_key headers["key"] = api_key - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) end # @@ -38,8 +38,8 @@ def initialize( # @return [Mihari::Structs::GreyNoise::Response] # def gnql_search(query, size: PAGE_SIZE, scroll: nil) - params = { query: query, size: size, scroll: scroll }.compact - Structs::GreyNoise::Response.from_dynamic! get_json("/v2/experimental/gnql", params: params) + params = {query:, size:, scroll:}.compact + Structs::GreyNoise::Response.from_dynamic! get_json("/v2/experimental/gnql", params:) end # @@ -54,7 +54,7 @@ def gnql_search_with_pagination(query, size: PAGE_SIZE, pagination_limit: Mihari Enumerator.new do |y| pagination_limit.times do - res = gnql_search(query, size: size, scroll: scroll) + res = gnql_search(query, size:, scroll:) y.yield res diff --git a/lib/mihari/clients/hunterhow.rb b/lib/mihari/clients/hunterhow.rb index 169578431..6306dd7b3 100644 --- a/lib/mihari/clients/hunterhow.rb +++ b/lib/mihari/clients/hunterhow.rb @@ -29,7 +29,7 @@ def initialize( ) raise(ArgumentError, "api_key is required") unless api_key - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) @api_key = api_key end @@ -46,13 +46,13 @@ def initialize( def search(query, start_time:, end_time:, page: 1, page_size: PAGE_SIZE) params = { query: Base64.urlsafe_encode64(query), - page: page, - page_size: page_size, - start_time: start_time, - end_time: end_time, + page:, + page_size:, + start_time:, + end_time:, "api-key": api_key }.compact - Structs::HunterHow::Response.from_dynamic! get_json("/search", params: params) + Structs::HunterHow::Response.from_dynamic! get_json("/search", params:) end # @@ -75,10 +75,10 @@ def search_with_pagination( (1..pagination_limit).each do |page| res = search( query, - start_time: start_time, - end_time: end_time, - page: page, - page_size: page_size + start_time:, + end_time:, + page:, + page_size: ) y.yield res diff --git a/lib/mihari/clients/misp.rb b/lib/mihari/clients/misp.rb index 82e1569c7..ad014684c 100644 --- a/lib/mihari/clients/misp.rb +++ b/lib/mihari/clients/misp.rb @@ -18,7 +18,7 @@ def initialize(base_url, api_key:, headers: {}, timeout: nil) headers["authorization"] = api_key headers["accept"] = "application/json" - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # diff --git a/lib/mihari/clients/mmdb.rb b/lib/mihari/clients/mmdb.rb index 6facc8a74..77d6309e5 100644 --- a/lib/mihari/clients/mmdb.rb +++ b/lib/mihari/clients/mmdb.rb @@ -12,7 +12,7 @@ class MMDB < Base # @param [Integer, nil] timeout # def initialize(base_url = "https://ip.circl.lu", headers: {}, timeout: nil) - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # diff --git a/lib/mihari/clients/onyphe.rb b/lib/mihari/clients/onyphe.rb index 0e4663d53..b37fa3d48 100644 --- a/lib/mihari/clients/onyphe.rb +++ b/lib/mihari/clients/onyphe.rb @@ -27,7 +27,7 @@ def initialize( ) raise(ArgumentError, "api_key is required") if api_key.nil? - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) @api_key = api_key end @@ -39,8 +39,8 @@ def initialize( # @return [Mihari::Structs::Onyphe::Response] # def datascan(query, page: 1) - params = { page: page, apikey: api_key } - Structs::Onyphe::Response.from_dynamic! get_json("/api/v2/simple/datascan/#{query}", params: params) + params = {page:, apikey: api_key} + Structs::Onyphe::Response.from_dynamic! get_json("/api/v2/simple/datascan/#{query}", params:) end # @@ -52,7 +52,7 @@ def datascan(query, page: 1) def datascan_with_pagination(query, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| - res = datascan(query, page: page) + res = datascan(query, page:) y.yield res diff --git a/lib/mihari/clients/otx.rb b/lib/mihari/clients/otx.rb index de81fbbc3..3c8888f29 100644 --- a/lib/mihari/clients/otx.rb +++ b/lib/mihari/clients/otx.rb @@ -16,7 +16,7 @@ def initialize(base_url = "https://otx.alienvault.com", api_key:, headers: {}, t raise(ArgumentError, "api_key is required") unless api_key headers["x-otx-api-key"] = api_key - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # diff --git a/lib/mihari/clients/passivetotal.rb b/lib/mihari/clients/passivetotal.rb index a5060f2cd..cf47c8277 100644 --- a/lib/mihari/clients/passivetotal.rb +++ b/lib/mihari/clients/passivetotal.rb @@ -21,7 +21,7 @@ def initialize(base_url = "https://api.passivetotal.org", username:, api_key:, h headers["authorization"] = "Basic #{Base64.strict_encode64("#{username}:#{api_key}")}" - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # @@ -32,8 +32,8 @@ def initialize(base_url = "https://api.passivetotal.org", username:, api_key:, h # @return [Hash] # def passive_dns_search(query) - params = { query: query } - get_json("/v2/dns/passive/unique", params: params) + params = {query:} + get_json("/v2/dns/passive/unique", params:) end # @@ -45,7 +45,7 @@ def passive_dns_search(query) # def reverse_whois_search(query) get_json("/v2/whois/search", params: { - query: query, + query:, field: "email" }.compact) end @@ -58,7 +58,7 @@ def reverse_whois_search(query) # @return [Hash] # def ssl_search(query) - get_json("/v2/ssl-certificate/history", params: { query: query }) + get_json("/v2/ssl-certificate/history", params: {query:}) end end end diff --git a/lib/mihari/clients/publsedive.rb b/lib/mihari/clients/publsedive.rb index d25cadf0e..355197717 100644 --- a/lib/mihari/clients/publsedive.rb +++ b/lib/mihari/clients/publsedive.rb @@ -20,7 +20,7 @@ def initialize(base_url = "https://pulsedive.com", api_key:, headers: {}, timeou @api_key = api_key - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # @@ -29,7 +29,7 @@ def initialize(base_url = "https://pulsedive.com", api_key:, headers: {}, timeou # @return [Hash] # def get_indicator(ip_or_domain) - get_json "/api/info.php", params: { indicator: ip_or_domain, key: api_key } + get_json "/api/info.php", params: {indicator: ip_or_domain, key: api_key} end # @@ -38,7 +38,7 @@ def get_indicator(ip_or_domain) # @return [Hash] # def get_properties(indicator_id) - get_json "/api/info.php", params: { iid: indicator_id, get: "properties", key: api_key } + get_json "/api/info.php", params: {iid: indicator_id, get: "properties", key: api_key} end end end diff --git a/lib/mihari/clients/securitytrails.rb b/lib/mihari/clients/securitytrails.rb index 4b437bc26..db556a642 100644 --- a/lib/mihari/clients/securitytrails.rb +++ b/lib/mihari/clients/securitytrails.rb @@ -17,7 +17,7 @@ def initialize(base_url = "https://api.securitytrails.com", api_key:, headers: { headers["apikey"] = api_key - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # @@ -48,7 +48,7 @@ def mail_search(query) # @return [Hash] # def search_by_mail(mail) - post_json "/v1/domains/list", json: { filter: { whois_email: mail } } + post_json "/v1/domains/list", json: {filter: {whois_email: mail}} end # @@ -57,7 +57,7 @@ def search_by_mail(mail) # @return [Hash] # def search_by_ip(ip) - post_json "/v1/domains/list", json: { filter: { ipv4: ip } } + post_json "/v1/domains/list", json: {filter: {ipv4: ip}} end # @@ -69,13 +69,13 @@ def search_by_ip(ip) # def get_all_dns_history(domain, type:, page: 1) Enumerator.new do |y| - res = get_dns_history(domain, type: type, page: page) + res = get_dns_history(domain, type:, page:) y.yield res pages = res["pages"].to_i (page + 1..pages).each do |page| - y.yield get_dns_history(domain, type: type, page: page) + y.yield get_dns_history(domain, type:, page:) end end end @@ -90,7 +90,7 @@ def get_all_dns_history(domain, type:, page: 1) # @return [Hash] # def get_dns_history(domain, type:, page:) - get_json "/v1/history/#{domain}/dns/#{type}", params: { page: page } + get_json "/v1/history/#{domain}/dns/#{type}", params: {page:} end end end diff --git a/lib/mihari/clients/shodan.rb b/lib/mihari/clients/shodan.rb index 827989714..47d891735 100644 --- a/lib/mihari/clients/shodan.rb +++ b/lib/mihari/clients/shodan.rb @@ -27,7 +27,7 @@ def initialize( ) raise(ArgumentError, "api_key is required") unless api_key - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) @api_key = api_key end @@ -41,12 +41,12 @@ def initialize( # def search(query, page: 1, minify: true) params = { - query: query, - page: page, - minify: minify, + query:, + page:, + minify:, key: api_key } - Structs::Shodan::Response.from_dynamic! get_json("/shodan/host/search", params: params) + Structs::Shodan::Response.from_dynamic! get_json("/shodan/host/search", params:) end # @@ -59,7 +59,7 @@ def search(query, page: 1, minify: true) def search_with_pagination(query, minify: true, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| - res = search(query, page: page, minify: minify) + res = search(query, page:, minify:) y.yield res diff --git a/lib/mihari/clients/shodan_internet_db.rb b/lib/mihari/clients/shodan_internet_db.rb index 7b0605506..4562b0f53 100644 --- a/lib/mihari/clients/shodan_internet_db.rb +++ b/lib/mihari/clients/shodan_internet_db.rb @@ -12,7 +12,7 @@ class ShodanInternetDB < Base # @param [Integer, nil] timeout # def initialize(base_url = "https://internetdb.shodan.io", headers: {}, timeout: nil) - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) end # diff --git a/lib/mihari/clients/the_hive.rb b/lib/mihari/clients/the_hive.rb index 04346f7c8..f0ec67e91 100644 --- a/lib/mihari/clients/the_hive.rb +++ b/lib/mihari/clients/the_hive.rb @@ -19,7 +19,7 @@ def initialize(base_url, api_key:, api_version: "v1", headers: {}, timeout: nil) raise(ArgumentError, "api_key is required") unless api_key headers["authorization"] = "Bearer #{api_key}" - super(base_url, headers: headers, timeout: timeout) + super(base_url, headers:, timeout:) @api_version = api_version end @@ -31,7 +31,7 @@ def initialize(base_url, api_key:, api_version: "v1", headers: {}, timeout: nil) # def alert(json) json = json.to_camelback_keys.compact - post_json("/api/#{api_version}/alert", json: json) + post_json("/api/#{api_version}/alert", json:) end end end diff --git a/lib/mihari/clients/urlscan.rb b/lib/mihari/clients/urlscan.rb index c40a0799e..e18e7772a 100644 --- a/lib/mihari/clients/urlscan.rb +++ b/lib/mihari/clients/urlscan.rb @@ -24,7 +24,7 @@ def initialize( headers["api-key"] = api_key - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) end # @@ -35,8 +35,8 @@ def initialize( # @return [Mihari::Structs::Urlscan::Response] # def search(q, size: nil, search_after: nil) - params = { q: q, size: size, search_after: search_after }.compact - Structs::Urlscan::Response.from_dynamic! get_json("/api/v1/search/", params: params) + params = {q:, size:, search_after:}.compact + Structs::Urlscan::Response.from_dynamic! get_json("/api/v1/search/", params:) end # @@ -51,7 +51,7 @@ def search_with_pagination(q, size: nil, pagination_limit: Mihari.config.paginat Enumerator.new do |y| pagination_limit.times do - res = search(q, size: size, search_after: search_after) + res = search(q, size:, search_after:) y.yield res diff --git a/lib/mihari/clients/virustotal.rb b/lib/mihari/clients/virustotal.rb index 74755b585..aeaf3a767 100644 --- a/lib/mihari/clients/virustotal.rb +++ b/lib/mihari/clients/virustotal.rb @@ -24,7 +24,7 @@ def initialize( headers["x-apikey"] = api_key - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) end # @@ -52,8 +52,8 @@ def ip_search(query) # @return [Mihari::Structs::VirusTotalIntelligence::Response] # def intel_search(query, cursor: nil) - params = { query: query, cursor: cursor }.compact - Structs::VirusTotalIntelligence::Response.from_dynamic! get_json("/api/v3/intelligence/search", params: params) + params = {query:, cursor:}.compact + Structs::VirusTotalIntelligence::Response.from_dynamic! get_json("/api/v3/intelligence/search", params:) end # @@ -67,7 +67,7 @@ def intel_search_with_pagination(query, pagination_limit: Mihari.config.paginati Enumerator.new do |y| pagination_limit.times do - res = intel_search(query, cursor: cursor) + res = intel_search(query, cursor:) y.yield res diff --git a/lib/mihari/clients/zoomeye.rb b/lib/mihari/clients/zoomeye.rb index 5f03af422..d6f7b956b 100644 --- a/lib/mihari/clients/zoomeye.rb +++ b/lib/mihari/clients/zoomeye.rb @@ -27,14 +27,14 @@ def initialize( raise(ArgumentError, "api_key is required") unless api_key headers["api-key"] = api_key - super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout) + super(base_url, headers:, pagination_interval:, timeout:) end # # @return [::HTTP::Client] # def http - @http ||= HTTP::Factory.build(headers: headers, timeout: timeout, raise_exception: false) + @http ||= HTTP::Factory.build(headers:, timeout:, raise_exception: false) end # @@ -48,11 +48,11 @@ def http # def host_search(query, page: nil, facets: nil) params = { - query: query, - page: page, - facets: facets + query:, + page:, + facets: }.compact - get_json "/host/search", params: params + get_json "/host/search", params: end # @@ -65,7 +65,7 @@ def host_search(query, page: nil, facets: nil) def host_search_with_pagination(query, facets: nil, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| - res = host_search(query, facets: facets, page: page) + res = host_search(query, facets:, page:) break if res.nil? @@ -90,11 +90,11 @@ def host_search_with_pagination(query, facets: nil, pagination_limit: Mihari.con # def web_search(query, page: nil, facets: nil) params = { - query: query, - page: page, - facets: facets + query:, + page:, + facets: }.compact - get_json "/web/search", params: params + get_json "/web/search", params: end # @@ -107,7 +107,7 @@ def web_search(query, page: nil, facets: nil) def web_search_with_pagination(query, facets: nil, pagination_limit: Mihari.config.pagination_limit) Enumerator.new do |y| (1..pagination_limit).each do |page| - res = web_search(query, facets: facets, page: page) + res = web_search(query, facets:, page:) break if res.nil? diff --git a/lib/mihari/commands/alert.rb b/lib/mihari/commands/alert.rb index ba91692e5..678be7301 100644 --- a/lib/mihari/commands/alert.rb +++ b/lib/mihari/commands/alert.rb @@ -21,7 +21,7 @@ def included(thor) # @return [Mihari::Services::ResultValue] # def _search(q, page: 1, limit: 10) - filter = Structs::Filters::Search.new(q: q, page: page, limit: limit) + filter = Structs::Filters::Search.new(q:, page:, limit:) Services::AlertSearcher.result(filter).value! end end diff --git a/lib/mihari/commands/artifact.rb b/lib/mihari/commands/artifact.rb index 7e2b2e08b..be30b2927 100644 --- a/lib/mihari/commands/artifact.rb +++ b/lib/mihari/commands/artifact.rb @@ -20,7 +20,7 @@ def included(thor) # @return [Mihari::Services::ResultValue] # def _search(q, page: 1, limit: 10) - filter = Structs::Filters::Search.new(q: q, page: page, limit: limit) + filter = Structs::Filters::Search.new(q:, page:, limit:) Services::ArtifactSearcher.result(filter).value! end end diff --git a/lib/mihari/commands/rule.rb b/lib/mihari/commands/rule.rb index 53bcb12fe..85d38bebf 100644 --- a/lib/mihari/commands/rule.rb +++ b/lib/mihari/commands/rule.rb @@ -21,7 +21,7 @@ def included(thor) # @return [Mihari::Services::ResultValue] # def _search(q, page: 1, limit: 10) - filter = Structs::Filters::Search.new(q: q, page: page, limit: limit) + filter = Structs::Filters::Search.new(q:, page:, limit:) Services::RuleSearcher.result(filter).value! end end diff --git a/lib/mihari/commands/tag.rb b/lib/mihari/commands/tag.rb index 414f3031c..a432edf11 100644 --- a/lib/mihari/commands/tag.rb +++ b/lib/mihari/commands/tag.rb @@ -20,7 +20,7 @@ def included(thor) # @return [Mihari::Services::ResultValue] # def _search(q, page: 1, limit: 10) - filter = Structs::Filters::Search.new(q: q, page: page, limit: limit) + filter = Structs::Filters::Search.new(q:, page:, limit:) Services::TagSearcher.result(filter).value! end end diff --git a/lib/mihari/concerns/configurable.rb b/lib/mihari/concerns/configurable.rb index 427d0f86f..07cec5016 100644 --- a/lib/mihari/concerns/configurable.rb +++ b/lib/mihari/concerns/configurable.rb @@ -40,7 +40,7 @@ def configuration_items configuration_keys.map do |key| value = Mihari.config.send(key) value = "REDACTED" if value && Mihari.config.hide_config_values - { key: key.upcase, value: value } + {key: key.upcase, value:} end end diff --git a/lib/mihari/concerns/retriable.rb b/lib/mihari/concerns/retriable.rb index 1609c1022..edffde9ee 100644 --- a/lib/mihari/concerns/retriable.rb +++ b/lib/mihari/concerns/retriable.rb @@ -41,7 +41,7 @@ def retry_on_error(times: 3, interval: 5, exponential_backoff: true, condition: begin try += 1 yield - rescue StandardError => e + rescue => e # Raise error if it's not a retriable error raise e unless condition.call(e) diff --git a/lib/mihari/constants.rb b/lib/mihari/constants.rb index 8e1a92d86..62b6dc7e9 100644 --- a/lib/mihari/constants.rb +++ b/lib/mihari/constants.rb @@ -5,8 +5,8 @@ module Mihari DEFAULT_DATA_TYPES = Types::DataTypes.values.freeze # @return [Array] - DEFAULT_EMITTERS = Emitters::Database.keys.map { |name| { emitter: name.downcase } }.freeze + DEFAULT_EMITTERS = Emitters::Database.keys.map { |name| {emitter: name.downcase} }.freeze # @return [Array] - DEFAULT_ENRICHERS = Mihari.enricher_to_class.keys.map { |name| { enricher: name.downcase } }.freeze + DEFAULT_ENRICHERS = Mihari.enricher_to_class.keys.map { |name| {enricher: name.downcase} }.freeze end diff --git a/lib/mihari/emitters/base.rb b/lib/mihari/emitters/base.rb index c3162886f..8e4eac0af 100644 --- a/lib/mihari/emitters/base.rb +++ b/lib/mihari/emitters/base.rb @@ -14,7 +14,7 @@ class Base < Actor # @param [Hash, nil] options # def initialize(rule:, options: nil) - super(options: options) + super(options:) @rule = rule end diff --git a/lib/mihari/emitters/database.rb b/lib/mihari/emitters/database.rb index 7404af324..3d527785a 100644 --- a/lib/mihari/emitters/database.rb +++ b/lib/mihari/emitters/database.rb @@ -16,7 +16,7 @@ class Database < Base def call(artifacts) return if artifacts.empty? - alert = Models::Alert.new(artifacts: artifacts, rule_id: rule.id) + alert = Models::Alert.new(artifacts:, rule_id: rule.id) alert.save alert end diff --git a/lib/mihari/emitters/misp.rb b/lib/mihari/emitters/misp.rb index 6967c040c..48301cbbe 100644 --- a/lib/mihari/emitters/misp.rb +++ b/lib/mihari/emitters/misp.rb @@ -24,7 +24,7 @@ class MISP < Base # @param [Hash, nil] params # def initialize(rule:, options: nil, **params) - super(rule: rule, options: options) + super(rule:, options:) @url = params[:url] || Mihari.config.misp_url @api_key = params[:api_key] || Mihari.config.misp_api_key @@ -51,7 +51,7 @@ def call(artifacts) Event: { info: rule.title, Attribute: artifacts.map { |artifact| build_attribute(artifact) }, - Tag: rule.tags.map { |tag| { name: tag } } + Tag: rule.tags.map { |tag| {name: tag} } } }) end @@ -66,7 +66,7 @@ def target private def client - @client ||= Clients::MISP.new(url, api_key: api_key, timeout: timeout) + @client ||= Clients::MISP.new(url, api_key:, timeout:) end # @@ -77,7 +77,7 @@ def client # @return [Hash] # def build_attribute(artifact) - { value: artifact.data, type: to_misp_type(type: artifact.data_type, value: artifact.data) } + {value: artifact.data, type: to_misp_type(type: artifact.data_type, value: artifact.data)} end # diff --git a/lib/mihari/emitters/slack.rb b/lib/mihari/emitters/slack.rb index 0b46d5c59..6e9fc925a 100644 --- a/lib/mihari/emitters/slack.rb +++ b/lib/mihari/emitters/slack.rb @@ -30,25 +30,25 @@ def actions def vt_link return nil unless _vt_link - { type: "button", text: "VirusTotal", url: _vt_link } + {type: "button", text: "VirusTotal", url: _vt_link} end def urlscan_link return nil unless _urlscan_link - { type: "button", text: "urlscan.io", url: _urlscan_link } + {type: "button", text: "urlscan.io", url: _urlscan_link} end def censys_link return nil unless _censys_link - { type: "button", text: "Censys", url: _censys_link } + {type: "button", text: "Censys", url: _censys_link} end def shodan_link return nil unless _shodan_link - { type: "button", text: "Shodan", url: _shodan_link } + {type: "button", text: "Shodan", url: _shodan_link} end # @return [Array] @@ -57,7 +57,7 @@ def to_a { text: defanged_data, fallback: "VT & urlscan.io links", - actions: actions + actions: } ] end @@ -140,7 +140,7 @@ class Slack < Base # @param [Hash, nil] params # def initialize(rule:, options: nil, **params) - super(rule: rule, options: options) + super(rule:, options:) @webhook_url = params[:webhook_url] || Mihari.config.slack_webhook_url @channel = params[:channel] || Mihari.config.slack_channel || DEFAULT_CHANNEL @@ -177,9 +177,9 @@ def target # def notifier @notifier ||= lambda do - return ::Slack::Notifier.new(webhook_url, channel: channel, username: username) if timeout.nil? + return ::Slack::Notifier.new(webhook_url, channel:, username:) if timeout.nil? - ::Slack::Notifier.new(webhook_url, channel: channel, username: username, http_options: { timeout: timeout }) + ::Slack::Notifier.new(webhook_url, channel:, username:, http_options: {timeout:}) end.call end @@ -215,7 +215,7 @@ def call(artifacts) @artifacts = artifacts - notifier.post(text: text, attachments: attachments, mrkdwn: true) + notifier.post(text:, attachments:, mrkdwn: true) end end end diff --git a/lib/mihari/emitters/the_hive.rb b/lib/mihari/emitters/the_hive.rb index 82f506ba0..29fb798ca 100644 --- a/lib/mihari/emitters/the_hive.rb +++ b/lib/mihari/emitters/the_hive.rb @@ -18,7 +18,7 @@ class TheHive < Base # @param [Hash] params # def initialize(rule:, options: nil, **params) - super(rule: rule, options: options) + super(rule:, options:) @url = params[:url] || Mihari.config.thehive_url @api_key = params[:api_key] || Mihari.config.thehive_api_key @@ -56,7 +56,7 @@ def call(artifacts) private def client - Clients::TheHive.new(url, api_key: api_key, api_version: "v1", timeout: timeout) + Clients::TheHive.new(url, api_key:, api_version: "v1", timeout:) end # diff --git a/lib/mihari/emitters/webhook.rb b/lib/mihari/emitters/webhook.rb index 7080a2c7e..22b53ae4b 100644 --- a/lib/mihari/emitters/webhook.rb +++ b/lib/mihari/emitters/webhook.rb @@ -36,7 +36,7 @@ class Webhook < Base # @param [Hash, nil] params # def initialize(rule:, options: nil, **params) - super(rule: rule, options: options) + super(rule:, options:) @url = Addressable::URI.parse(params[:url]) @headers = params[:headers] || {} @@ -75,14 +75,14 @@ def call(artifacts) when "GET" http.get(url).body.to_s when "POST" - http.post(url, json: json).body.to_s + http.post(url, json:).body.to_s end end private def http - HTTP::Factory.build headers: headers, timeout: timeout + HTTP::Factory.build headers:, timeout: end # @@ -91,7 +91,7 @@ def http # @return [String] # def render - Services::JbuilderRenderer.call(template, { rule: rule, artifacts: artifacts }) + Services::JbuilderRenderer.call(template, {rule:, artifacts:}) end # diff --git a/lib/mihari/enrichers/base.rb b/lib/mihari/enrichers/base.rb index 9e52583bf..3572abb7f 100644 --- a/lib/mihari/enrichers/base.rb +++ b/lib/mihari/enrichers/base.rb @@ -10,7 +10,7 @@ class Base < Actor # @param [Hash, nil] options # def initialize(options: nil) - super(options: options) + super(options:) end # diff --git a/lib/mihari/enrichers/google_public_dns.rb b/lib/mihari/enrichers/google_public_dns.rb index 22efad9bf..4ba002d48 100644 --- a/lib/mihari/enrichers/google_public_dns.rb +++ b/lib/mihari/enrichers/google_public_dns.rb @@ -50,7 +50,7 @@ def supported_data_types end def client - @client ||= Clients::GooglePublicDNS.new(timeout: timeout) + @client ||= Clients::GooglePublicDNS.new(timeout:) end end end diff --git a/lib/mihari/enrichers/mmdb.rb b/lib/mihari/enrichers/mmdb.rb index 9737a1171..701b91fa0 100644 --- a/lib/mihari/enrichers/mmdb.rb +++ b/lib/mihari/enrichers/mmdb.rb @@ -39,7 +39,7 @@ def supported_data_types end def client - @client ||= Clients::MMDB.new(timeout: timeout) + @client ||= Clients::MMDB.new(timeout:) end end end diff --git a/lib/mihari/enrichers/shodan.rb b/lib/mihari/enrichers/shodan.rb index a77bdd909..69ca50ecd 100644 --- a/lib/mihari/enrichers/shodan.rb +++ b/lib/mihari/enrichers/shodan.rb @@ -22,13 +22,13 @@ def call(artifact) if tapped.reverse_dns_names.empty? tapped.reverse_dns_names = (res&.hostnames || []).map do |name| - Models::ReverseDnsName.new(name: name) + Models::ReverseDnsName.new(name:) end end if tapped.vulnerabilities.empty? tapped.vulnerabilities = (res&.vulns || []).map do |name| - Models::Vulnerability.new(name: name) + Models::Vulnerability.new(name:) end end end @@ -50,7 +50,7 @@ def supported_data_types end def client - @client ||= Clients::ShodanInternetDB.new(timeout: timeout) + @client ||= Clients::ShodanInternetDB.new(timeout:) end end end diff --git a/lib/mihari/enrichers/whois.rb b/lib/mihari/enrichers/whois.rb index 3122ffc67..f967def2f 100644 --- a/lib/mihari/enrichers/whois.rb +++ b/lib/mihari/enrichers/whois.rb @@ -23,7 +23,7 @@ def call(artifact) return if record.parser.available? artifact.whois_record ||= Models::WhoisRecord.new( - domain: domain, + domain:, created_on: get_created_on(record.parser), updated_on: get_updated_on(record.parser), expires_on: get_expires_on(record.parser), @@ -64,7 +64,7 @@ def whois @whois ||= lambda do return ::Whois::Client.new if timeout.nil? - ::Whois::Client.new(timeout: timeout) + ::Whois::Client.new(timeout:) end.call end diff --git a/lib/mihari/entities/alert.rb b/lib/mihari/entities/alert.rb index cc62d70cf..4406432b3 100644 --- a/lib/mihari/entities/alert.rb +++ b/lib/mihari/entities/alert.rb @@ -3,16 +3,16 @@ module Mihari module Entities class Alert < Grape::Entity - expose :id, documentation: { type: Integer, required: true } - expose :rule_id, documentation: { type: String, required: true }, as: :ruleId - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :id, documentation: {type: Integer, required: true} + expose :rule_id, documentation: {type: String, required: true}, as: :ruleId + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt - expose :artifacts, using: Entities::BaseArtifact, documentation: { type: Entities::BaseArtifact, is_array: true } - expose :tags, using: Entities::Tag, documentation: { type: Entities::Tag, is_array: true, required: true } + expose :artifacts, using: Entities::BaseArtifact, documentation: {type: Entities::BaseArtifact, is_array: true} + expose :tags, using: Entities::Tag, documentation: {type: Entities::Tag, is_array: true, required: true} end class AlertsWithPagination < Pagination - expose :results, using: Entities::Alert, documentation: { type: Entities::Alert, is_array: true, required: true } + expose :results, using: Entities::Alert, documentation: {type: Entities::Alert, is_array: true, required: true} end end end diff --git a/lib/mihari/entities/artifact.rb b/lib/mihari/entities/artifact.rb index 6e8d8c2fb..217bd2fe1 100644 --- a/lib/mihari/entities/artifact.rb +++ b/lib/mihari/entities/artifact.rb @@ -3,40 +3,40 @@ module Mihari module Entities class BaseArtifact < Grape::Entity - expose :id, documentation: { type: Integer, required: true } - expose :data, documentation: { type: String, required: true } - expose :data_type, documentation: { type: String, required: true }, as: :dataType - expose :source, documentation: { type: String, required: true } - expose :query, documentation: { type: String, required: false } - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt - expose :tags, using: Entities::Tag, documentation: { type: Entities::Tag, is_array: true, required: true } + expose :id, documentation: {type: Integer, required: true} + expose :data, documentation: {type: String, required: true} + expose :data_type, documentation: {type: String, required: true}, as: :dataType + expose :source, documentation: {type: String, required: true} + expose :query, documentation: {type: String, required: false} + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt + expose :tags, using: Entities::Tag, documentation: {type: Entities::Tag, is_array: true, required: true} end class Artifact < BaseArtifact - expose :metadata, documentation: { type: Hash } + expose :metadata, documentation: {type: Hash} expose :autonomous_system, using: Entities::AutonomousSystem, - documentation: { type: Entities::AutonomousSystem, required: false }, as: :autonomousSystem - expose :geolocation, using: Entities::Geolocation, documentation: { type: Entities::Geolocation, required: false } + documentation: {type: Entities::AutonomousSystem, required: false}, as: :autonomousSystem + expose :geolocation, using: Entities::Geolocation, documentation: {type: Entities::Geolocation, required: false} expose :whois_record, using: Entities::WhoisRecord, - documentation: { type: Entities::WhoisRecord, required: false }, as: :whoisRecord + documentation: {type: Entities::WhoisRecord, required: false}, as: :whoisRecord expose :reverse_dns_names, using: Entities::ReverseDnsName, - documentation: { type: Entities::ReverseDnsName, is_array: true, required: false }, as: :reverseDnsNames do |status, _options| + documentation: {type: Entities::ReverseDnsName, is_array: true, required: false}, as: :reverseDnsNames do |status, _options| status.reverse_dns_names.empty? ? nil : status.reverse_dns_names end expose :dns_records, using: Entities::DnsRecord, - documentation: { type: Entities::DnsRecord, is_array: true, required: false }, as: :dnsRecords do |status, _options| + documentation: {type: Entities::DnsRecord, is_array: true, required: false}, as: :dnsRecords do |status, _options| status.dns_records.empty? ? nil : status.dns_records end - expose :ceps, using: Entities::CPE, documentation: { type: Entities::CPE, is_array: true, required: false }, + expose :ceps, using: Entities::CPE, documentation: {type: Entities::CPE, is_array: true, required: false}, as: :cpes do |status, _options| status.cpes.empty? ? nil : status.cpes end - expose :ports, using: Entities::Port, documentation: { type: Entities::Port, is_array: true, required: false }, + expose :ports, using: Entities::Port, documentation: {type: Entities::Port, is_array: true, required: false}, as: :ports do |status, _options| status.ports.empty? ? nil : status.ports end - expose :vulnerabilities, using: Vulnerability, documentation: { type: Vulnerability, is_array: true, required: false }, + expose :vulnerabilities, using: Vulnerability, documentation: {type: Vulnerability, is_array: true, required: false}, as: :vulnerabilities do |status, _options| status.vulnerabilities.empty? ? nil : status.vulnerabilities end @@ -44,7 +44,7 @@ class Artifact < BaseArtifact class ArtifactsWithPagination < Pagination expose :results, using: Entities::BaseArtifact, - documentation: { type: Entities::Artifact, is_array: true, required: true } + documentation: {type: Entities::Artifact, is_array: true, required: true} end end end diff --git a/lib/mihari/entities/autonomous_system.rb b/lib/mihari/entities/autonomous_system.rb index 27aaa430e..569a07c18 100644 --- a/lib/mihari/entities/autonomous_system.rb +++ b/lib/mihari/entities/autonomous_system.rb @@ -3,7 +3,7 @@ module Mihari module Entities class AutonomousSystem < Grape::Entity - expose :number, documentation: { type: Integer, required: true } + expose :number, documentation: {type: Integer, required: true} end end end diff --git a/lib/mihari/entities/config.rb b/lib/mihari/entities/config.rb index 75f48d942..f020f9e49 100644 --- a/lib/mihari/entities/config.rb +++ b/lib/mihari/entities/config.rb @@ -3,10 +3,10 @@ module Mihari module Entities class Config < Grape::Entity - expose :name, documentation: { type: String, required: true } - expose :type, documentation: { type: String, required: true } - expose :items, documentation: { type: Hash, is_array: true, required: true } - expose :configured, documentation: { type: Grape::API::Boolean, required: true } + expose :name, documentation: {type: String, required: true} + expose :type, documentation: {type: String, required: true} + expose :items, documentation: {type: Hash, is_array: true, required: true} + expose :configured, documentation: {type: Grape::API::Boolean, required: true} end end end diff --git a/lib/mihari/entities/cpe.rb b/lib/mihari/entities/cpe.rb index cf8a98a5a..21812bbf1 100644 --- a/lib/mihari/entities/cpe.rb +++ b/lib/mihari/entities/cpe.rb @@ -3,8 +3,8 @@ module Mihari module Entities class CPE < Grape::Entity - expose :name, documentation: { type: String, required: true } - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :name, documentation: {type: String, required: true} + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt end end end diff --git a/lib/mihari/entities/dns.rb b/lib/mihari/entities/dns.rb index 9ad834e99..741cccde2 100644 --- a/lib/mihari/entities/dns.rb +++ b/lib/mihari/entities/dns.rb @@ -3,9 +3,9 @@ module Mihari module Entities class DnsRecord < Grape::Entity - expose :resource, documentation: { type: String, required: true } - expose :value, documentation: { type: String, required: true } - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :resource, documentation: {type: String, required: true} + expose :value, documentation: {type: String, required: true} + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt end end end diff --git a/lib/mihari/entities/geolocation.rb b/lib/mihari/entities/geolocation.rb index 7a74dec6c..d5658d481 100644 --- a/lib/mihari/entities/geolocation.rb +++ b/lib/mihari/entities/geolocation.rb @@ -3,9 +3,9 @@ module Mihari module Entities class Geolocation < Grape::Entity - expose :country, documentation: { type: String, required: true } - expose :country_code, documentation: { type: String, required: true }, as: :countryCode - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :country, documentation: {type: String, required: true} + expose :country_code, documentation: {type: String, required: true}, as: :countryCode + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt end end end diff --git a/lib/mihari/entities/ip_address.rb b/lib/mihari/entities/ip_address.rb index d70b8da1b..a1e55f8ea 100644 --- a/lib/mihari/entities/ip_address.rb +++ b/lib/mihari/entities/ip_address.rb @@ -3,9 +3,9 @@ module Mihari module Entities class IPAddress < Grape::Entity - expose :country_code, documentation: { type: String, required: true }, as: :countryCode - expose :asn, documentation: { type: Integer, required: false } - expose :loc, documentation: { type: String, required: false } + expose :country_code, documentation: {type: String, required: true}, as: :countryCode + expose :asn, documentation: {type: Integer, required: false} + expose :loc, documentation: {type: String, required: false} end end end diff --git a/lib/mihari/entities/messages.rb b/lib/mihari/entities/messages.rb index c19518ca8..a1a491275 100644 --- a/lib/mihari/entities/messages.rb +++ b/lib/mihari/entities/messages.rb @@ -3,15 +3,15 @@ module Mihari module Entities class Message < Grape::Entity - expose :message, documentation: { type: String, required: true } + expose :message, documentation: {type: String, required: true} end class ErrorMessage < Message - expose :detail, documentation: { type: Hash, required: false } + expose :detail, documentation: {type: Hash, required: false} end class QueueMessage < Message - expose :queued, documentation: { type: Grape::API::Boolean, required: true } + expose :queued, documentation: {type: Grape::API::Boolean, required: true} end end end diff --git a/lib/mihari/entities/pagination.rb b/lib/mihari/entities/pagination.rb index aa43ae949..683985770 100644 --- a/lib/mihari/entities/pagination.rb +++ b/lib/mihari/entities/pagination.rb @@ -3,9 +3,9 @@ module Mihari module Entities class Pagination < Grape::Entity - expose :total, documentation: { type: Integer, required: true } - expose :current_page, documentation: { type: Integer, required: true }, as: :currentPage - expose :page_size, documentation: { type: Integer, required: true }, as: :pageSize + expose :total, documentation: {type: Integer, required: true} + expose :current_page, documentation: {type: Integer, required: true}, as: :currentPage + expose :page_size, documentation: {type: Integer, required: true}, as: :pageSize end end end diff --git a/lib/mihari/entities/port.rb b/lib/mihari/entities/port.rb index 8f1e2bef3..09dfe4d06 100644 --- a/lib/mihari/entities/port.rb +++ b/lib/mihari/entities/port.rb @@ -3,8 +3,8 @@ module Mihari module Entities class Port < Grape::Entity - expose :number, documentation: { type: Integer, required: true } - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :number, documentation: {type: Integer, required: true} + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt end end end diff --git a/lib/mihari/entities/reverse_dns.rb b/lib/mihari/entities/reverse_dns.rb index 6442a2e87..154a1bf12 100644 --- a/lib/mihari/entities/reverse_dns.rb +++ b/lib/mihari/entities/reverse_dns.rb @@ -3,8 +3,8 @@ module Mihari module Entities class ReverseDnsName < Grape::Entity - expose :name, documentation: { type: String, required: true } - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :name, documentation: {type: String, required: true} + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt end end end diff --git a/lib/mihari/entities/rule.rb b/lib/mihari/entities/rule.rb index 23d2181b2..f60faeb5c 100644 --- a/lib/mihari/entities/rule.rb +++ b/lib/mihari/entities/rule.rb @@ -3,17 +3,17 @@ module Mihari module Entities class Rule < Grape::Entity - expose :id, documentation: { type: String, required: true } - expose :title, documentation: { type: String, required: true } - expose :description, documentation: { type: String, required: true } - expose :yaml, documentation: { type: String, required: true } - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt - expose :updated_at, documentation: { type: DateTime, required: true }, as: :updatedAt - expose :tags, using: Entities::Tag, documentation: { type: Entities::Tag, is_array: true, required: true } + expose :id, documentation: {type: String, required: true} + expose :title, documentation: {type: String, required: true} + expose :description, documentation: {type: String, required: true} + expose :yaml, documentation: {type: String, required: true} + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt + expose :updated_at, documentation: {type: DateTime, required: true}, as: :updatedAt + expose :tags, using: Entities::Tag, documentation: {type: Entities::Tag, is_array: true, required: true} end class RulesWithPagination < Pagination - expose :results, using: Entities::Rule, documentation: { type: Entities::Rule, is_array: true, required: true } + expose :results, using: Entities::Rule, documentation: {type: Entities::Rule, is_array: true, required: true} end end end diff --git a/lib/mihari/entities/tag.rb b/lib/mihari/entities/tag.rb index 05d661b23..9a5b79a59 100644 --- a/lib/mihari/entities/tag.rb +++ b/lib/mihari/entities/tag.rb @@ -3,12 +3,12 @@ module Mihari module Entities class Tag < Grape::Entity - expose :id, documentation: { type: Integer, required: true } - expose :name, documentation: { type: String, required: true } + expose :id, documentation: {type: Integer, required: true} + expose :name, documentation: {type: String, required: true} end class TagsWithPagination < Pagination - expose :results, using: Entities::Tag, documentation: { type: Entities::Tag, is_array: true, required: true } + expose :results, using: Entities::Tag, documentation: {type: Entities::Tag, is_array: true, required: true} end end end diff --git a/lib/mihari/entities/vulnerability.rb b/lib/mihari/entities/vulnerability.rb index 32a082fcf..036ffa989 100644 --- a/lib/mihari/entities/vulnerability.rb +++ b/lib/mihari/entities/vulnerability.rb @@ -3,8 +3,8 @@ module Mihari module Entities class Vulnerability < Grape::Entity - expose :name, documentation: { type: String, required: true } - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :name, documentation: {type: String, required: true} + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt end end end diff --git a/lib/mihari/entities/whois.rb b/lib/mihari/entities/whois.rb index e4cb14082..10b5f55d2 100644 --- a/lib/mihari/entities/whois.rb +++ b/lib/mihari/entities/whois.rb @@ -3,15 +3,15 @@ module Mihari module Entities class WhoisRecord < Grape::Entity - expose :domain, documentation: { type: String, required: true } - expose :created_on, documentation: { type: Date, required: false }, as: :createdOn - expose :updated_on, documentation: { type: Date, required: false }, as: :updatedOn - expose :expires_on, documentation: { type: Date, required: false }, as: :expiresOn - expose :registrar, documentation: { type: Hash, required: false } - expose :contacts, documentation: { type: Hash, is_array: true, required: true } do |whois_record, _options| + expose :domain, documentation: {type: String, required: true} + expose :created_on, documentation: {type: Date, required: false}, as: :createdOn + expose :updated_on, documentation: {type: Date, required: false}, as: :updatedOn + expose :expires_on, documentation: {type: Date, required: false}, as: :expiresOn + expose :registrar, documentation: {type: Hash, required: false} + expose :contacts, documentation: {type: Hash, is_array: true, required: true} do |whois_record, _options| whois_record.contacts.map(&:to_camelback_keys) end - expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :created_at, documentation: {type: DateTime, required: true}, as: :createdAt end end end diff --git a/lib/mihari/errors.rb b/lib/mihari/errors.rb index 054301c96..5968d2e20 100644 --- a/lib/mihari/errors.rb +++ b/lib/mihari/errors.rb @@ -74,7 +74,7 @@ def initialize(msg, status_code, body) end def detail - { status_code: status_code, body: body } + {status_code:, body:} end end diff --git a/lib/mihari/models/artifact.rb b/lib/mihari/models/artifact.rb index bce0a55a2..82fd642ca 100644 --- a/lib/mihari/models/artifact.rb +++ b/lib/mihari/models/artifact.rb @@ -159,8 +159,8 @@ class Artifact < ActiveRecord::Base # def unique?(base_time: nil, artifact_ttl: nil) artifact = self.class.joins(:alert).where( - data: data, - alert: { rule_id: rule_id } + data:, + alert: {rule_id:} ).order(created_at: :desc).first return true if artifact.nil? diff --git a/lib/mihari/models/port.rb b/lib/mihari/models/port.rb index 84b063ea1..96cf8256a 100644 --- a/lib/mihari/models/port.rb +++ b/lib/mihari/models/port.rb @@ -19,7 +19,7 @@ class << self # def build_by_ip(ip, enricher: Enrichers::Shodan.new) enricher.result(ip).fmap do |res| - (res&.ports || []).map { |port| new(port: port) } + (res&.ports || []).map { |port| new(port:) } end.value_or [] end end diff --git a/lib/mihari/rule.rb b/lib/mihari/rule.rb index 2d6a925a8..6da374c74 100644 --- a/lib/mihari/rule.rb +++ b/lib/mihari/rule.rb @@ -103,7 +103,7 @@ def updated_on # def tags data[:tags].uniq.filter_map do |name| - Models::Tag.find_or_create_by(name: name) + Models::Tag.find_or_create_by(name:) end end @@ -163,7 +163,7 @@ def normalized_artifacts # @return [Array] # def unique_artifacts - normalized_artifacts.select { |artifact| artifact.unique?(base_time: base_time, artifact_ttl: artifact_ttl) } + normalized_artifacts.select { |artifact| artifact.unique?(base_time:, artifact_ttl:) } end # @@ -221,11 +221,11 @@ def model end rescue ActiveRecord::RecordNotFound Mihari::Models::Rule.new( - id: id, - title: title, - description: description, - data: data, - taggings: taggings + id:, + title:, + description:, + data:, + taggings: ) end @@ -319,9 +319,7 @@ def analyzers @analyzers ||= queries.deep_dup.map do |params| name = params.delete(:analyzer) klass = get_analyzer_class(name) - klass.from_params(params).tap do |analyzer| - analyzer.validate_configuration! - end + klass.from_params(params).tap(&:validate_configuration!) end end @@ -363,9 +361,7 @@ def emitters options = params.delete(:options) klass = get_emitter_class(name) - klass.new(rule: self, options: options, **params).tap do |emitter| - emitter.validate_configuration! - end + klass.new(rule: self, options:, **params).tap(&:validate_configuration!) end end @@ -399,7 +395,7 @@ def enrichers options = params.delete(:options) klass = get_enricher_class(name) - klass.new(options: options, **params) + klass.new(options:, **params) end end diff --git a/lib/mihari/services/feed.rb b/lib/mihari/services/feed.rb index 6af551ca8..538fd0e71 100644 --- a/lib/mihari/services/feed.rb +++ b/lib/mihari/services/feed.rb @@ -28,10 +28,10 @@ def call(url, headers: {}, method: "GET", params: nil, json: nil, form: nil, tim return read_file(url.path) if url.scheme == "file" - http = HTTP::Factory.build(headers: headers, timeout: timeout) + http = HTTP::Factory.build(headers:, timeout:) - res = http.get(url, params: params) if method == "GET" - res = http.post(url, params: params, json: json, form: form) if method == "POST" + res = http.get(url, params:) if method == "GET" + res = http.post(url, params:, json:, form:) if method == "POST" body = res.body.to_s content_type = res["Content-Type"].to_s diff --git a/lib/mihari/services/proxies.rb b/lib/mihari/services/proxies.rb index e61c405b0..4c886913a 100644 --- a/lib/mihari/services/proxies.rb +++ b/lib/mihari/services/proxies.rb @@ -61,7 +61,7 @@ def rule_id # def artifacts @artifacts ||= data[:artifacts].map do |data| - artifact = Models::Artifact.new(data: data) + artifact = Models::Artifact.new(data:) artifact.rule_id = rule_id artifact.source = source artifact diff --git a/lib/mihari/services/renderer.rb b/lib/mihari/services/renderer.rb index 6ba4b1de0..99af71058 100644 --- a/lib/mihari/services/renderer.rb +++ b/lib/mihari/services/renderer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "tilt/jbuilder" module Mihari diff --git a/lib/mihari/services/searchers.rb b/lib/mihari/services/searchers.rb index 44ac1d55c..065e517db 100644 --- a/lib/mihari/services/searchers.rb +++ b/lib/mihari/services/searchers.rb @@ -35,7 +35,7 @@ def call(params) ResultValue.new( total: klass.count_by_filter(filter), results: klass.search_by_filter(filter), - filter: filter + filter: ) end diff --git a/lib/mihari/sidekiq/application.rb b/lib/mihari/sidekiq/application.rb index 919f67657..28ad473e7 100644 --- a/lib/mihari/sidekiq/application.rb +++ b/lib/mihari/sidekiq/application.rb @@ -5,9 +5,9 @@ require "mihari/sidekiq/jobs" Sidekiq.configure_server do |config| - config.redis = { url: Mihari.config.sidekiq_redis_url.to_s } + config.redis = {url: Mihari.config.sidekiq_redis_url.to_s} end Sidekiq.configure_client do |config| - config.redis = { url: Mihari.config.sidekiq_redis_url.to_s } + config.redis = {url: Mihari.config.sidekiq_redis_url.to_s} end diff --git a/lib/mihari/structs/censys.rb b/lib/mihari/structs/censys.rb index b7ed4dab7..be30863d2 100644 --- a/lib/mihari/structs/censys.rb +++ b/lib/mihari/structs/censys.rb @@ -48,8 +48,8 @@ def geolocation return nil if country.nil? Mihari::Models::Geolocation.new( - country: country, - country_code: country_code + country:, + country_code: ) end @@ -126,10 +126,10 @@ def ports def artifact Models::Artifact.new( data: ip, - metadata: metadata, + metadata:, autonomous_system: autonomous_system.as, geolocation: location.geolocation, - ports: ports + ports: ) end diff --git a/lib/mihari/structs/google_public_dns.rb b/lib/mihari/structs/google_public_dns.rb index 3227ed438..ac95a9616 100644 --- a/lib/mihari/structs/google_public_dns.rb +++ b/lib/mihari/structs/google_public_dns.rb @@ -4,8 +4,8 @@ module Mihari module Structs module GooglePublicDNS INT_TYPE_TO_TYPE = - { 1 => :A, 38 => :A6, 28 => :AAAA, 18 => :AFSDB, 255 => :ANY, 42 => :APL, 34 => :ATMA, 252 => :AXFR, 37 => :CERT, - 5 => :CNAME, 49 => :DHCID, 32_769 => :DLV, 39 => :DNAME, 48 => :DNSKEY, 43 => :DS, 31 => :EID, 102 => :GID, 27 => :GPOS, 13 => :HINFO, 45 => :IPSECKEY, 20 => :ISDN, 251 => :IXFR, 25 => :KEY, 36 => :KX, 29 => :LOC, 254 => :MAILA, 253 => :MAILB, 7 => :MB, 3 => :MD, 4 => :MF, 8 => :MG, 14 => :MINFO, 9 => :MR, 15 => :MX, 35 => :NAPTR, 32 => :NIMLOC, 2 => :NS, 22 => :NSAP, 23 => :NSAP_PTR, 47 => :NSEC, 50 => :NSEC3, 51 => :NSEC3PARAMS, 10 => :NULL, 30 => :NXT, 41 => :OPT, 12 => :PTR, 26 => :PX, 17 => :RP, 46 => :RRSIG, 21 => :RT, 24 => :SIG, 40 => :SINK, 6 => :SOA, 33 => :SRV, 44 => :SSHFP, 250 => :TSIG, 16 => :TXT, 101 => :UID, 100 => :UINFO, 103 => :UNSPEC, 11 => :WKS, 19 => :X25 }.freeze + {1 => :A, 38 => :A6, 28 => :AAAA, 18 => :AFSDB, 255 => :ANY, 42 => :APL, 34 => :ATMA, 252 => :AXFR, 37 => :CERT, + 5 => :CNAME, 49 => :DHCID, 32_769 => :DLV, 39 => :DNAME, 48 => :DNSKEY, 43 => :DS, 31 => :EID, 102 => :GID, 27 => :GPOS, 13 => :HINFO, 45 => :IPSECKEY, 20 => :ISDN, 251 => :IXFR, 25 => :KEY, 36 => :KX, 29 => :LOC, 254 => :MAILA, 253 => :MAILB, 7 => :MB, 3 => :MD, 4 => :MF, 8 => :MG, 14 => :MINFO, 9 => :MR, 15 => :MX, 35 => :NAPTR, 32 => :NIMLOC, 2 => :NS, 22 => :NSAP, 23 => :NSAP_PTR, 47 => :NSEC, 50 => :NSEC3, 51 => :NSEC3PARAMS, 10 => :NULL, 30 => :NXT, 41 => :OPT, 12 => :PTR, 26 => :PX, 17 => :RP, 46 => :RRSIG, 21 => :RT, 24 => :SIG, 40 => :SINK, 6 => :SOA, 33 => :SRV, 44 => :SSHFP, 250 => :TSIG, 16 => :TXT, 101 => :UID, 100 => :UINFO, 103 => :UNSPEC, 11 => :WKS, 19 => :X25}.freeze class Answer < Dry::Struct # @!attribute [r] name @@ -30,7 +30,7 @@ def from_dynamic!(d) new( name: d.fetch("name"), data: d.fetch("data"), - resource_type: resource_type + resource_type: ) end end diff --git a/lib/mihari/structs/greynoise.rb b/lib/mihari/structs/greynoise.rb index 3dfb78370..75e5744bb 100644 --- a/lib/mihari/structs/greynoise.rb +++ b/lib/mihari/structs/greynoise.rb @@ -30,8 +30,8 @@ def as # def geolocation Mihari::Models::Geolocation.new( - country: country, - country_code: country_code + country:, + country_code: ) end diff --git a/lib/mihari/structs/onyphe.rb b/lib/mihari/structs/onyphe.rb index 6cbbb7400..3bd20e2df 100644 --- a/lib/mihari/structs/onyphe.rb +++ b/lib/mihari/structs/onyphe.rb @@ -29,9 +29,9 @@ class Result < Dry::Struct def artifact Mihari::Models::Artifact.new( data: ip, - metadata: metadata, + metadata:, autonomous_system: as, - geolocation: geolocation + geolocation: ) end @@ -43,7 +43,7 @@ def geolocation Mihari::Models::Geolocation.new( country: NormalizeCountry(country_code, to: :short), - country_code: country_code + country_code: ) end diff --git a/lib/mihari/structs/shodan.rb b/lib/mihari/structs/shodan.rb index 40bf84767..01a87dfef 100644 --- a/lib/mihari/structs/shodan.rb +++ b/lib/mihari/structs/shodan.rb @@ -20,7 +20,7 @@ def geolocation Mihari::Models::Geolocation.new( country: country_name, - country_code: country_code + country_code: ) end @@ -106,7 +106,7 @@ def from_dynamic!(d) new( asn: d["asn"], - hostnames: hostnames, + hostnames:, location: Location.from_dynamic!(d.fetch("location")), domains: d.fetch("domains"), ip_str: d.fetch("ip_str"), @@ -205,20 +205,20 @@ def artifacts ports = collect_ports_by_ip(match.ip_str).map { |port| Models::Port.new(number: port) } reverse_dns_names = collect_hostnames_by_ip(match.ip_str).map do |name| - Models::ReverseDnsName.new(name: name) + Models::ReverseDnsName.new(name:) end - cpes = collect_cpes_by_ip(match.ip_str).map { |name| Models::CPE.new(name: name) } - vulnerabilities = collect_vulns_by_ip(match.ip_str).map { |name| Models::Vulnerability.new(name: name) } + cpes = collect_cpes_by_ip(match.ip_str).map { |name| Models::CPE.new(name:) } + vulnerabilities = collect_vulns_by_ip(match.ip_str).map { |name| Models::Vulnerability.new(name:) } Mihari::Models::Artifact.new( data: match.ip_str, - metadata: metadata, + metadata:, autonomous_system: match.autonomous_system, geolocation: match.location.geolocation, - ports: ports, - reverse_dns_names: reverse_dns_names, - cpes: cpes, - vulnerabilities: vulnerabilities + ports:, + reverse_dns_names:, + cpes:, + vulnerabilities: ) end end diff --git a/lib/mihari/structs/urlscan.rb b/lib/mihari/structs/urlscan.rb index 461742255..4571ca272 100644 --- a/lib/mihari/structs/urlscan.rb +++ b/lib/mihari/structs/urlscan.rb @@ -53,7 +53,7 @@ class Result < Dry::Struct # def artifacts values = [page.url, page.domain, page.ip].compact - values.map { |value| Mihari::Models::Artifact.new(data: value, metadata: metadata) } + values.map { |value| Mihari::Models::Artifact.new(data: value, metadata:) } end class << self diff --git a/lib/mihari/structs/virustotal_intelligence.rb b/lib/mihari/structs/virustotal_intelligence.rb index eeb265e6b..ad2a7348a 100644 --- a/lib/mihari/structs/virustotal_intelligence.rb +++ b/lib/mihari/structs/virustotal_intelligence.rb @@ -56,7 +56,7 @@ def value # @return [Mihari::Models::Artifact] # def artifact - Models::Artifact.new(data: value, metadata: metadata) + Models::Artifact.new(data: value, metadata:) end class << self @@ -74,7 +74,7 @@ def from_dynamic!(d) new( type: d.fetch("type"), id: d.fetch("id"), - context_attributes: context_attributes, + context_attributes:, metadata: d ) end diff --git a/lib/mihari/web/api.rb b/lib/mihari/web/api.rb index 4194cb4b1..f855b800f 100644 --- a/lib/mihari/web/api.rb +++ b/lib/mihari/web/api.rb @@ -24,7 +24,7 @@ class API < Grape::API mount Endpoints::Rules mount Endpoints::Tags - add_swagger_documentation(api_version: "v1", info: { title: "Mihari API" }) + add_swagger_documentation(api_version: "v1", info: {title: "Mihari API"}) end end end diff --git a/lib/mihari/web/application.rb b/lib/mihari/web/application.rb index 8ffcd0dd9..5cd4e86b4 100644 --- a/lib/mihari/web/application.rb +++ b/lib/mihari/web/application.rb @@ -97,7 +97,7 @@ def run!(port: 9292, host: "localhost", threads: "0:5", verbose: false, worker_t Host: host, Threads: threads, Verbose: verbose, - worker_timeout: worker_timeout + worker_timeout: ) do |_| Launchy.open("http://#{host}:#{port}") if !Mihari.development? && open rescue Launchy::CommandNotFoundError diff --git a/lib/mihari/web/endpoints/alerts.rb b/lib/mihari/web/endpoints/alerts.rb index 4a1e38479..01a6594fc 100644 --- a/lib/mihari/web/endpoints/alerts.rb +++ b/lib/mihari/web/endpoints/alerts.rb @@ -33,7 +33,7 @@ class Alerts < Grape::API desc "Get an alert", { success: Entities::Alert, - failure: [{ code: 404, model: Entities::ErrorMessage }], + failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Get an alert" } params do @@ -46,14 +46,14 @@ class Alerts < Grape::API case result.failure when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end desc "Delete an alert", { - success: { code: 204, model: Entities::Message }, - failure: [{ code: 404, model: Entities::ErrorMessage }], + success: {code: 204, model: Entities::Message}, + failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Delete an alert" } params do @@ -64,26 +64,26 @@ class Alerts < Grape::API id = params["id"].to_i result = Services::AlertDestroyer.result(id) - return present({ message: "" }, with: Entities::Message) if result.success? + return present({message: ""}, with: Entities::Message) if result.success? case result.failure when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end desc "Create an alert", { - success: { code: 201, model: Entities::Alert }, + success: {code: 201, model: Entities::Alert}, failure: [ - { code: 404, model: Entities::ErrorMessage } + {code: 404, model: Entities::ErrorMessage} ], summary: "Create an alert" } params do - requires :ruleId, type: String, documentation: { param_type: "body" } - requires :artifacts, type: Array, documentation: { type: String, is_array: true, param_type: "body" } - optional :source, type: String, documentation: { param_type: "body" } + requires :ruleId, type: String, documentation: {param_type: "body"} + requires :artifacts, type: Array, documentation: {type: String, is_array: true, param_type: "body"} + optional :source, type: String, documentation: {param_type: "body"} end post "/" do status 201 @@ -93,7 +93,7 @@ class Alerts < Grape::API case result.failure when ActiveRecord::RecordNotFound - error!({ message: "Rule:#{params["ruleId"]} not found" }, 404) + error!({message: "Rule:#{params["ruleId"]} not found"}, 404) end raise result.failure end diff --git a/lib/mihari/web/endpoints/artifacts.rb b/lib/mihari/web/endpoints/artifacts.rb index 5e7ece9ee..acf37a4bd 100644 --- a/lib/mihari/web/endpoints/artifacts.rb +++ b/lib/mihari/web/endpoints/artifacts.rb @@ -33,7 +33,7 @@ class Artifacts < Grape::API desc "Get an artifact", { success: Entities::Artifact, - failure: [{ code: 404, model: Entities::ErrorMessage }], + failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Get an artifact" } params do @@ -46,14 +46,14 @@ class Artifacts < Grape::API case result.failure when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end desc "Enrich an artifact", { - success: { code: 201, model: Entities::Message }, - failure: [{ code: 400, model: Entities::ErrorMessage }, { code: 404, model: Entities::ErrorMessage }], + success: {code: 201, model: Entities::Message}, + failure: [{code: 400, model: Entities::ErrorMessage}, {code: 404, model: Entities::ErrorMessage}], summary: "Enrich an artifact" } params do @@ -75,20 +75,20 @@ class Artifacts < Grape::API end.to_result message = queued ? "ID:#{id}'s enrichment is queued" : "ID:#{id}'s enrichment is successful" - return present({ message: message, queued: queued }, with: Entities::QueueMessage) if result.success? + return present({message:, queued:}, with: Entities::QueueMessage) if result.success? case result.failure when UnenrichableError - error!({ message: result.failure.message }, 400) + error!({message: result.failure.message}, 400) when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end desc "Delete an artifact", { - success: { code: 204, model: Entities::Message }, - failure: [{ code: 404, model: Entities::ErrorMessage }], + success: {code: 204, model: Entities::Message}, + failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Delete an artifact" } params do @@ -99,11 +99,11 @@ class Artifacts < Grape::API id = params["id"].to_i result = Services::ArtifactDestroyer.result(id) - return present({ message: "" }, with: Entities::Message) if result.success? + return present({message: ""}, with: Entities::Message) if result.success? case result.failure when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end diff --git a/lib/mihari/web/endpoints/ip_addresses.rb b/lib/mihari/web/endpoints/ip_addresses.rb index c15d9a1ac..d654a823d 100644 --- a/lib/mihari/web/endpoints/ip_addresses.rb +++ b/lib/mihari/web/endpoints/ip_addresses.rb @@ -11,15 +11,15 @@ class IPAddresses < Grape::API desc "Get IP address data", { success: Entities::IPAddress, failure: [ - { code: 404, model: Entities::ErrorMessage }, - { code: 422, model: Entities::ErrorMessage } + {code: 404, model: Entities::ErrorMessage}, + {code: 422, model: Entities::ErrorMessage} ], summary: "Get IP address data" } params do requires :ip, type: String end - get "/:ip", requirements: { ip: %r{[^/]+} } do + get "/:ip", requirements: {ip: %r{[^/]+}} do ip = params[:ip].to_s result = Services::IPGetter.result(ip) if result.success? @@ -37,8 +37,8 @@ class IPAddresses < Grape::API failure = result.failure case failure when Mihari::StatusError - error!({ message: "IP:#{ip} not found" }, failure.status_code) if failure.status_code == 404 - error!({ message: "IP format invalid" }, failure.status_code) if failure.status_code == 422 + error!({message: "IP:#{ip} not found"}, failure.status_code) if failure.status_code == 404 + error!({message: "IP format invalid"}, failure.status_code) if failure.status_code == 422 end raise failure end diff --git a/lib/mihari/web/endpoints/rules.rb b/lib/mihari/web/endpoints/rules.rb index fc13f00c3..0303f8fb8 100644 --- a/lib/mihari/web/endpoints/rules.rb +++ b/lib/mihari/web/endpoints/rules.rb @@ -51,7 +51,7 @@ def call(yaml, overwrite: true) desc "Get a rule", { success: Entities::Rule, - failure: [{ code: 404, model: Entities::ErrorMessage }], + failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Get a rule" } params do @@ -64,14 +64,14 @@ def call(yaml, overwrite: true) case result.failure when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end desc "Search by a rule", { - success: { code: 201, model: Entities::QueueMessage }, - failure: [{ code: 404, model: Entities::ErrorMessage }], + success: {code: 201, model: Entities::QueueMessage}, + failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Run a rule" } params do @@ -95,25 +95,25 @@ def call(yaml, overwrite: true) end.to_result message = queued ? "ID:#{id}'s search is queued" : "ID:#{id}'s search is successful" - return present({ message: message, queued: queued }, with: Entities::QueueMessage) if result.success? + return present({message:, queued:}, with: Entities::QueueMessage) if result.success? case result.failure when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end desc "Create a rule", { - success: { code: 201, model: Entities::Rule }, + success: {code: 201, model: Entities::Rule}, failure: [ - { code: 400, model: Entities::ErrorMessage }, - { code: 422, model: Entities::ErrorMessage } + {code: 400, model: Entities::ErrorMessage}, + {code: 422, model: Entities::ErrorMessage} ], summary: "Create a rule" } params do - requires :yaml, type: String, documentation: { param_type: "body" } + requires :yaml, type: String, documentation: {param_type: "body"} end post "/" do status 201 @@ -126,25 +126,25 @@ def call(yaml, overwrite: true) failure = result.failure case failure when Psych::SyntaxError - error!({ message: failure.message }, 422) + error!({message: failure.message}, 422) when ValidationError - error!({ message: "Rule format invalid", detail: failure.errors.to_h }, 422) + error!({message: "Rule format invalid", detail: failure.errors.to_h}, 422) when IntegrityError - error!({ message: failure.message }, 400) + error!({message: failure.message}, 400) end raise failure end desc "Update a rule", { - success: { code: 201, model: Entities::Rule }, + success: {code: 201, model: Entities::Rule}, failure: [ - { code: 404, model: Entities::ErrorMessage }, - { code: 422, model: Entities::ErrorMessage } + {code: 404, model: Entities::ErrorMessage}, + {code: 422, model: Entities::ErrorMessage} ], summary: "Update a rule" } params do - requires :yaml, type: String, documentation: { param_type: "body" } + requires :yaml, type: String, documentation: {param_type: "body"} end put "/" do status 201 @@ -157,18 +157,18 @@ def call(yaml, overwrite: true) failure = result.failure case failure when ActiveRecord::RecordNotFound - error!({ message: "Rule not found" }, 404) + error!({message: "Rule not found"}, 404) when Psych::SyntaxError - error!({ message: failure.message }, 422) + error!({message: failure.message}, 422) when ValidationError - error!({ message: "Rule format invalid", detail: failure.errors.to_h }, 422) + error!({message: "Rule format invalid", detail: failure.errors.to_h}, 422) end raise failure end desc "Delete a rule", { - success: { code: 204, model: Entities::Message }, - failure: [{ code: 404, model: Entities::ErrorMessage }], + success: {code: 204, model: Entities::Message}, + failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Delete a rule" } params do @@ -179,11 +179,11 @@ def call(yaml, overwrite: true) id = params[:id].to_s result = Services::RuleDestroyer.result(id) - return present({ message: "ID:#{id} is deleted" }, with: Entities::Message) if result.success? + return present({message: "ID:#{id} is deleted"}, with: Entities::Message) if result.success? case result.failure when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end diff --git a/lib/mihari/web/endpoints/tags.rb b/lib/mihari/web/endpoints/tags.rb index 7ae3e1956..74dcc1fa1 100644 --- a/lib/mihari/web/endpoints/tags.rb +++ b/lib/mihari/web/endpoints/tags.rb @@ -32,8 +32,8 @@ class Tags < Grape::API end desc "Delete a tag", { - success: { code: 204, model: Entities::Message }, - failure: [{ code: 404, model: Entities::ErrorMessage }], + success: {code: 204, model: Entities::Message}, + failure: [{code: 404, model: Entities::ErrorMessage}], summary: "Delete a tag" } params do @@ -44,11 +44,11 @@ class Tags < Grape::API id = params[:id].to_i result = Services::TagDestroyer.result(id) - return present({ message: "" }, with: Entities::Message) if result.success? + return present({message: ""}, with: Entities::Message) if result.success? case result.failure when ActiveRecord::RecordNotFound - error!({ message: "ID:#{id} not found" }, 404) + error!({message: "ID:#{id} not found"}, 404) end raise result.failure end diff --git a/spec/analyzers/feed_spec.rb b/spec/analyzers/feed_spec.rb index c0695a8db..448876c7c 100644 --- a/spec/analyzers/feed_spec.rb +++ b/spec/analyzers/feed_spec.rb @@ -7,8 +7,8 @@ described_class.new( "https://threatfox-api.abuse.ch/api/v1/", method: "POST", - json: { query: "get_iocs", days: 1 }, - headers: { "api-key": ENV["THREATFOX_API_KEY"] }, + json: {query: "get_iocs", days: 1}, + headers: {"api-key": ENV["THREATFOX_API_KEY"]}, selector: "data.map(&:ioc)" ) end diff --git a/spec/analyzers/hunterhow_spec.rb b/spec/analyzers/hunterhow_spec.rb index 0a2a7b0d4..1d18174a5 100644 --- a/spec/analyzers/hunterhow_spec.rb +++ b/spec/analyzers/hunterhow_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Mihari::Analyzers::HunterHow, :vcr do - subject(:analyzer) { described_class.new(query, start_time: start_time, end_time: end_time) } + subject(:analyzer) { described_class.new(query, start_time:, end_time:) } let!(:query) { 'ip:"1.1.1.1"' } let!(:start_time) { Date.parse "2023-08-01" } diff --git a/spec/analyzers/zoomeye_spec.rb b/spec/analyzers/zoomeye_spec.rb index 8e816f6dc..586800c67 100644 --- a/spec/analyzers/zoomeye_spec.rb +++ b/spec/analyzers/zoomeye_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Mihari::Analyzers::ZoomEye, :vcr do - subject(:analyzer) { described_class.new(query, type: type) } + subject(:analyzer) { described_class.new(query, type:) } let(:type) { "host" } diff --git a/spec/cli/alert_spec.rb b/spec/cli/alert_spec.rb index 732912782..1199711ee 100644 --- a/spec/cli/alert_spec.rb +++ b/spec/cli/alert_spec.rb @@ -15,7 +15,7 @@ describe "#list-transform" do it do expect do - described_class.new.invoke(:list_transform, [], { template: "json.array! results.map(&:id)" }) + described_class.new.invoke(:list_transform, [], {template: "json.array! results.map(&:id)"}) end.to output(include(alert.id.to_s)).to_stdout end end @@ -29,7 +29,7 @@ describe "#create" do before do @file = Tempfile.new("dummy") - @file.write(YAML.dump({ rule_id: rule.id, artifacts: %w[1.1.1.1] })) + @file.write(YAML.dump({rule_id: rule.id, artifacts: %w[1.1.1.1]})) @file.rewind end diff --git a/spec/cli/artifact_spec.rb b/spec/cli/artifact_spec.rb index 940411ac7..e41107173 100644 --- a/spec/cli/artifact_spec.rb +++ b/spec/cli/artifact_spec.rb @@ -12,7 +12,7 @@ describe "#list-transform" do it do expect do - described_class.new.invoke(:list_transform, [], { template: "json.array! results.map(&:id)" }) + described_class.new.invoke(:list_transform, [], {template: "json.array! results.map(&:id)"}) end.to output(include(artifact.id.to_s)).to_stdout end end diff --git a/spec/cli/rule_spec.rb b/spec/cli/rule_spec.rb index 73b61a111..54334dba8 100644 --- a/spec/cli/rule_spec.rb +++ b/spec/cli/rule_spec.rb @@ -43,7 +43,7 @@ describe "#list-transform" do it do expect do - described_class.new.invoke(:list_transform, [], { template: "json.array! results.map(&:id)" }) + described_class.new.invoke(:list_transform, [], {template: "json.array! results.map(&:id)"}) end.to output(include(rule.id.to_s)).to_stdout end end diff --git a/spec/cli/tag_spec.rb b/spec/cli/tag_spec.rb index bb30588f5..3239d4edb 100644 --- a/spec/cli/tag_spec.rb +++ b/spec/cli/tag_spec.rb @@ -13,7 +13,7 @@ describe "#list-transform" do it do expect do - described_class.new.invoke(:list_transform, [], { template: "json.array! results.map(&:id)" }) + described_class.new.invoke(:list_transform, [], {template: "json.array! results.map(&:id)"}) end.to output(include(tag.id.to_s)).to_stdout end end diff --git a/spec/commands/search_spec.rb b/spec/commands/search_spec.rb index a296781f4..a0036f6a9 100644 --- a/spec/commands/search_spec.rb +++ b/spec/commands/search_spec.rb @@ -18,7 +18,7 @@ class SearchCLI < Mihari::CLI::Base describe "#search" do it do - expect { SearchCLI.new.invoke(:search, [path], { force_overwrite: true }) }.to output(include(rule.id)).to_stdout + expect { SearchCLI.new.invoke(:search, [path], {force_overwrite: true}) }.to output(include(rule.id)).to_stdout end end end diff --git a/spec/concerns/error_unwrappable_spec.rb b/spec/concerns/error_unwrappable_spec.rb index 57070169f..1c5549883 100644 --- a/spec/concerns/error_unwrappable_spec.rb +++ b/spec/concerns/error_unwrappable_spec.rb @@ -26,21 +26,21 @@ def raise_error describe "#unwrap_error" do it do subject.raise_try_error - rescue StandardError => e + rescue => e expect(e).not_to be_a ZeroDivisionError expect(subject.unwrap_error(e)).to be_a ZeroDivisionError end it do subject.raise_result_error - rescue StandardError => e + rescue => e expect(e).not_to be_a ZeroDivisionError expect(subject.unwrap_error(e)).to be_a ZeroDivisionError end it do subject.raise_error - rescue StandardError => e + rescue => e expect(e).to be_a ZeroDivisionError expect(subject.unwrap_error(e)).to be_a ZeroDivisionError end diff --git a/spec/concerns/retriable_spec.rb b/spec/concerns/retriable_spec.rb index b23eb04a7..32558d431 100644 --- a/spec/concerns/retriable_spec.rb +++ b/spec/concerns/retriable_spec.rb @@ -12,7 +12,7 @@ def initialize end def retriable_get(url) - retry_on_error(times: times, interval: interval) do + retry_on_error(times:, interval:) do get url end end diff --git a/spec/emitters/database_spec.rb b/spec/emitters/database_spec.rb index dbf317e0c..191694c0e 100644 --- a/spec/emitters/database_spec.rb +++ b/spec/emitters/database_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Mihari::Emitters::Database do - subject(:emitter) { described_class.new(rule: rule) } + subject(:emitter) { described_class.new(rule:) } let_it_be(:rule) { Mihari::Rule.from_model FactoryBot.create(:rule) } let!(:artifacts) { [Mihari::Models::Artifact.new(data: "1.1.1.1")] } diff --git a/spec/emitters/misp_spec.rb b/spec/emitters/misp_spec.rb index 94eeb8431..57bc42aa8 100644 --- a/spec/emitters/misp_spec.rb +++ b/spec/emitters/misp_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Mihari::Emitters::MISP, :vcr do - subject(:emitter) { described_class.new(rule: rule) } + subject(:emitter) { described_class.new(rule:) } include_context "with mocked logger" diff --git a/spec/emitters/slack_spec.rb b/spec/emitters/slack_spec.rb index 79abb6577..0d4184f0b 100644 --- a/spec/emitters/slack_spec.rb +++ b/spec/emitters/slack_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Mihari::Emitters::Slack do - subject(:emitter) { described_class.new(rule: rule) } + subject(:emitter) { described_class.new(rule:) } let_it_be(:rule) { Mihari::Rule.from_model FactoryBot.create(:rule) } let!(:artifacts) do diff --git a/spec/emitters/the_hive_spec.rb b/spec/emitters/the_hive_spec.rb index 2c9d27987..159ea3b2b 100644 --- a/spec/emitters/the_hive_spec.rb +++ b/spec/emitters/the_hive_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Mihari::Emitters::TheHive, :vcr do - subject(:emitter) { described_class.new(rule: rule) } + subject(:emitter) { described_class.new(rule:) } include_context "with mocked logger" @@ -30,7 +30,7 @@ describe "#call" do let!(:mock_client) { instance_double("client") } - let!(:mocked_emitter) { described_class.new(rule: rule) } + let!(:mocked_emitter) { described_class.new(rule:) } before do allow(mocked_emitter).to receive(:client).and_return(mock_client) diff --git a/spec/emitters/webhook_spec.rb b/spec/emitters/webhook_spec.rb index ebde8805b..5b653b445 100644 --- a/spec/emitters/webhook_spec.rb +++ b/spec/emitters/webhook_spec.rb @@ -11,7 +11,7 @@ describe "#configured?" do context "without URL" do - let(:emitter) { described_class.new(rule: rule) } + let(:emitter) { described_class.new(rule:) } it do expect(emitter.configured?).to be false @@ -19,7 +19,7 @@ end context "with URL" do - let(:emitter) { described_class.new(rule: rule, url: url) } + let(:emitter) { described_class.new(rule:, url:) } it do expect(emitter.configured?).to be true @@ -30,9 +30,9 @@ describe "#call" do let(:emitter) do described_class.new( - rule: rule, - url: url, - headers: { "Content-Type": "application/json" } + rule:, + url:, + headers: {"Content-Type": "application/json"} ) end @@ -47,10 +47,10 @@ context "with a template file" do let(:emitter) do described_class.new( - rule: rule, - url: url, + rule:, + url:, template: "spec/fixtures/templates/test.json.jbuilder", - headers: { "Content-Type": "application/json" } + headers: {"Content-Type": "application/json"} ) end @@ -63,7 +63,7 @@ end describe "#target" do - let(:emitter) { described_class.new(rule: rule, url: url) } + let(:emitter) { described_class.new(rule:, url:) } it do expect(emitter.target).to be_a(String) diff --git a/spec/factories/alerts.rb b/spec/factories/alerts.rb index a143ef094..8e9bc509e 100644 --- a/spec/factories/alerts.rb +++ b/spec/factories/alerts.rb @@ -6,11 +6,11 @@ factory :alert_with_artifacts do after(:create) do |alert, _context| - create(:artifact, :ip, alert: alert) - create(:artifact, :domain, alert: alert) - create(:artifact, :url, alert: alert) - create(:artifact, :mail, alert: alert) - create(:artifact, :hash, alert: alert) + create(:artifact, :ip, alert:) + create(:artifact, :domain, alert:) + create(:artifact, :url, alert:) + create(:artifact, :mail, alert:) + create(:artifact, :hash, alert:) end end end diff --git a/spec/factories/artifacts.rb b/spec/factories/artifacts.rb index 2fd211a0c..0a24667fb 100644 --- a/spec/factories/artifacts.rb +++ b/spec/factories/artifacts.rb @@ -54,12 +54,12 @@ after(:create) do |artifact| case artifact.data_type when "ip" - create(:autonomous_system, artifact: artifact) - create_list(:reverse_dns_name, 1, artifact: artifact) + create(:autonomous_system, artifact:) + create_list(:reverse_dns_name, 1, artifact:) when "domain" - create_list(:dns_record, 1, artifact: artifact) + create_list(:dns_record, 1, artifact:) when "url" - create_list(:dns_record, 1, artifact: artifact) + create_list(:dns_record, 1, artifact:) end end end diff --git a/spec/factories/rules.rb b/spec/factories/rules.rb index 530fc6638..2541aa05d 100644 --- a/spec/factories/rules.rb +++ b/spec/factories/rules.rb @@ -8,12 +8,12 @@ tags { build_list :tag, 1 } data do { - id: id, - title: title, - description: description, + id:, + title:, + description:, queries: [], tags: [], - emitters: [{ emitter: "database" }] + emitters: [{emitter: "database"}] } end @@ -23,7 +23,7 @@ end after(:create) do |rule, context| - create_list(:alert_with_artifacts, context.alerts_count, rule: rule) + create_list(:alert_with_artifacts, context.alerts_count, rule:) end end end diff --git a/spec/fixtures/templates/test.json.jbuilder b/spec/fixtures/templates/test.json.jbuilder index 7e614c50b..0d6096be5 100644 --- a/spec/fixtures/templates/test.json.jbuilder +++ b/spec/fixtures/templates/test.json.jbuilder @@ -1 +1,3 @@ +# frozen_string_literal: true + json.id rule.id diff --git a/spec/http_spec.rb b/spec/http_spec.rb index 79ba47745..a32fdd246 100644 --- a/spec/http_spec.rb +++ b/spec/http_spec.rb @@ -31,22 +31,22 @@ describe ".post" do context "with application/x-www-form-urlencoded" do - let!(:form) { { foo: "bar" } } - let(:headers) { { "content-type": "application/x-www-form-urlencoded" } } + let!(:form) { {foo: "bar"} } + let(:headers) { {"content-type": "application/x-www-form-urlencoded"} } it do - res = described_class.build(headers: headers).post("#{server.base_url}/post", form: form) + res = described_class.build(headers:).post("#{server.base_url}/post", form:) data = JSON.parse(res.body.to_s) expect(data.dig("form", "foo")).to eq("bar") end end context "with application/json" do - let!(:json) { { foo: "bar" } } - let(:headers) { { "content-type": "application/json" } } + let!(:json) { {foo: "bar"} } + let(:headers) { {"content-type": "application/json"} } it do - res = described_class.build(headers: headers).post("#{server.base_url}/post", json: json) + res = described_class.build(headers:).post("#{server.base_url}/post", json:) data = JSON.parse(res.body.to_s) inner_data = JSON.parse(data["data"]) expect(inner_data["foo"]).to eq("bar") diff --git a/spec/mihari_spec.rb b/spec/mihari_spec.rb index fdda416ca..a36136f88 100644 --- a/spec/mihari_spec.rb +++ b/spec/mihari_spec.rb @@ -11,13 +11,13 @@ describe "#sidekiq?" do it "returns false in RSpec" do - expect(Mihari.sidekiq?).to eq(false) + expect(described_class.sidekiq?).to eq(false) end end describe "#puma?" do it "returns false in RSpec" do - expect(Mihari.puma?).to eq(false) + expect(described_class.puma?).to eq(false) end end end diff --git a/spec/models/artifact_spec.rb b/spec/models/artifact_spec.rb index 560cddbf2..f320cedc1 100644 --- a/spec/models/artifact_spec.rb +++ b/spec/models/artifact_spec.rb @@ -49,7 +49,7 @@ obj = described_class.new(data: artifact.data, alert_id: alert.id) obj.rule_id = rule.id - expect(obj.unique?(base_time: base_time, artifact_ttl: artifact_ttl)).to be false + expect(obj.unique?(base_time:, artifact_ttl:)).to be false end it do @@ -58,7 +58,7 @@ end obj = described_class.new(data: artifact.data, alert_id: alert.id) - expect(obj.unique?(base_time: base_time, artifact_ttl: artifact_ttl)).to be true + expect(obj.unique?(base_time:, artifact_ttl:)).to be true end end end diff --git a/spec/rule_spec.rb b/spec/rule_spec.rb index 05dacc109..5c5e6ed80 100644 --- a/spec/rule_spec.rb +++ b/spec/rule_spec.rb @@ -10,23 +10,23 @@ let!(:tags) { %w[test] } let(:falsepositives) { [] } let(:data_types) { Mihari::DEFAULT_DATA_TYPES } - let!(:emitters) { [{ emitter: "database" }] } + let!(:emitters) { [{emitter: "database"}] } let!(:created_on) { Date.today } let!(:updated_on) { Date.today } let!(:artifact_ttl) { 0 } let(:rule) do described_class.new( - title: title, - description: description, - tags: tags, - queries: queries, - id: id, - data_types: data_types, - falsepositives: falsepositives, - emitters: emitters, - created_on: created_on, - updated_on: updated_on, - artifact_ttl: artifact_ttl + title:, + description:, + tags:, + queries:, + id:, + data_types:, + falsepositives:, + emitters:, + created_on:, + updated_on:, + artifact_ttl: ) end @@ -100,7 +100,7 @@ context "with an invalid analyzer" do let(:queries) do [ - { analyzer: "shodan", query: "foo" } + {analyzer: "shodan", query: "foo"} ] end diff --git a/spec/schemas/rule_spec.rb b/spec/schemas/rule_spec.rb index 7ee0e9b8c..cf8452d93 100644 --- a/spec/schemas/rule_spec.rb +++ b/spec/schemas/rule_spec.rb @@ -14,15 +14,15 @@ let(:artifact_ttl) { nil } let(:data) do { - id: id, - description: description, - title: title, - queries: queries, - emitters: emitters, - enrichers: enrichers, - falsepositives: falsepositives, - data_types: data_types, - artifact_ttl: artifact_ttl + id:, + description:, + title:, + queries:, + emitters:, + enrichers:, + falsepositives:, + data_types:, + artifact_ttl: }.compact end @@ -39,7 +39,7 @@ let(:queries) do analyzers = Mihari.analyzer_to_class.keys - %w[zoomeye crtsh feed hunterhow] analyzers.map do |analyzer| - { analyzer: analyzer, query: "foo" } + {analyzer:, query: "foo"} end end @@ -52,9 +52,9 @@ context "with analyzers need additional options" do let(:queries) do [ - { analyzer: "crtsh", query: "foo", exclude_expired: true }, - { analyzer: "zoomeye", query: "foo", type: "host" }, - { analyzer: "zoomeye", query: "foo", type: "host", options: { interval: 10 } } + {analyzer: "crtsh", query: "foo", exclude_expired: true}, + {analyzer: "zoomeye", query: "foo", type: "host"}, + {analyzer: "zoomeye", query: "foo", type: "host", options: {interval: 10}} ] end @@ -75,7 +75,7 @@ end context "with invalid analyzer name" do - let(:queries) { [{ analyzer: "foo", query: "foo" }] } + let(:queries) { [{analyzer: "foo", query: "foo"}] } it do result = contract.call(**data) @@ -86,9 +86,9 @@ context "with invalid options" do let(:queries) do [ - { analyzer: "shodan", query: "foo" }, - { analyzer: "crtsh", query: "foo", exclude_expired: 1 }, # should be bool - { analyzer: "zoomeye", query: "foo", type: "bar" } # should be any of host or web + {analyzer: "shodan", query: "foo"}, + {analyzer: "crtsh", query: "foo", exclude_expired: 1}, # should be bool + {analyzer: "zoomeye", query: "foo", type: "bar"} # should be any of host or web ] end @@ -144,7 +144,7 @@ end context "with invalid emitter name" do - let(:emitters) { [{ emitter: "foo" }] } + let(:emitters) { [{emitter: "foo"}] } it do result = contract.call(**data) @@ -153,11 +153,11 @@ end context "without having database emitter" do - let(:emitters) { [{ emitter: "misp" }] } + let(:emitters) { [{emitter: "misp"}] } it do result = contract.call(**data) - expect(result.errors.to_h).to eq({ emitters: ["Emitter:database should be included in emitters"] }) + expect(result.errors.to_h).to eq({emitters: ["Emitter:database should be included in emitters"]}) end end end diff --git a/spec/services/feed_parser_spec.rb b/spec/services/feed_parser_spec.rb index 36975ca92..48447542e 100644 --- a/spec/services/feed_parser_spec.rb +++ b/spec/services/feed_parser_spec.rb @@ -4,7 +4,7 @@ let!(:data) do { a: %w[a b c], - b: [{ foo: "bar", bar: "foo" }, { foo: "foo", bar: "bar" }], + b: [{foo: "bar", bar: "foo"}, {foo: "foo", bar: "bar"}], c: [%w[1 2 3], %w[4 5 6], %w[7 8 9]] } end diff --git a/spec/support/httpbin.rb b/spec/support/httpbin.rb index e1ec86ac5..d4b17a21c 100644 --- a/spec/support/httpbin.rb +++ b/spec/support/httpbin.rb @@ -56,28 +56,28 @@ def body def body_payload return {} if body == "" - return { data: body, files: {}, form: {}, json: JSON.parse(body) } if json? - return { data: "", files: {}, form: Rack::Utils.parse_nested_query(body), json: nil } if form_data? + return {data: body, files: {}, form: {}, json: JSON.parse(body)} if json? + return {data: "", files: {}, form: Rack::Utils.parse_nested_query(body), json: nil} if form_data? - { data: body, files: {}, form: {}, json: nil } + {data: body, files: {}, form: {}, json: nil} end def ok_response - payload = body_payload.merge(args: query_string, headers: headers, origin: origin, url: url) + payload = body_payload.merge(args: query_string, headers:, origin:, url:) - ["200", { "Content-Type" => "application/json" }, [JSON.generate(payload)]] - ["200", { "Content-Type" => "text/plain" }, [JSON.generate(payload)]] + ["200", {"Content-Type" => "application/json"}, [JSON.generate(payload)]] + ["200", {"Content-Type" => "text/plain"}, [JSON.generate(payload)]] end def status_response(status) - [status, { "Content-Type" => "text/plain" }, [JSON.generate({})]] + [status, {"Content-Type" => "text/plain"}, [JSON.generate({})]] end def error_404 - ["404", { "Content-Type" => "application/json" }, [JSON.generate({})]] + ["404", {"Content-Type" => "application/json"}, [JSON.generate({})]] end def error_405 - ["405", { "Content-Type" => "application/json" }, [JSON.generate({})]] + ["405", {"Content-Type" => "application/json"}, [JSON.generate({})]] end end diff --git a/spec/support/shared_contexts/sidekiq_context.rb b/spec/support/shared_contexts/sidekiq_context.rb index 23ef5ab14..e86ed74a2 100644 --- a/spec/support/shared_contexts/sidekiq_context.rb +++ b/spec/support/shared_contexts/sidekiq_context.rb @@ -3,21 +3,21 @@ RSpec.shared_context "with faked Sidekiq configuration" do before(:all) do Sidekiq.configure_server do |config| - config.redis = { url: "redis://localhost:6379" } + config.redis = {url: "redis://localhost:6379"} end Sidekiq.configure_client do |config| - config.redis = { url: "redis://localhost:6379" } + config.redis = {url: "redis://localhost:6379"} end end after(:all) do Sidekiq.configure_server do |config| - config.redis = { url: Mihari.config.sidekiq_redis_url.to_s } + config.redis = {url: Mihari.config.sidekiq_redis_url.to_s} end Sidekiq.configure_client do |config| - config.redis = { url: Mihari.config.sidekiq_redis_url.to_s } + config.redis = {url: Mihari.config.sidekiq_redis_url.to_s} end end end diff --git a/spec/web/endpoints/alerts_spec.rb b/spec/web/endpoints/alerts_spec.rb index b2f879c37..9ef47e11d 100644 --- a/spec/web/endpoints/alerts_spec.rb +++ b/spec/web/endpoints/alerts_spec.rb @@ -39,7 +39,7 @@ def app context "with invalid page type" do it "returns 400" do - get "/api/alerts", { page: "foo" } + get "/api/alerts", {page: "foo"} expect(last_response.status).to eq(400) end end @@ -63,13 +63,13 @@ def app describe "post /api/alerts" do context "with invalid format" do it "returns 400" do - post("/api/alerts/", { foo: "bar" }.to_json, "CONTENT_TYPE" => "application/json") + post("/api/alerts/", {foo: "bar"}.to_json, "CONTENT_TYPE" => "application/json") expect(last_response.status).to eq(400) end end context "with valid params" do - let!(:payload) { { ruleId: rule.id, artifacts: ["1.1.1.1"] } } + let!(:payload) { {ruleId: rule.id, artifacts: ["1.1.1.1"]} } it "returns 201" do post("/api/alerts/", payload.to_json, "CONTENT_TYPE" => "application/json") diff --git a/spec/web/endpoints/rules_spec.rb b/spec/web/endpoints/rules_spec.rb index 54af3c406..30f24fe8f 100644 --- a/spec/web/endpoints/rules_spec.rb +++ b/spec/web/endpoints/rules_spec.rb @@ -58,7 +58,7 @@ def app data["title"] = title end end - let(:payload) { { yaml: data.to_yaml } } + let(:payload) { {yaml: data.to_yaml} } it "returns 204" do put("/api/rules/", payload.to_json, "CONTENT_TYPE" => "application/json") @@ -89,7 +89,7 @@ def app data["id"] = Faker::Internet.unique.uuid end end - let!(:payload) { { yaml: data.to_yaml } } + let!(:payload) { {yaml: data.to_yaml} } it "returns 201" do post("/api/rules/", payload.to_json, "CONTENT_TYPE" => "application/json") @@ -105,14 +105,14 @@ def app context "with invalid YAML format" do it "returns 422" do - post("/api/rules/", { yaml: { foo: "bar" }.to_yaml }.to_json, "CONTENT_TYPE" => "application/json") + post("/api/rules/", {yaml: {foo: "bar"}.to_yaml}.to_json, "CONTENT_TYPE" => "application/json") expect(last_response.status).to eq(422) end end context "without having YAML" do it "returns 400" do - post("/api/rules/", { foo: "bar" }.to_json, "CONTENT_TYPE" => "application/json") + post("/api/rules/", {foo: "bar"}.to_json, "CONTENT_TYPE" => "application/json") expect(last_response.status).to eq(400) end end