Class: LetsEncrypt::Certificate
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- LetsEncrypt::Certificate
- Includes:
- CertificateIssuable, CertificateVerifiable
- Defined in:
- app/models/lets_encrypt/certificate.rb
Overview
Schema Information
Table name: letsencrypt_certificates
id :integer not null, primary key
domain :string(255)
certificate :text(65535)
intermediaries :text(65535)
key :text(65535)
expires_at :datetime
renew_after :datetime
verification_path :string(255)
verification_string :string(255)
created_at :datetime not null
updated_at :datetime not null
Indexes
index_letsencrypt_certificates_on_domain (domain)
index_letsencrypt_certificates_on_renew_after (renew_after)
Instance Method Summary collapse
-
#active? ⇒ Boolean
Returns false if certificate is not issued.
-
#bundle ⇒ Object
Returns full-chain bundled certificates.
- #certificate_object ⇒ Object
-
#delete_from_redis ⇒ Object
Delete certificate from redis.
-
#expired? ⇒ Boolean
Returns true if certificate is expired.
-
#get ⇒ Object
(also: #renew)
Returns true if success get a new certificate.
- #key_object ⇒ Object
-
#save_to_redis ⇒ Object
Save certificate into redis.
Methods included from CertificateIssuable
Methods included from CertificateVerifiable
Instance Method Details
#active? ⇒ Boolean
Returns false if certificate is not issued.
This method didn’t check certificate is valid, its only uses for checking is there has a certificate.
45 46 47 |
# File 'app/models/lets_encrypt/certificate.rb', line 45 def active? certificate.present? end |
#bundle ⇒ Object
Returns full-chain bundled certificates
64 65 66 |
# File 'app/models/lets_encrypt/certificate.rb', line 64 def bundle (certificate || '') + (intermediaries || '') end |
#certificate_object ⇒ Object
68 69 70 |
# File 'app/models/lets_encrypt/certificate.rb', line 68 def certificate_object @certificate_object ||= OpenSSL::X509::Certificate.new(certificate) end |
#delete_from_redis ⇒ Object
Delete certificate from redis
82 83 84 |
# File 'app/models/lets_encrypt/certificate.rb', line 82 def delete_from_redis LetsEncrypt::Redis.delete(self) end |
#expired? ⇒ Boolean
Returns true if certificate is expired.
50 51 52 |
# File 'app/models/lets_encrypt/certificate.rb', line 50 def expired? Time.zone.now >= expires_at end |
#get ⇒ Object Also known as: renew
Returns true if success get a new certificate
55 56 57 58 59 |
# File 'app/models/lets_encrypt/certificate.rb', line 55 def get ActiveSupport::Notifications.instrument('letsencrypt.issue', domain: domain) do verify && issue end end |
#key_object ⇒ Object
72 73 74 |
# File 'app/models/lets_encrypt/certificate.rb', line 72 def key_object @key_object ||= OpenSSL::PKey::RSA.new(key) end |
#save_to_redis ⇒ Object
Save certificate into redis
77 78 79 |
# File 'app/models/lets_encrypt/certificate.rb', line 77 def save_to_redis LetsEncrypt::Redis.save(self) end |