Skip to content

Add Mongoid Support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ appraise 'rails6' do
gem 'activemodel', '~> 6.1'
gem 'activerecord', '~> 6.1'
gem 'activesupport', '~> 6.1'
gem 'mongoid', '~> 8'
end

appraise 'rails7' do
@@ -18,4 +19,5 @@ appraise 'rails7' do
gem 'activemodel', '~> 7'
gem 'activerecord', '~> 7'
gem 'activesupport', '~> 7'
gem 'mongoid', '~> 8'
end
2 changes: 1 addition & 1 deletion app/controllers/lets_encrypt/verifications_controller.rb
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ def render_verification_string
end

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

def filename
19 changes: 14 additions & 5 deletions app/models/lets_encrypt/certificate.rb
Original file line number Diff line number Diff line change
@@ -22,17 +22,26 @@ module LetsEncrypt
# index_letsencrypt_certificates_on_domain (domain)
# index_letsencrypt_certificates_on_renew_after (renew_after)
#
class Certificate < ApplicationRecord
class Certificate
include Mongoid::Document
include Mongoid::Timestamps
include CertificateVerifiable
include CertificateIssuable

self.table_name = 'letsencrypt_certificates'
field :domain, type: String
field :certificate, type: String
field :intermediaries, type: String
field :key, type: String
field :expires_at, type: DateTime
field :renew_after, type: DateTime
field :verification_path, type: String
field :verification_string, type: String

validates :domain, presence: true, uniqueness: true

scope :active, -> { where('certificate IS NOT NULL AND expires_at > ?', Time.zone.now) }
scope :renewable, -> { where('renew_after IS NULL OR renew_after <= ?', Time.zone.now) }
scope :expired, -> { where('expires_at <= ?', Time.zone.now) }
scope :active, -> { where(:certificate.ne => nil, :expires_at.gt => Time.zone.now) }
scope :renewable, -> { self.or({ :renew_after => nil }, { :renew_after.lte => Time.zone.now }) }
scope :expired, -> { where(:expires_at.lte => Time.zone.now) }

before_create -> { self.key = OpenSSL::PKey::RSA.new(4096).to_s }
after_destroy -> { delete_from_redis }, if: -> { LetsEncrypt.config.use_redis? && active? }
1 change: 1 addition & 0 deletions gemfiles/rails6.gemfile
Original file line number Diff line number Diff line change
@@ -15,5 +15,6 @@ gem "actionview", "~> 6.1"
gem "activemodel", "~> 6.1"
gem "activerecord", "~> 6.1"
gem "activesupport", "~> 6.1"
gem "mongoid", "~> 8"

gemspec path: "../"
16 changes: 13 additions & 3 deletions gemfiles/rails6.gemfile.lock
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ PATH
activemodel (>= 6.1)
activerecord (>= 6.1)
activesupport (>= 6.1)
mongoid (>= 8)
railties (>= 6.1)
redis

@@ -58,6 +59,7 @@ GEM
thor (>= 0.14.0)
ast (2.4.2)
base64 (0.2.0)
bson (5.0.1)
builder (3.2.4)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
@@ -91,14 +93,21 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
net-imap (0.4.4)
mongo (2.20.1)
bson (>= 4.14.1, < 6.0.0)
mongoid (8.1.5)
activemodel (>= 5.1, < 7.2, != 7.0.0)
concurrent-ruby (>= 1.0.5, < 2.0)
mongo (>= 2.18.0, < 3.0.0)
ruby2_keywords (~> 0.0.5)
net-imap (0.4.16)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.4.0)
net-smtp (0.5.0)
net-protocol
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
@@ -205,6 +214,7 @@ DEPENDENCIES
activerecord (~> 6.1)
activesupport (~> 6.1)
appraisal
mongoid (~> 8)
rails-letsencrypt!
railties (~> 6.1)
rspec-rails
@@ -214,4 +224,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
2.4.13
2.3.18
1 change: 1 addition & 0 deletions gemfiles/rails7.gemfile
Original file line number Diff line number Diff line change
@@ -15,5 +15,6 @@ gem "actionview", "~> 7"
gem "activemodel", "~> 7"
gem "activerecord", "~> 7"
gem "activesupport", "~> 7"
gem "mongoid", "~> 8"

gemspec path: "../"
16 changes: 13 additions & 3 deletions gemfiles/rails7.gemfile.lock
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ PATH
activemodel (>= 6.1)
activerecord (>= 6.1)
activesupport (>= 6.1)
mongoid (>= 8)
railties (>= 6.1)
redis

@@ -70,6 +71,7 @@ GEM
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.6)
bson (5.0.1)
builder (3.2.4)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
@@ -108,15 +110,22 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.22.2)
mongo (2.20.1)
bson (>= 4.14.1, < 6.0.0)
mongoid (8.1.5)
activemodel (>= 5.1, < 7.2, != 7.0.0)
concurrent-ruby (>= 1.0.5, < 2.0)
mongo (>= 2.18.0, < 3.0.0)
ruby2_keywords (~> 0.0.5)
mutex_m (0.2.0)
net-imap (0.4.10)
net-imap (0.4.16)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.4.0.1)
net-smtp (0.5.0)
net-protocol
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
@@ -238,6 +247,7 @@ DEPENDENCIES
activerecord (~> 7)
activesupport (~> 7)
appraisal
mongoid (~> 8)
rails-letsencrypt!
railties (~> 7)
rspec-rails
@@ -247,4 +257,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
2.4.13
2.3.18
1 change: 1 addition & 0 deletions rails-letsencrypt.gemspec
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activemodel', '>= 6.1'
s.add_dependency 'activerecord', '>= 6.1'
s.add_dependency 'activesupport', '>= 6.1'
s.add_dependency 'mongoid', '>= 8'
s.add_dependency 'railties', '>= 6.1'
s.add_dependency 'redis'
s.metadata['rubygems_mfa_required'] = 'true'
1 change: 1 addition & 0 deletions spec/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
require_relative 'boot'

require 'rails/all'
require 'mongoid'

Bundler.require(*Rails.groups)
require 'rails-letsencrypt'
10 changes: 10 additions & 0 deletions spec/dummy/config/mongoid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test:
clients:
default:
database: rails_letsencrypt_test
hosts:
- localhost:27017
options:
read:
mode: :primary
max_pool_size: 1
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -39,6 +39,10 @@
end

RSpec.configure do |config|
config.before(:each) do
Mongoid.purge!
end

# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.