Skip to content

Commit

Permalink
Add rubocop and correct warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Nov 7, 2023
1 parent 974b187 commit 0c35f8c
Show file tree
Hide file tree
Showing 30 changed files with 244 additions and 242 deletions.
23 changes: 14 additions & 9 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
inherit_from: .rubocop_todo.yml
require:
- rubocop-rails

AllCops:
DisplayCopNames: true
TargetRubyVersion: 2.4
Include:
- Rakefile
- lib/**/*.rake
TargetRubyVersion: 2.7
SuggestExtensions: false
NewCops: enable
Exclude:
- Gemfile
- Appraisals
- rails-letsencrypt.gemspec
- lib/generators/lets_encrypt/templates/migration.rb
- gemfiles/*
- spec/dummy/**/*
- lib/generators/lets_encrypt/templates/*

Rails:
Enabled: true

Naming/FileName:
Exclude:
- lib/rails-letsencrypt.rb

Metrics/BlockLength:
Exclude:
- spec/**/*.rb
61 changes: 0 additions & 61 deletions .rubocop_todo.yml

This file was deleted.

28 changes: 14 additions & 14 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# frozen_string_literal: true

appraise 'rails6' do
gem "railties", "~> 6.1"
gem "actionmailer", "~> 6.1"
gem "actionpack", "~> 6.1"
gem "actionview", "~> 6.1"
gem "activemodel", "~> 6.1"
gem "activerecord", "~> 6.1"
gem "activesupport", "~> 6.1"
gem 'railties', '~> 6.1'
gem 'actionmailer', '~> 6.1'
gem 'actionpack', '~> 6.1'
gem 'actionview', '~> 6.1'
gem 'activemodel', '~> 6.1'
gem 'activerecord', '~> 6.1'
gem 'activesupport', '~> 6.1'
end

appraise 'rails7' do
gem "railties", "~> 7"
gem "actionmailer", "~> 7"
gem "actionpack", "~> 7"
gem "actionview", "~> 7"
gem "activemodel", "~> 7"
gem "activerecord", "~> 7"
gem "activesupport", "~> 7"
gem 'railties', '~> 7'
gem 'actionmailer', '~> 7'
gem 'actionpack', '~> 7'
gem 'actionview', '~> 7'
gem 'activemodel', '~> 7'
gem 'activerecord', '~> 7'
gem 'activesupport', '~> 7'
end
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Declare your gem's dependencies in lets_encrypt.gemspec.
Expand All @@ -13,4 +14,9 @@ gemspec

# To use a debugger
# gem 'byebug', group: [:development, :test]
gem 'appraisal'
gem 'rspec-rails'
gem 'rubocop', '~> 1.57.2'
gem 'rubocop-rails'
gem 'simplecov', '~> 0.16.1'
gem 'sqlite3'
3 changes: 2 additions & 1 deletion app/controllers/lets_encrypt/verifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module LetsEncrypt
class VerificationsController < ApplicationController
def show
return render_verification_string if certificate.present?
render plain: 'Verification not found', status: 404

render plain: 'Verification not found', status: :not_found
end

protected
Expand Down
1 change: 1 addition & 0 deletions app/jobs/lets_encrypt/renew_certificates_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class RenewCertificatesJob < ApplicationJob
def perform
LetsEncrypt.certificate_model.renewable.each do |certificate|
next if certificate.renew

certificate.update(renew_after: 1.day.from_now)
end
end
Expand Down
8 changes: 5 additions & 3 deletions app/models/concerns/lets_encrypt/certificate_issuable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ module CertificateIssuable
def issue
logger.info "Getting certificate for #{domain}"
create_certificate
# rubocop:disable Metrics/LineLength
logger.info "Certificate issued for #{domain} (expires on #{expires_at}, will renew after #{renew_after})"
# rubocop:enable Metrics/LineLength
true
end

Expand All @@ -30,12 +28,16 @@ def create_certificate
order.finalize(csr: csr)
sleep 1 while order.status == 'processing'
fullchain = order.certificate.split("\n\n")
assign_new_certificate(fullchain)
save!
end

def assign_new_certificate(fullchain)
cert = OpenSSL::X509::Certificate.new(fullchain.shift)
self.certificate = cert.to_pem
self.intermediaries = fullchain.join("\n\n")
self.expires_at = cert.not_after
self.renew_after = (expires_at - 1.month) + rand(10).days
save!
end
end
end
6 changes: 3 additions & 3 deletions app/models/concerns/lets_encrypt/certificate_verifiable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ def check_verify_status
true
end

def retry_on_verify_error(e)
def retry_on_verify_error(error)
@retries ||= 0
if e.is_a?(Acme::Client::Error::BadNonce) && @retries < 5
if error.is_a?(Acme::Client::Error::BadNonce) && @retries < 5
@retries += 1
logger.info "#{domain}: Bad nounce encountered. Retrying (#{@retries} of 5 attempts)"
sleep 1
verify
else
logger.info "#{domain}: Error: #{e.class} (#{e.message})"
return false
false
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/lets_encrypt/certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module LetsEncrypt
# index_letsencrypt_certificates_on_domain (domain)
# index_letsencrypt_certificates_on_renew_after (renew_after)
#
class Certificate < ActiveRecord::Base
class Certificate < ApplicationRecord
include CertificateVerifiable
include CertificateIssuable

Expand All @@ -33,8 +33,8 @@ class Certificate < ActiveRecord::Base
scope :expired, -> { where('expires_at <= ?', Time.zone.now) }

before_create -> { self.key = OpenSSL::PKey::RSA.new(4096).to_s }
after_save -> { save_to_redis }, if: -> { LetsEncrypt.config.use_redis? && active? }
after_destroy -> { delete_from_redis }, if: -> { LetsEncrypt.config.use_redis? && active? }
after_save -> { save_to_redis }, if: -> { LetsEncrypt.config.use_redis? && active? }

# Returns false if certificate is not issued.
#
Expand Down
6 changes: 3 additions & 3 deletions bin/rails
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/letsencrypt/engine', __FILE__)
ENGINE_ROOT = File.expand_path('..', __dir__)
ENGINE_PATH = File.expand_path('../lib/letsencrypt/engine', __dir__)

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])

require 'rails/all'
Expand Down
5 changes: 5 additions & 0 deletions gemfiles/rails6.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

source "https://rubygems.org"

gem "appraisal"
gem "rspec-rails"
gem "rubocop", "~> 1.57.2"
gem "rubocop-rails"
gem "simplecov", "~> 0.16.1"
gem "sqlite3"
gem "railties", "~> 6.1"
gem "actionmailer", "~> 6.1"
Expand Down
45 changes: 34 additions & 11 deletions gemfiles/rails6.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ GEM
bundler
rake
thor (>= 0.14.0)
base64 (0.1.1)
ast (2.4.2)
base64 (0.2.0)
builder (3.2.4)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.3)
date (3.3.4)
diff-lcs (1.5.0)
docile (1.4.0)
erubi (1.12.0)
Expand All @@ -77,6 +78,7 @@ GEM
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
loofah (2.21.4)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -87,24 +89,24 @@ GEM
net-smtp
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
net-imap (0.4.4)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
net-protocol (0.2.2)
timeout
net-smtp (0.4.0)
net-protocol
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
racc (1.7.3)
rack (2.2.8)
rack-test (2.1.0)
Expand All @@ -122,11 +124,14 @@ GEM
method_source
rake (>= 12.2)
thor (~> 1.0)
rainbow (3.1.1)
rake (13.1.0)
redis (5.0.8)
redis-client (>= 0.17.0)
redis-client (0.18.0)
connection_pool
regexp_parser (2.8.2)
rexml (3.2.6)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
Expand All @@ -144,24 +149,40 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-rails (2.22.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
sqlite3 (1.6.8)
mini_portile2 (~> 2.8.0)
sqlite3 (1.6.8-x86_64-darwin)
sqlite3 (1.6.8-x86_64-linux)
thor (1.3.0)
timeout (0.4.0)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
zeitwerk (2.6.12)

PLATFORMS
ruby
x86_64-darwin-22
x86_64-linux

Expand All @@ -176,6 +197,8 @@ DEPENDENCIES
rails-letsencrypt!
railties (~> 6.1)
rspec-rails
rubocop (~> 1.57.2)
rubocop-rails
simplecov (~> 0.16.1)
sqlite3

Expand Down
5 changes: 5 additions & 0 deletions gemfiles/rails7.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

source "https://rubygems.org"

gem "appraisal"
gem "rspec-rails"
gem "rubocop", "~> 1.57.2"
gem "rubocop-rails"
gem "simplecov", "~> 0.16.1"
gem "sqlite3"
gem "railties", "~> 7"
gem "actionmailer", "~> 7"
Expand Down
Loading

0 comments on commit 0c35f8c

Please sign in to comment.