Skip to content

Commit

Permalink
Merge a68cd9e into 1f079f6
Browse files Browse the repository at this point in the history
  • Loading branch information
telsaiori committed Oct 6, 2019
2 parents 1f079f6 + a68cd9e commit dc71740
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ LetsEncrypt.config do |config|
# The redis server url
# Default is nil
config.redis_url = 'redis://localhost:6379/1'

# Enable it if you want to customize the model
# Default is LetsEncrypt::Certificate
#config.certificate_model = 'MyCertificate'
end
```

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lets_encrypt/verifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def render_verification_string
end

def certificate
LetsEncrypt::Certificate.find_by(verification_path: filename)
LetsEncrypt.certificate_model.find_by(verification_path: filename)
end

def filename
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/lets_encrypt/renew_certificates_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RenewCertificatesJob < ApplicationJob
queue_as :default

def perform
LetsEncrypt::Certificate.renewable.each do |certificate|
LetsEncrypt.certificate_model.renewable.each do |certificate|
next if certificate.renew
certificate.update(renew_after: 1.day.from_now)
end
Expand Down
4 changes: 4 additions & 0 deletions lib/letsencrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,9 @@ def config(&block)
def table_name_prefix
'letsencrypt_'
end

def certificate_model
config.certificate_model.constantize
end
end
end
4 changes: 4 additions & 0 deletions lib/letsencrypt/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class Configuration
config_accessor :save_to_redis
config_accessor :redis_url

config_accessor :certificate_model do
'LetsEncrypt::Certificate'
end

# Returns true if enabled `save_to_redis` feature
def use_redis?
save_to_redis == true
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/letsencrypt_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace :letsencrypt do
task renew: :environment do
count = 0
failed = 0
LetsEncrypt::Certificate.renewable do |certificate|
LetsEncrypt.certificate_model.renewable do |certificate|
count += 1
next if certificate.renew
failed += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

RSpec.describe LetsEncrypt::VerificationsController, type: :controller do
routes { LetsEncrypt::Engine.routes }
class OtherModel < LetsEncrypt::Certificate
end
before(:each) do
LetsEncrypt.config.certificate_model = 'OtherModel'
end

it 'returns 404 status when no valid verification path found' do
open(:get, :show, verification_path: :invalid_path)
Expand All @@ -12,7 +17,7 @@

context 'has certificate' do
let!(:certificate) do
LetsEncrypt::Certificate.create(
LetsEncrypt.certificate_model.create(
domain: 'example.com',
verification_path: '.well-known/acme-challenge/valid_path',
verification_string: 'verification'
Expand Down

0 comments on commit dc71740

Please sign in to comment.