lib/mihari/analyzers/base.rb in mihari-0.10.0 vs lib/mihari/analyzers/base.rb in mihari-0.11.0

- old
+ new

@@ -3,14 +3,11 @@ require "parallel" module Mihari module Analyzers class Base - def initialize - @the_hive = TheHive.new - @cache = Cache.new - end + include Configurable # @return [Array<String>, Array<Mihari::Artifact>] def artifacts raise NotImplementedError, "You must implement #{self.class}##{__method__}" end @@ -45,29 +42,41 @@ emitter.emit(title: title, description: description, artifacts: unique_artifacts, tags: tags) rescue StandardError => e puts "Emission by #{emitter.class} is failed: #{e}" end + def self.inherited(child) + Mihari.analyzers << child + end + private + def the_hive + @the_hive ||= TheHive.new + end + + def cache + @cache ||= Cache.new + end + # @return [Array<Mihari::Artifact>] def normalized_artifacts @normalized_artifacts ||= artifacts.map do |artifact| artifact.is_a?(Artifact) ? artifact : Artifact.new(artifact) end.select(&:valid?) end def uncached_artifacts @uncached_artifacts ||= normalized_artifacts.reject do |artifact| - @cache.cached? artifact.data + cache.cached? artifact.data end end # @return [Array<Mihari::Artifact>] def unique_artifacts - return uncached_artifacts unless @the_hive.valid? + return uncached_artifacts unless the_hive.valid? - @unique_artifacts ||= @the_hive.artifact.find_non_existing_artifacts(uncached_artifacts) + @unique_artifacts ||= the_hive.artifact.find_non_existing_artifacts(uncached_artifacts) end def set_unique_artifacts unique_artifacts rescue ArgumentError => _e