Sha256: 6c576d48dad4c52cad6bbfcbc2088ccc6f4e3a36af37ef4f6e2166d6749942a7

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

module LetsencryptWebfaction
  class DomainValidator
    def initialize(domains, client, public_dir)
      @domains = domains
      @client = client
      @public_dir = File.expand_path(public_dir)
    end

    def validate!
      write_files!

      challenges.each(&:request_verification)

      i = 0
      until all_challenges_valid? || i == 10
        # Wait a bit for the server to make the request, or really just blink, it should be fast.
        sleep(1)

        i += 1
      end

      raise 'Failed to verify statuses in 10 seconds.' unless all_challenges_valid?
    end

    private

    def authorizations
      @domains.map { |domain| @client.authorize(domain: domain) }
    end

    def challenges
      @challenges ||= authorizations.map(&:http01)
    end

    def all_challenges_valid?
      challenges.reject { |challenge| challenge.verify_status == 'valid' }.empty?
    end

    def write_files!
      challenges.each do |challenge|
        # Save the file. We'll create a public directory to serve it from, and we'll creating the challenge directory.
        FileUtils.mkdir_p(File.join(@public_dir, File.dirname(challenge.filename)))

        # Then writing the file
        File.write(File.join(@public_dir, challenge.filename), challenge.file_content)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
letsencrypt_webfaction-1.1.6 lib/letsencrypt_webfaction/domain_validator.rb
letsencrypt_webfaction-1.1.5 lib/letsencrypt_webfaction/domain_validator.rb
letsencrypt_webfaction-1.1.4 lib/letsencrypt_webfaction/domain_validator.rb
letsencrypt_webfaction-1.1.3 lib/letsencrypt_webfaction/domain_validator.rb
letsencrypt_webfaction-1.1.2 lib/letsencrypt_webfaction/domain_validator.rb
letsencrypt_webfaction-1.1.1 lib/letsencrypt_webfaction/domain_validator.rb
letsencrypt_webfaction-1.1.0 lib/letsencrypt_webfaction/domain_validator.rb