Class: Acmesmith::OrderingService
- Inherits:
-
Object
- Object
- Acmesmith::OrderingService
- Defined in:
- lib/acmesmith/ordering_service.rb
Defined Under Namespace
Classes: NotCompleted
Instance Attribute Summary collapse
-
#acme ⇒ Object
readonly
Returns the value of attribute acme.
-
#chain_preferences ⇒ Object
readonly
Returns the value of attribute chain_preferences.
-
#challenge_responder_rules ⇒ Object
readonly
Returns the value of attribute challenge_responder_rules.
-
#common_name ⇒ Object
readonly
Returns the value of attribute common_name.
-
#identifiers ⇒ Object
readonly
Returns the value of attribute identifiers.
-
#not_after ⇒ Object
readonly
Returns the value of attribute not_after.
-
#not_before ⇒ Object
readonly
Returns the value of attribute not_before.
-
#private_key ⇒ Object
readonly
Returns the value of attribute private_key.
Instance Method Summary collapse
- #certificate ⇒ Object
- #csr ⇒ Acme::Client::CertificateRequest
- #ensure_authorization ⇒ Object
- #finalize_order ⇒ Object
-
#initialize(acme:, common_name:, identifiers:, private_key:, challenge_responder_rules:, chain_preferences:, not_before: nil, not_after: nil) ⇒ OrderingService
constructor
A new instance of OrderingService.
-
#order ⇒ Object
Acme::Client::Resources::Order[].
-
#pem_chain ⇒ Object
String.
- #perform! ⇒ Object
- #sans ⇒ Array<String>
- #wait_order_for_complete ⇒ Object
Constructor Details
#initialize(acme:, common_name:, identifiers:, private_key:, challenge_responder_rules:, chain_preferences:, not_before: nil, not_after: nil) ⇒ OrderingService
Returns a new instance of OrderingService.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/acmesmith/ordering_service.rb', line 17 def initialize(acme:, common_name:, identifiers:, private_key:, challenge_responder_rules:, chain_preferences:, not_before: nil, not_after: nil) @acme = acme @common_name = common_name @identifiers = identifiers @private_key = private_key @challenge_responder_rules = challenge_responder_rules @chain_preferences = chain_preferences @not_before = not_before @not_after = not_after end |
Instance Attribute Details
#acme ⇒ Object (readonly)
Returns the value of attribute acme.
28 29 30 |
# File 'lib/acmesmith/ordering_service.rb', line 28 def acme @acme end |
#chain_preferences ⇒ Object (readonly)
Returns the value of attribute chain_preferences.
28 29 30 |
# File 'lib/acmesmith/ordering_service.rb', line 28 def chain_preferences @chain_preferences end |
#challenge_responder_rules ⇒ Object (readonly)
Returns the value of attribute challenge_responder_rules.
28 29 30 |
# File 'lib/acmesmith/ordering_service.rb', line 28 def challenge_responder_rules @challenge_responder_rules end |
#common_name ⇒ Object (readonly)
Returns the value of attribute common_name.
28 29 30 |
# File 'lib/acmesmith/ordering_service.rb', line 28 def common_name @common_name end |
#identifiers ⇒ Object (readonly)
Returns the value of attribute identifiers.
28 29 30 |
# File 'lib/acmesmith/ordering_service.rb', line 28 def identifiers @identifiers end |
#not_after ⇒ Object (readonly)
Returns the value of attribute not_after.
28 29 30 |
# File 'lib/acmesmith/ordering_service.rb', line 28 def not_after @not_after end |
#not_before ⇒ Object (readonly)
Returns the value of attribute not_before.
28 29 30 |
# File 'lib/acmesmith/ordering_service.rb', line 28 def not_before @not_before end |
#private_key ⇒ Object (readonly)
Returns the value of attribute private_key.
28 29 30 |
# File 'lib/acmesmith/ordering_service.rb', line 28 def private_key @private_key end |
Instance Method Details
#certificate ⇒ Object
93 94 95 |
# File 'lib/acmesmith/ordering_service.rb', line 93 def certificate @certificate or raise NotCompleted, "not completed yet" end |
#csr ⇒ Acme::Client::CertificateRequest
108 109 110 |
# File 'lib/acmesmith/ordering_service.rb', line 108 def csr @csr ||= Acme::Client::CertificateRequest.new(subject: { common_name: common_name }, names: sans, private_key: private_key) end |
#ensure_authorization ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/acmesmith/ordering_service.rb', line 55 def return if order..empty? || order.status == 'ready' puts "=> Looking for required domain authorizations" puts order..map(&:domain).each do |domain| puts " * #{domain}" end puts AuthorizationService.new(challenge_responder_rules, order.).perform! end |
#finalize_order ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/acmesmith/ordering_service.rb', line 67 def finalize_order puts puts "=> Finalizing the order" puts puts csr.csr.to_pem puts print " * Requesting..." order.finalize(csr: csr) puts" [ ok ]" end |
#order ⇒ Object
Returns Acme::Client::Resources::Order[].
98 99 100 |
# File 'lib/acmesmith/ordering_service.rb', line 98 def order @order or raise "BUG: order not yet generated" end |
#pem_chain ⇒ Object
Returns String.
88 89 90 91 |
# File 'lib/acmesmith/ordering_service.rb', line 88 def pem_chain url = order.certificate_url or raise NotCompleted, "not completed yet" CertificateRetrievingService.new(acme, common_name, url, chain_preferences: chain_preferences).pem_chain end |
#perform! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/acmesmith/ordering_service.rb', line 30 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}" () finalize_order() wait_order_for_complete() @certificate = Certificate.by_issuance(pem_chain, csr, name: common_name) puts puts "=> Certificate issued" nil end |
#sans ⇒ Array<String>
103 104 105 |
# File 'lib/acmesmith/ordering_service.rb', line 103 def sans identifiers[1..-1] end |
#wait_order_for_complete ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/acmesmith/ordering_service.rb', line 79 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 |