Sha256: 396ebfed9c1544308b713b70ec82e18e5ef41997b0176d3dc2b8d39de3d9c31f

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Mihari
  module Enrichers
    #
    # Whois enricher
    #
    class Whois < Base
      prepend MemoWise

      #
      # Query IAIA Whois API
      #
      # @param [Mihari::Models::Artifact] artifact
      #
      def call(artifact)
        return if artifact.domain.nil?

        artifact.tap do |tapped|
          tapped.whois_record ||= memoized_lookup(PublicSuffix.domain(artifact.domain))
        end
      end

      private

      def client
        @client ||= Clients::Whois.new(timeout:)
      end

      #
      # @param [Mihari::Models::Artifact] artifact
      #
      # @return [Boolean]
      #
      def callable_relationships?(artifact)
        artifact.whois_record.nil?
      end

      def supported_data_types
        %w[url domain]
      end

      #
      # @param [String] domain
      #
      # @return [Mihari::Models::WhoisRecord, nil]
      #
      def memoized_lookup(domain)
        client.lookup domain
      end
      memo_wise :memoized_lookup
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mihari-8.0.0 lib/mihari/enrichers/whois.rb
mihari-7.6.4 lib/mihari/enrichers/whois.rb
mihari-7.6.3 lib/mihari/enrichers/whois.rb