Class: LetsencryptHeroku::Process::AuthorizeDomains

Inherits:
Object
  • Object
show all
Includes:
Tools
Defined in:
lib/letsencrypt_heroku/process/authorize_domains.rb

Instance Method Summary collapse

Methods included from Tools

#banner, #error, #execute, #log, #output

Instance Method Details

#authorize(domain:, context:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/letsencrypt_heroku/process/authorize_domains.rb', line 13

def authorize(domain:, context:)
  challenge = context.client.authorize(domain: domain).http01

  execute "heroku config:set LETSENCRYPT_RESPONSE=#{challenge.file_content} --app #{context.config.heroku_challenge_app}"

  test_response(domain: domain, challenge: challenge)

  challenge.request_verification
  sleep(1) while 'pending' == challenge.verify_status
  challenge.verify_status == 'valid' or error('failed authorization')
end

#perform(context) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/letsencrypt_heroku/process/authorize_domains.rb', line 5

def perform(context)
  context.config.domains.each do |domain|
    output "Authorize #{domain}" do
      authorize(domain: domain, context: context)
    end
  end
end

#test_response(domain:, challenge:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/letsencrypt_heroku/process/authorize_domains.rb', line 25

def test_response(domain:, challenge:)
  url        = "http://#{domain}/#{challenge.filename}"
  fail_count = 0
  answer     = nil

  while answer != challenge.file_content
    error('failed test response') if fail_count > 30
    fail_count += 1
    sleep(5)
    answer = `curl -sL #{url}`
  end
end