Sha256: b52b779a89ab2bd0018b204ab862903c10057c1a36dd9d519f80a5f1e96623e6

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Mihari
  module Commands
    #
    # Search sub-commands
    #
    module Search
      class << self
        def included(thor)
          thor.class_eval do
            include Dry::Monads[:try, :result]
            include Mixins

            desc "search [PATH_OR_ID]", "Search by a rule (Outputs null if there is no new finding)"
            around :with_db_connection
            method_option :force_overwrite, type: :boolean, aliases: "-f", desc: "Force overwriting a rule"
            #
            # Search by a rule
            #
            # @param [String] path_or_id
            #
            def search(path_or_id)
              result = Dry::Monads::Try[StandardError] do
                # @type [Mihari::Rule]
                rule = Services::RuleBuilder.call(path_or_id)

                force_overwrite = options["force_overwrite"] || false
                message = "There is a diff in the rule. Are you sure you want to overwrite the rule? (y/n)"
                exit 0 if rule.diff? && !force_overwrite && !yes?(message)

                rule.update_or_create
                rule.call
              end.to_result

              # @type [Mihari::Models::Alert]
              alert = result.value!
              data = Entities::Alert.represent(alert)
              puts JSON.pretty_generate(data.as_json)
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mihari-6.3.0 lib/mihari/commands/search.rb
mihari-6.2.0 lib/mihari/commands/search.rb
mihari-6.1.0 lib/mihari/commands/search.rb
mihari-6.0.0 lib/mihari/commands/search.rb
mihari-5.7.2 lib/mihari/commands/search.rb