Module: Mihari::Commands::Search
- Included in:
- Mihari::CLI::App, Mihari::CLI::Rule
- Defined in:
- lib/mihari/commands/search.rb
Overview
Search sub-commands
Class Method Summary collapse
Class Method Details
.included(thor) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mihari/commands/search.rb', line 10 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 = ["force_overwrite"] || false = "Are you sure you want to overwrite this rule? (y/n)" # @type [Mihari::Models::Alert] alert = Dry::Monads::Try[StandardError] do # @type [Mihari::Rule] rule = Services::RuleBuilder.call(path_or_id) exit 0 if rule.diff? && !force_overwrite && !yes?() rule.update_or_create rule.call end.value! data = Entities::Alert.represent(alert) puts JSON.pretty_generate(data.as_json) end end end |