Skip to content

Commit

Permalink
refactor: rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ninoseki committed Oct 2, 2019
1 parent ff9e907 commit e5b59eb
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 24 deletions.
4 changes: 3 additions & 1 deletion lib/mihari/analyzers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

module Mihari
module Analyzers
class Base < Configurable
class Base
include Configurable

# @return [Array<String>, Array<Mihari::Artifact>]
def artifacts
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/analyzers/censys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def artifacts

private

def keys
def config_keys
%w(CENSYS_ID CENSYS_SECRET)
end

def api
raise ArgumentError, configuration_status unless valid?
raise ArgumentError, configuration_status unless configured?

@api ||= ::Censys::API.new
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/analyzers/circl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def artifacts

private

def keys
def config_keys
%w(CIRCL_PASSIVE_USERNAME CIRCL_PASSIVE_PASSWORD)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/analyzers/onyphe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def artifacts

private

def keys
def config_keys
%w(ONYPHE_API_KEY)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/analyzers/securitytrails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def artifacts

private

def keys
def config_keys
%w(SECURITYTRAILS_API_KEY)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/analyzers/securitytrails_domain_feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def artifacts

private

def keys
def config_keys
%w(SECURITYTRAILS_API_KEY)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/analyzers/shodan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def artifacts

private

def keys
def config_keys
%w(SHODAN_API_KEY)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/analyzers/virustotal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def artifacts

private

def keys
def config_keys
%w(VIRUSTOTAL_API_KEY)
end

Expand Down
18 changes: 8 additions & 10 deletions lib/mihari/configurable.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# frozen_string_literal: true

module Mihari
class Configurable
def valid?
keys.all? { |key| ENV.key? key }
module Configurable
def configured?
config_keys.all? { |key| ENV.key? key }
end

def configuration_status
return nil if keys.empty?
return nil if config_keys.empty?

names = keys.join(" and ")
be_verb = keys.length == 1 ? "is" : "are"
status = valid? ? "found" : "missing"
names = config_keys.join(" and ")
be_verb = config_keys.length == 1 ? "is" : "are"
status = configured? ? "found" : "missing"
"#{names} #{be_verb} #{status}"
end

private

def keys
def config_keys
[]
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/mihari/emitters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

module Mihari
module Emitters
class Base < Configurable
class Base
include Configurable

def self.inherited(child)
Mihari.emitters << child
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/emitters/misp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def emit(title:, artifacts:, tags: [], **_options)

private

def keys
def config_keys
%w(MISP_API_ENDPOINT MISP_API_KEY)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/emitters/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def emit(title:, description:, artifacts:, tags: [])

private

def keys
def config_keys
%w(SLACK_WEBHOOK_URL)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/emitters/the_hive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def emit(title:, description:, artifacts:, tags: [])

private

def keys
def config_keys
%w(THEHIVE_API_ENDPOINT THEHIVE_API_KEY)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def statuses
name = full_name.split("::").last.to_s

instance = full_name.include?("analyzers") ? klass.new("dummy") : klass.new
status = instance.valid?
status = instance.configured?
message = instance.configuration_status

message ? [name, { status: status, message: message }] : nil
Expand Down

0 comments on commit e5b59eb

Please sign in to comment.