Skip to content

Commit

Permalink
Merge pull request #1054 from ninoseki/renew-standard-rubocop
Browse files Browse the repository at this point in the history
refactor: simplify RuboCop & Standard config
  • Loading branch information
ninoseki authored Jan 27, 2024
2 parents 2076bc3 + 39c3961 commit fc0c453
Show file tree
Hide file tree
Showing 133 changed files with 499 additions and 513 deletions.
4 changes: 0 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
Style/HashSyntax:
EnforcedShorthandSyntax: either
Style/StringLiterals:
EnforcedStyle: double_quotes
Metrics/BlockLength:
Max: 150
Exclude:
Expand Down
4 changes: 0 additions & 4 deletions .standard.yml

This file was deleted.

2 changes: 1 addition & 1 deletion lib/mihari.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def sidekiq?
#
def puma?
!Puma.stats.nil?
rescue StandardError
rescue
false
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/analyzers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Base < Actor
# @param [Hash, nil] options
#
def initialize(query, options: nil)
super(options: options)
super(options:)

@query = query
end
Expand Down
10 changes: 5 additions & 5 deletions lib/mihari/analyzers/binaryedge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/mihari/analyzers/censys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +29,7 @@ def initialize(query, options: nil, id: nil, secret: nil)
# @return [Array<Mihari::Models::Artifact>]
#
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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/analyzers/circl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions lib/mihari/analyzers/crtsh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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
end

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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/analyzers/dnstwister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,7 +40,7 @@ def valid_type?
end

def client
Clients::DNSTwister.new(timeout: timeout)
Clients::DNSTwister.new(timeout:)
end

#
Expand Down
30 changes: 12 additions & 18 deletions lib/mihari/analyzers/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/mihari/analyzers/fofa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/mihari/analyzers/greynoise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ 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

def artifacts
client.gnql_search_with_pagination(
query,
pagination_limit: pagination_limit
pagination_limit:
).map(&:artifacts).flatten
end

private

def client
Clients::GreyNoise.new(
api_key: api_key,
pagination_interval: pagination_interval,
timeout: timeout
api_key:,
pagination_interval:,
timeout:
)
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/mihari/analyzers/hunterhow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/mihari/analyzers/onyphe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ 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

def artifacts
client.datascan_with_pagination(
query,
pagination_limit: pagination_limit
pagination_limit:
).map(&:artifacts).flatten
end

private

def client
Clients::Onyphe.new(
api_key: api_key,
pagination_interval: pagination_interval,
timeout: timeout
api_key:,
pagination_interval:,
timeout:
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/analyzers/otx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

#
Expand Down
6 changes: 3 additions & 3 deletions lib/mihari/analyzers/passivetotal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -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

#
Expand Down
6 changes: 3 additions & 3 deletions lib/mihari/analyzers/pulsedive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -38,15 +38,15 @@ def artifacts
nil
else
data = property["value"]
Models::Artifact.new(data: data, metadata: property)
Models::Artifact.new(data:, metadata: property)
end
end
end

private

def client
@client ||= Clients::PulseDive.new(api_key: api_key, timeout: timeout)
@client ||= Clients::PulseDive.new(api_key:, timeout:)
end

#
Expand Down
Loading

0 comments on commit fc0c453

Please sign in to comment.