class LetsencryptWebfaction::DomainValidator

Public Class Methods

new(order, client, public_dirs) click to toggle source
# File lib/letsencrypt_webfaction/domain_validator.rb, line 7
def initialize(order, client, public_dirs)
  @order = order
  @client = client
  @public_dirs = public_dirs.map { |dir| File.expand_path(dir) }
end

Public Instance Methods

validate!() click to toggle source
# File lib/letsencrypt_webfaction/domain_validator.rb, line 13
def validate! # rubocop:disable Metrics/MethodLength
  write_files!

  challenges.map(&:request_validation).tap do |requests|
    next unless requests.any?(&:!)

    $stderr.puts 'Failed to request validations.'
    return false
  end

  10.times do
    challenges.each(&:reload)
    break if no_challenges_pending?

    sleep(2)
  end

  return true if all_challenges_valid?

  print_errors
  false
end

Private Instance Methods

all_challenges_valid?() click to toggle source
# File lib/letsencrypt_webfaction/domain_validator.rb, line 46
def all_challenges_valid?
  challenges.reject { |challenge| challenge.status == 'valid' }.empty?
end
challenges() click to toggle source
# File lib/letsencrypt_webfaction/domain_validator.rb, line 38
def challenges
  @challenges ||= @order.authorizations.map(&:http)
end
no_challenges_pending?() click to toggle source
# File lib/letsencrypt_webfaction/domain_validator.rb, line 42
def no_challenges_pending?
  challenges.none? { |challenge| challenge.status == 'pending' }
end
print_errors() click to toggle source
write_files!() click to toggle source
# File lib/letsencrypt_webfaction/domain_validator.rb, line 50
def write_files!
  challenges.each do |challenge|
    @public_dirs.each do |public_dir|
      # 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