Sha256: 55cc191607483c8e8d2e4b14dd5f26630949f028413d6b741a73119430b5e8cf

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "dnsruby"
require "public_suffix"

module GitHubPages
  module HealthCheck
    class CAA
      attr_reader :host
      attr_reader :error

      def initialize(host)
        @host = host
      end

      def errored?
        records # load the records first
        !error.nil?
      end

      def lets_encrypt_allowed?
        return false if errored?
        return true unless records_present?
        records.any? { |r| r.property_value == "letsencrypt.org" }
      end

      def records_present?
        return false if errored?
        records && !records.empty?
      end

      def records
        @records ||= (get_caa_records(host) | get_caa_records(PublicSuffix.domain(host)))
      end

      private

      def get_caa_records(domain)
        query(domain).select { |r| r.type == "CAA" && r.property_tag == "issue" }
      end

      def query(domain)
        resolver = Dnsruby::Resolver.new
        resolver.retry_times = 2
        resolver.query_timeout = 2
        begin
          resolver.query(domain, "CAA", "IN").answer
        rescue StandardError => e
          @error = e
          []
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
github-pages-health-check-1.7.3 lib/github-pages-health-check/caa.rb
github-pages-health-check-1.7.2 lib/github-pages-health-check/caa.rb
github-pages-health-check-1.7.1 lib/github-pages-health-check/caa.rb
github-pages-health-check-1.7.0 lib/github-pages-health-check/caa.rb
github-pages-health-check-1.6.0 lib/github-pages-health-check/caa.rb