Class: AcmeNsupdate::Strategies::Dns01

Inherits:
Object
  • Object
show all
Includes:
AcmeNsupdate::Strategy
Defined in:
lib/acme_nsupdate/strategies/dns01.rb

Constant Summary collapse

IDENTIFIER =
"dns-01"

Instance Method Summary collapse

Methods included from AcmeNsupdate::Strategy

for, included, strategies, #verify_domains

Constructor Details

#initialize(client) ⇒ Dns01

Returns a new instance of Dns01.



12
13
14
# File 'lib/acme_nsupdate/strategies/dns01.rb', line 12

def initialize client
  @client = client
end

Instance Method Details

#cleanup(challenges) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/acme_nsupdate/strategies/dns01.rb', line 39

def cleanup challenges
  @client.logger.info("Cleaning up challenges")
  challenges.each do |domain, challenge|
    nsupdate = @client.build_nsupdate
    nsupdate.del(*record(domain, challenge))
    nsupdate.send
  end
end

#publish_challenges(order) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/acme_nsupdate/strategies/dns01.rb', line 16

def publish_challenges(order)
  challenges = map_authorizations(order) {|domain, authorization|
    challenge = authorization.dns01
    abort "Challenge dns-01 not supported by the given ACME server" unless challenge

    nsupdate = @client.build_nsupdate
    nsupdate.del(*record(domain, challenge, true)) unless @client.options[:keep]
    nsupdate.add(*record(domain, challenge), @client.options[:txt_ttl])
    nsupdate.send

    challenge
  }

  unless challenges.empty?
    @client.logger.info "Waiting up to 120 seconds for the DNS updates to go live"
    unless verify_live_challenges(@client.options[:master], challenges)
      raise AcmeNsupdate::Client::Error, "DNS challenges didn't appear on all nameservers within 120 seconds"
    end
  end

  challenges
end