lib/mihari/rule.rb in mihari-7.3.0 vs lib/mihari/rule.rb in mihari-7.3.1

- old
+ new

@@ -31,13 +31,13 @@ # # @return [Boolean] # def errors? - return false if @errors.nil? + return false if errors.nil? - !@errors.empty? + !errors.empty? end def [](key) data key.to_sym end @@ -161,26 +161,24 @@ # Uniquify artifacts (assure rule level uniqueness) # # @return [Array<Mihari::Models::Artifact>] # def unique_artifacts - normalized_artifacts.select do |artifact| - artifact.unique?(base_time: base_time, artifact_ttl: artifact_ttl) - end + normalized_artifacts.select { |artifact| artifact.unique?(base_time: base_time, artifact_ttl: artifact_ttl) } end # # Enriched artifacts # # @return [Array<Mihari::Models::Artifact>] # def enriched_artifacts - @enriched_artifacts ||= unique_artifacts.map do |artifact| - serial_enrichers.each { |enricher| enricher.result(artifact) } - Parallel.each(parallel_enrichers) { |enricher| enricher.result(artifact) } - - artifact + @enriched_artifacts ||= Parallel.map(unique_artifacts) do |artifact| + artifact.tap do |tapped| + # NOTE: To apply changes correctly, enrichers should be applied to an artifact serially + enrichers.each { |enricher| enricher.result(tapped) } + end end end # # Bulk emit @@ -335,13 +333,14 @@ analyzers.reject(&:parallel?) end # @return [Array<Dry::Monads::Result::Success<Array<Mihari::Models::Artifact>>, Dry::Monads::Result::Failure>] def analyzer_results - parallel_results = Parallel.map(parallel_analyzers, &:result) - serial_results = serial_analyzers.map(&:result) - parallel_results + serial_results + [].tap do |out| + out << Parallel.map(parallel_analyzers, &:result) + out << serial_analyzers.map(&:result) + end.flatten end # # Get emitter class # @@ -400,17 +399,9 @@ options = params.delete(:options) klass = get_enricher_class(name) klass.new(options: options, **params) end - end - - def parallel_enrichers - enrichers.select(&:parallel?) - end - - def serial_enrichers - enrichers.reject(&:parallel?) end # # Validate the data format #