Sha256: db007bd2d0994751ff29535ae08d7d53dd849a69e009ace6aa102db3b7ad2163

Contents?: true

Size: 764 Bytes

Versions: 7

Compression:

Stored size: 764 Bytes

Contents

# frozen_string_literal: true

module Mihari
  module Models
    #
    # AS model
    #
    class AutonomousSystem < ActiveRecord::Base
      belongs_to :artifact

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

        #
        # Build AS
        #
        # @param [String] ip
        # @param [Mihari::Enrichers::IPInfo] enricher
        #
        # @return [Mihari::AutonomousSystem, nil]
        #
        def build_by_ip(ip, enricher: Enrichers::IPInfo.new)
          result = enricher.result(ip).bind do |res|
            value = res&.asn
            if value.nil?
              Success nil
            else
              Success new(asn: value)
            end
          end
          result.value_or nil
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mihari-6.3.0 lib/mihari/models/autonomous_system.rb
mihari-6.2.0 lib/mihari/models/autonomous_system.rb
mihari-6.1.0 lib/mihari/models/autonomous_system.rb
mihari-6.0.0 lib/mihari/models/autonomous_system.rb
mihari-5.7.2 lib/mihari/models/autonomous_system.rb
mihari-5.7.1 lib/mihari/models/autonomous_system.rb
mihari-5.7.0 lib/mihari/models/autonomous_system.rb