Sha256: 596f3799ef36b1b4504a3b1377109cec65e41c8d3845a593a72bcb7328c21a39

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 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 Concerns::DatabaseConnectable

            desc "search PATH_OR_ID", "Search by a rule"
            around :with_db_connection
            method_option :force_overwrite, type: :boolean, default: false, aliases: "-f",
              desc: "Force overwriting a rule"
            #
            # Search by a rule
            #
            # @param [String] path_or_id
            #
            def search(path_or_id)
              force_overwrite = options["force_overwrite"] || false
              message = "Are you sure you want to overwrite this rule? (y/n)"

              # @type [Mihari::Rule]
              rule = Services::RuleBuilder.call(path_or_id)
              exit 0 if rule.diff? && !force_overwrite && !yes?(message)

              rule.update_or_create
              alert = rule.call

              data = Entities::Alert.represent(alert)
              puts JSON.pretty_generate(data.as_json)
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mihari-8.0.2 lib/mihari/commands/search.rb
mihari-8.0.1 lib/mihari/commands/search.rb
mihari-8.0.0 lib/mihari/commands/search.rb