Sha256: 1bf169593acbbd05d26dc7c121f95205a0c675f1a4472652e451b1f4537d8b93

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require "securitytrails"

module Mihari
  module Analyzers
    class SecurityTrailsDomainFeed < Base
      attr_reader :type

      attr_reader :title
      attr_reader :description
      attr_reader :tags

      def initialize(regexp, type: "registered", title: nil, description: nil, tags: [])
        super()

        @_regexp = regexp
        @type = type

        raise InvalidInputError, "#{@_regexp} is not a valid regexp" unless regexp
        raise InvalidInputError, "#{type} is not a valid type" unless valid_type?

        @title = title || "SecurityTrails domain feed lookup"
        @description = description || "Regexp = /#{@_regexp}/"
        @tags = tags
      end

      def artifacts
        lookup || []
      end

      private

      def config_keys
        %w(SECURITYTRAILS_API_KEY)
      end

      def api
        @api ||= ::SecurityTrails::API.new
      end

      def valid_type?
        %w(all new registered).include? type
      end

      def regexp
        @regexp ||= Regexp.compile(@_regexp)
      rescue InvalidInputError => _e
        nil
      end

      def lookup
        new_domains.select do |domain|
          regexp.match? domain
        end
      end

      def new_domains
        api.feeds.domains type
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mihari-0.17.5 lib/mihari/analyzers/securitytrails_domain_feed.rb
mihari-0.17.4 lib/mihari/analyzers/securitytrails_domain_feed.rb
mihari-0.17.3 lib/mihari/analyzers/securitytrails_domain_feed.rb
mihari-0.17.2 lib/mihari/analyzers/securitytrails_domain_feed.rb
mihari-0.17.1 lib/mihari/analyzers/securitytrails_domain_feed.rb