Class: Acmesmith::OrderingService

Inherits:
Object
  • Object
show all
Defined in:
lib/acmesmith/ordering_service.rb

Defined Under Namespace

Classes: NotCompleted

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(acme:, identifiers:, challenge_responder_rules:, not_before: nil, not_after: nil) ⇒ OrderingService

Returns a new instance of OrderingService.

Parameters:

  • acme (Acme::Client)

    ACME client

  • identifiers (Array<String>)

    Array of domain names for a ordering certificate. The first item will be a common name.

  • challenge_responder_rules (Array<Acmesmith::Config::ChallengeResponderRule>)

    responders

  • not_before (Time) (defaults to: nil)
  • not_after (Time) (defaults to: nil)


13
14
15
16
17
18
19
# File 'lib/acmesmith/ordering_service.rb', line 13

def initialize(acme:, identifiers:, challenge_responder_rules:, not_before: nil, not_after: nil)
  @acme = acme
  @identifiers = identifiers
  @challenge_responder_rules = challenge_responder_rules
  @not_before = not_before
  @not_after = not_after
end

Instance Attribute Details

#acmeObject (readonly)

Returns the value of attribute acme.



21
22
23
# File 'lib/acmesmith/ordering_service.rb', line 21

def acme
  @acme
end

#challenge_responder_rulesObject (readonly)

Returns the value of attribute challenge_responder_rules.



21
22
23
# File 'lib/acmesmith/ordering_service.rb', line 21

def challenge_responder_rules
  @challenge_responder_rules
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



21
22
23
# File 'lib/acmesmith/ordering_service.rb', line 21

def identifiers
  @identifiers
end

#not_afterObject (readonly)

Returns the value of attribute not_after.



21
22
23
# File 'lib/acmesmith/ordering_service.rb', line 21

def not_after
  @not_after
end

#not_beforeObject (readonly)

Returns the value of attribute not_before.



21
22
23
# File 'lib/acmesmith/ordering_service.rb', line 21

def not_before
  @not_before
end

Instance Method Details

#certificateObject



80
81
82
# File 'lib/acmesmith/ordering_service.rb', line 80

def certificate
  @certificate or raise NotCompleted, "not completed yet"
end

#common_nameString

Returns:

  • (String)


90
91
92
# File 'lib/acmesmith/ordering_service.rb', line 90

def common_name
  identifiers.first
end

#csrAcme::Client::CertificateRequest

Returns:

  • (Acme::Client::CertificateRequest)


100
101
102
# File 'lib/acmesmith/ordering_service.rb', line 100

def csr
  @csr ||= Acme::Client::CertificateRequest.new(subject: { common_name: common_name }, names: sans)
end

#ensure_authorizationObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/acmesmith/ordering_service.rb', line 48

def ensure_authorization
  return if order.authorizations.empty? || order.status == 'ready'
  puts "=> Looking for required domain authorizations"
  puts
  order.authorizations.map(&:domain).each do |domain|
    puts " * #{domain}"
  end
  puts

  AuthorizationService.new(challenge_responder_rules, order.authorizations).perform!
end

#finalize_orderObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/acmesmith/ordering_service.rb', line 60

def finalize_order
  puts
  puts "=> Finalizing the order"
  puts
  puts csr.csr.to_pem
  puts

  print " * Requesting..."
  order.finalize(csr: csr)
  puts" [ ok ]"
end

#orderObject

Returns Acme::Client::Resources::Order[].

Returns:

  • Acme::Client::Resources::Order[]



85
86
87
# File 'lib/acmesmith/ordering_service.rb', line 85

def order
  @order or raise "BUG: order not yet generated"
end

#perform!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/acmesmith/ordering_service.rb', line 23

def perform!
  puts "=> Ordering a certificate for the following identifiers:"
  puts
  puts " * CN:  #{common_name}"
  sans.each do |san|
    puts " * SAN: #{san}"
  end

  puts
  puts "=> Placing an order"
  @order = acme.new_order(identifiers: identifiers, not_before: not_before, not_after: not_after)
  puts " * URL: #{order.url}"

  ensure_authorization()

  finalize_order()
  wait_order_for_complete()

  @certificate = Certificate.by_issuance(order.certificate, csr)

  puts
  puts "=> Certificate issued"
  nil
end

#sansArray<String>

Returns:

  • (Array<String>)


95
96
97
# File 'lib/acmesmith/ordering_service.rb', line 95

def sans
  identifiers[1..-1]
end

#wait_order_for_completeObject



72
73
74
75
76
77
78
# File 'lib/acmesmith/ordering_service.rb', line 72

def wait_order_for_complete
  while %w(ready processing).include?(order.status)
    order.reload()
    puts " * Waiting for complete: status=#{order.status}"
    sleep 2
  end
end