authorization.rb 1.2 KB
Newer Older
1
2
3
4
5
class Acme::Client::Resources::Authorization
  HTTP01 = Acme::Client::Resources::Challenges::HTTP01
  DNS01 = Acme::Client::Resources::Challenges::DNS01
  TLSSNI01 = Acme::Client::Resources::Challenges::TLSSNI01

6
  attr_reader :client, :uri, :domain, :status, :expires, :http01, :dns01, :tls_sni01
7

8
  def initialize(client, uri, response)
9
    @client = client
10
    @uri = uri
11
12
13
    assign_attributes(response.body)
  end

14
15
  def verify_status
    response = @client.connection.get(@uri)
16

17
18
    assign_attributes(response.body)
    status
19
20
  end

21
22
  private

23
24
25
26
  def assign_attributes(body)
    @expires = Time.iso8601(body['expires']) if body.key? 'expires'
    @domain = body['identifier']['value']
    @status = body['status']
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
    assign_challenges(body['challenges'])
  end

  def assign_challenges(challenges)
    challenges.each do |attributes|
      challenge = case attributes.fetch('type')
                  when 'http-01'
                    @http01 ||= HTTP01.new(self)
                  when 'dns-01'
                    @dns01 ||= DNS01.new(self)
                  when 'tls-sni-01'
                    @tls_sni01 ||= TLSSNI01.new(self)
      end

      challenge.assign_attributes(attributes) if challenge
    end
43
44
  end
end