Module: Model::AcmeOrder
- Extended by:
- ActiveSupport::Concern
- Included in:
- Com::AcmeOrder
- Defined in:
- app/models/com/model/acme_order.rb
Instance Method Summary collapse
- #cert ⇒ Object
- #common_name ⇒ Object
- #csr ⇒ Object
-
#finalize ⇒ Object
status: valid.
- #get_cert(tries = 2) ⇒ Object
- #identifiers ⇒ Object
- #identifiers_string ⇒ Object
-
#order(renewal = false) ⇒ Object
status: pending.
- #renew_before_expired ⇒ Object
-
#renew_order ⇒ Object
x.
Instance Method Details
#cert ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/com/model/acme_order.rb', line 119 def cert r = order.certificate rescue Acme::Client::Error::BadNonce retry else file = Tempfile.new file.binmode file.write r file.rewind self.issued_at = Time.current self.status = order.status self.cert_key.attach io: file, filename: "#{identifiers_string}.pem" r end |
#common_name ⇒ Object
93 94 95 |
# File 'app/models/com/model/acme_order.rb', line 93 def common_name identifiers.first end |
#csr ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/models/com/model/acme_order.rb', line 97 def csr return @csr if defined? @csr @csr = Acme::Client::CertificateRequest.new(names: identifiers, subject: { common_name: common_name }) Tempfile.open do |file| file.binmode file.write @csr.private_key.to_pem file.rewind self.private_pem.attach io: file, filename: "#{identifiers_string}.key" end @csr end |
#finalize ⇒ Object
status: valid
110 111 112 113 114 115 116 117 |
# File 'app/models/com/model/acme_order.rb', line 110 def finalize order.finalize(csr: csr) rescue Acme::Client::Error::BadNonce retry ensure self.status = order.status self.save end |
#get_cert(tries = 2) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/com/model/acme_order.rb', line 67 def get_cert(tries = 2) case order.status when 'invalid' order(true) when 'pending' acme_identifiers.map(&:authorization) acme_identifiers.map(&:auto_verify).all?(true) && order.reload when 'ready' finalize when 'valid' cert # order.certificate_url.present? end rescue retry unless (tries -= 1).zero? end |
#identifiers ⇒ Object
83 84 85 |
# File 'app/models/com/model/acme_order.rb', line 83 def identifiers acme_identifiers.pluck(:identifier).sort end |
#identifiers_string ⇒ Object
87 88 89 90 91 |
# File 'app/models/com/model/acme_order.rb', line 87 def identifiers_string r = identifiers.first r = r.delete_prefix '*.' r.gsub('.', '_') end |
#order(renewal = false) ⇒ Object
status: pending
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/com/model/acme_order.rb', line 35 def order(renewal = false) if defined?(@order) && !renewal return @order end if !renewal && url begin @order = acme_account.client.order(url: url) rescue Acme::Client::Error::BadNonce retry rescue Acme::Client::Error::NotFound => e @order = renew_order end else @order = renew_order end @order end |
#renew_before_expired ⇒ Object
134 135 136 |
# File 'app/models/com/model/acme_order.rb', line 134 def renew_before_expired AcmeJob.set(wait_until: issued_at + 2.months).perform_later(self) end |
#renew_order ⇒ Object
x
56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/com/model/acme_order.rb', line 56 def renew_order r = acme_account.client.new_order(identifiers: identifiers) rescue Acme::Client::Error::BadNonce retry else self.orderid = r.to_h[:url].split('/')[-1] self.assign_attributes r.to_h.slice(:status, :url) self.save r end |