Sha256: aa4fb4a103a94e72da133e192564817a9cfaa2f6e5f1d3cc59578a125b03cbc0

Contents?: true

Size: 1.96 KB

Versions: 6

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

module Mihari
  module Commands
    #
    # Artifact sub-commands
    #
    module Artifact
      class << self
        def included(thor)
          thor.class_eval do
            include Concerns::DatabaseConnectable

            desc "list [QUERY]", "List/search artifacts"
            around :with_db_connection
            method_option :page, type: :numeric, default: 1
            method_option :limit, type: :numeric, default: 10
            #
            # @param [String] q
            #
            def list(q = "")
              filter = Structs::Filters::Search.new(q: q, page: options["page"], limit: options["limit"])
              value = Services::ArtifactSearcher.result(filter).value!
              data = Entities::ArtifactsWithPagination.represent(
                results: value.results,
                total: value.total,
                current_page: value.filter[:page].to_i,
                page_size: value.filter[:limit].to_i
              )
              puts JSON.pretty_generate(data.as_json)
            end

            desc "get [ID]", "Get an artifact"
            around :with_db_connection
            #
            # @param [Integer] id
            #
            def get(id)
              value = Services::ArtifactGetter.result(id).value!
              data = Entities::Artifact.represent(value)
              puts JSON.pretty_generate(data.as_json)
            end

            desc "enrich [ID]", "Enrich an artifact"
            around :with_db_connection
            #
            # @param [Integer] id
            #
            def enrich(id)
              Services::ArtifactEnricher.result(id).value!
            end

            desc "delete [ID]", "Delete an artifact"
            around :with_db_connection
            #
            # @param [Integer] id
            #
            def delete(id)
              Services::ArtifactDestroyer.result(id).value!
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mihari-7.0.5 lib/mihari/commands/artifact.rb
mihari-7.0.4 lib/mihari/commands/artifact.rb
mihari-7.0.3 lib/mihari/commands/artifact.rb
mihari-7.0.2 lib/mihari/commands/artifact.rb
mihari-7.0.1 lib/mihari/commands/artifact.rb
mihari-7.0.0 lib/mihari/commands/artifact.rb