Sha256: 47156de5e44c493db0c7b7fbf9dee15b8596b6a0b0dbd182480a382ca78f0375

Contents?: true

Size: 717 Bytes

Versions: 1

Compression:

Stored size: 717 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Models
    class Port < ActiveRecord::Base
      belongs_to :artifact

      class << self
        include Dry::Monads[:result]

        #
        # Build ports
        #
        # @param [String] ip
        # @param [Mihari::Enrichers::Shodan] enricher
        #
        # @return [Array<Mihari::Port>]
        #
        def build_by_ip(ip, enricher: Enrichers::Shodan.new)
          result = enricher.query_result(ip).bind do |res|
            if res.nil?
              Success []
            else
              Success(res.ports.map { |port| new(port: port) })
            end
          end
          result.value_or []
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mihari-5.6.2 lib/mihari/models/port.rb