Class: LeSsl::Manager
- Inherits:
-
Object
- Object
- LeSsl::Manager
- Defined in:
- lib/le_ssl/manager.rb
Constant Summary collapse
- PRODUCTION_ENDPOINT =
'https://acme-v01.api.letsencrypt.org/'- DEVELOPMENT_ENDPOINT =
'https://acme-staging.api.letsencrypt.org/'
Instance Method Summary collapse
- #authorize_for_domain(domain) ⇒ Object
-
#initialize(options = {}) ⇒ Manager
constructor
A new instance of Manager.
- #register(email) ⇒ Object
- #request_certificate(*domains) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Manager
Returns a new instance of Manager.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/le_ssl/manager.rb', line 6 def initialize(={}) email = [:email] || ENV['CERT_ACCOUNT_EMAIL'].presence raise LeSsl::NoContactEmailError if email.nil? raise LeSsl::TermsNotAcceptedError unless [:agree_terms] == true self.private_key = [:private_key].presence private_key # Check private key register(email) unless [:skip_register] == true end |
Instance Method Details
#authorize_for_domain(domain) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/le_ssl/manager.rb', line 19 def (domain) = client.(domain: domain) challenge = .http01 file_name = Rails.root.join('public', challenge.filename) dir = File.dirname(Rails.root.join('public', challenge.filename)) FileUtils.mkdir_p(dir) File.write(file_name, challenge.file_content) challenge.request_verification sleep(1) File.delete(file_name) if challenge.verify_status == 'invalid' return challenge.verify_status end |
#register(email) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/le_ssl/manager.rb', line 55 def register(email) client.register(contact: "mailto:#{email}").agree_terms return true rescue Acme::Client::Error::Malformed => e return false if e. == "Registration key is already in use" raise e end |
#request_certificate(*domains) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/le_ssl/manager.rb', line 39 def request_certificate(*domains) csr = Acme::Client::CertificateRequest.new(names: domains) certificate = client.new_certificate(csr) FileUtils.mkdir_p(Rails.root.join('config', 'ssl')) File.write(Rails.root.join('config', 'ssl', 'privkey.pem'), certificate.request.private_key.to_pem) File.write(Rails.root.join('config', 'ssl', 'cert.pem'), certificate.to_pem) File.write(Rails.root.join('config', 'ssl', 'chain.pem'), certificate.chain_to_pem) File.write(Rails.root.join('config', 'ssl', 'fullchain.pem'), certificate.fullchain_to_pem) return certificate rescue Acme::Client::Error::Unauthorized => e raise LeSsl::UnauthorizedError, e. end |