Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename #result to #get_result #1129

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mihari/actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def call(*args, **kwargs)
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
end

def result(...)
def get_result(...)
Try[StandardError] do
retry_on_error(times: retry_times, interval: retry_interval, exponential_backoff: retry_exponential_backoff) do
call(...)
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 @@ -77,7 +77,7 @@ def call
normalized_artifacts
end

def result(...)
def get_result(...)
result = Try[StandardError] do
retry_on_error(
times: retry_times,
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/commands/alert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def list_transform(q = "")
# @param [Integer] id
#
def get(id)
value = Services::AlertGetter.result(id).value!
value = Services::AlertGetter.get_result(id).value!
data = Entities::Alert.represent(value)
puts JSON.pretty_generate(data.as_json)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/commands/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def list_transform(q = "")
# @param [Integer] id
#
def get(id)
value = Services::ArtifactGetter.result(id).value!
value = Services::ArtifactGetter.get_result(id).value!
data = Entities::Artifact.represent(value)
puts JSON.pretty_generate(data.as_json)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/commands/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def list_transform(q = "")
desc "get ID", "Get a rule"
around :with_db_connection
def get(id)
value = Services::RuleGetter.result(id).value!
value = Services::RuleGetter.get_result(id).value!
data = Entities::Rule.represent(value)
puts JSON.pretty_generate(data.as_json)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/emitters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def call(artifacts)
#
# @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
#
def result(artifacts)
def get_result(artifacts)
result = Try[StandardError] do
retry_on_error(
times: retry_times,
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/enrichers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def call(artifact)
#
# @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
#
def result(artifact)
def get_result(artifact)
return unless callable?(artifact)

result = Try[StandardError] do
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/models/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def enrich_by_enrichers(enrichers)
# NOTE: doing parallel with ActiveRecord objects is troublesome (e.g. connection issue, etc.)
# so converting the object to an OpenStruct object
s = struct
results = Parallel.map(enrichers) { |enricher| enricher.result s }
results = Parallel.map(enrichers) { |enricher| enricher.get_result s }
enriched = results.compact.map { |result| result.value_or(nil) }.compact

self.dns_records = enriched.map(&:dns_records).flatten.compact
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/models/port.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class << self
# @return [Array<Mihari::Port>]
#
def build_by_ip(ip, enricher: Enrichers::Shodan.new)
enricher.result(ip).fmap do |res|
enricher.get_result(ip).fmap do |res|
(res&.ports || []).map { |port| new(port:) }
end.value_or []
end
Expand Down
8 changes: 4 additions & 4 deletions lib/mihari/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def bulk_emit
return [] if enriched_artifacts.empty?

[].tap do |out|
out << serial_emitters.map { |emitter| emitter.result(enriched_artifacts).value_or(nil) }
out << Parallel.map(parallel_emitters) { |emitter| emitter.result(enriched_artifacts).value_or(nil) }
out << serial_emitters.map { |emitter| emitter.get_result(enriched_artifacts).value_or(nil) }
out << Parallel.map(parallel_emitters) { |emitter| emitter.get_result(enriched_artifacts).value_or(nil) }
end.flatten.compact
end

Expand Down Expand Up @@ -349,8 +349,8 @@ def serial_analyzers
# @return [Array<Dry::Monads::Result::Success<Array<Mihari::Models::Artifact>>, Dry::Monads::Result::Failure>]
def analyzer_results
[].tap do |out|
out << Parallel.map(parallel_analyzers, &:result)
out << serial_analyzers.map(&:result)
out << Parallel.map(parallel_analyzers, &:get_result)
out << serial_analyzers.map(&:get_result)
end.flatten
end

Expand Down
6 changes: 3 additions & 3 deletions lib/mihari/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def call(*args, **kwargs)
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
end

def result(...)
def get_result(...)
Try[StandardError] { call(...) }.to_result
end

Expand All @@ -20,8 +20,8 @@ def call(...)
new.call(...)
end

def result(...)
new.result(...)
def get_result(...)
new.get_result(...)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/mihari/web/endpoints/alerts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Alerts < Grape::API
end
get "/:id" do
id = params[:id].to_i
result = Services::AlertGetter.result(id)
result = Services::AlertGetter.get_result(id)
return present(result.value!, with: Entities::Alert) if result.success?

case result.failure
Expand All @@ -61,7 +61,7 @@ class Alerts < Grape::API
end
delete "/:id" do
id = params["id"].to_i
result = Services::AlertDestroyer.result(id)
result = Services::AlertDestroyer.get_result(id)
return if result.success?

case result.failure
Expand All @@ -86,7 +86,7 @@ class Alerts < Grape::API
post "/" do
status 201

result = Services::AlertCreator.result(params)
result = Services::AlertCreator.get_result(params)
return present(result.value!, with: Entities::Alert) if result.success?

case result.failure
Expand Down
4 changes: 2 additions & 2 deletions lib/mihari/web/endpoints/artifacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Artifacts < Grape::API
end
get "/:id" do
id = params[:id].to_i
result = Services::ArtifactGetter.result(id)
result = Services::ArtifactGetter.get_result(id)
return present(result.value!, with: Entities::Artifact) if result.success?

case result.failure
Expand Down Expand Up @@ -98,7 +98,7 @@ class Artifacts < Grape::API
status 204

id = params["id"].to_i
result = Services::ArtifactDestroyer.result(id)
result = Services::ArtifactDestroyer.get_result(id)
return if result.success?

case result.failure
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/web/endpoints/ip_addresses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IPAddresses < Grape::API
end
get "/:ip", requirements: {ip: %r{[^/]+}} do
ip = params[:ip].to_s
result = Services::IPGetter.result(ip)
result = Services::IPGetter.get_result(ip)
if result.success?
value = result.value!
return present(
Expand Down
8 changes: 4 additions & 4 deletions lib/mihari/web/endpoints/rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def call(yaml, overwrite: true)
end
get "/:id" do
id = params[:id].to_s
result = Services::RuleGetter.result(params[:id].to_s)
result = Services::RuleGetter.get_result(params[:id].to_s)
return present(result.value!, with: Entities::Rule) if result.success?

case result.failure
Expand Down Expand Up @@ -120,7 +120,7 @@ def call(yaml, overwrite: true)

yaml = params[:yaml].to_s

result = RuleCreateUpdater.result(yaml, overwrite: false)
result = RuleCreateUpdater.get_result(yaml, overwrite: false)
return present(result.value!.model, with: Entities::Rule) if result.success?

failure = result.failure
Expand Down Expand Up @@ -151,7 +151,7 @@ def call(yaml, overwrite: true)

yaml = params[:yaml].to_s

result = RuleCreateUpdater.result(yaml, overwrite: true)
result = RuleCreateUpdater.get_result(yaml, overwrite: true)
return present(result.value!.model, with: Entities::Rule) if result.success?

failure = result.failure
Expand All @@ -178,7 +178,7 @@ def call(yaml, overwrite: true)
status 204

id = params[:id].to_s
result = Services::RuleDestroyer.result(id)
result = Services::RuleDestroyer.get_result(id)
return if result.success?

case result.failure
Expand Down
2 changes: 1 addition & 1 deletion lib/mihari/web/endpoints/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Tags < Grape::API
status 204

id = params[:id].to_i
result = Services::TagDestroyer.result(id)
result = Services::TagDestroyer.get_result(id)
return if result.success?

case result.failure
Expand Down
2 changes: 1 addition & 1 deletion spec/actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def call

describe "#result" do
it do
expect(actor.result.failure).to be_a(ZeroDivisionError)
expect(actor.get_result.failure).to be_a(ZeroDivisionError)
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions spec/fixtures/vcr_cassettes/Mihari_Enrichers_MMDB/ip_1_1_1_1.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading