mirror of
https://github.com/internetee/registry.git
synced 2025-08-11 20:19:34 +02:00
Fixed codeclimate issue
This commit is contained in:
parent
a9ed98d994
commit
e00213ef1c
2 changed files with 36 additions and 32 deletions
|
@ -2,6 +2,7 @@ require 'open3'
|
||||||
|
|
||||||
class Certificate < ApplicationRecord
|
class Certificate < ApplicationRecord
|
||||||
include Versions
|
include Versions
|
||||||
|
include Certificate::CertificateConcern
|
||||||
|
|
||||||
belongs_to :api_user
|
belongs_to :api_user
|
||||||
|
|
||||||
|
@ -35,7 +36,6 @@ class Certificate < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
validate :assign_metadata, on: :create
|
validate :assign_metadata, on: :create
|
||||||
|
|
||||||
def assign_metadata
|
def assign_metadata
|
||||||
return if errors.any?
|
return if errors.any?
|
||||||
|
|
||||||
|
@ -44,14 +44,6 @@ class Certificate < ApplicationRecord
|
||||||
errors.add(:base, I18n.t(:invalid_csr_or_crt))
|
errors.add(:base, I18n.t(:invalid_csr_or_crt))
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_metadata(origin)
|
|
||||||
pc = origin.subject.to_s
|
|
||||||
cn = pc.scan(%r{\/CN=(.+)}).flatten.first
|
|
||||||
self.common_name = cn.split('/').first
|
|
||||||
self.md5 = OpenSSL::Digest::MD5.new(origin.to_der).to_s if crt
|
|
||||||
self.interface = crt ? API : REGISTRAR
|
|
||||||
end
|
|
||||||
|
|
||||||
def parsed_crt
|
def parsed_crt
|
||||||
@p_crt ||= OpenSSL::X509::Certificate.new(crt) if crt
|
@p_crt ||= OpenSSL::X509::Certificate.new(crt) if crt
|
||||||
end
|
end
|
||||||
|
@ -109,35 +101,20 @@ class Certificate < ApplicationRecord
|
||||||
handle_revocation_failure(err_output)
|
handle_revocation_failure(err_output)
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
|
||||||
def tostdout(message)
|
|
||||||
time = Time.zone.now.utc
|
|
||||||
$stdout << "#{time} - #{message}\n" unless Rails.env.test?
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_crl
|
|
||||||
tostdout('Running crlupdater')
|
|
||||||
system('/bin/bash', ENV['crl_updater_path'].to_s)
|
|
||||||
tostdout('Finished running crlupdater')
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse_md_from_string(crt)
|
|
||||||
return if crt.blank?
|
|
||||||
|
|
||||||
crt = crt.split(' ').join("\n")
|
|
||||||
crt.gsub!("-----BEGIN\nCERTIFICATE-----\n", "-----BEGIN CERTIFICATE-----\n")
|
|
||||||
crt.gsub!("\n-----END\nCERTIFICATE-----", "\n-----END CERTIFICATE-----")
|
|
||||||
cert = OpenSSL::X509::Certificate.new(crt)
|
|
||||||
OpenSSL::Digest::MD5.new(cert.to_der).to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def certificate_origin
|
def certificate_origin
|
||||||
crt ? parsed_crt : parsed_csr
|
crt ? parsed_crt : parsed_csr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_metadata(origin)
|
||||||
|
pc = origin.subject.to_s
|
||||||
|
cn = pc.scan(%r{\/CN=(.+)}).flatten.first
|
||||||
|
self.common_name = cn.split('/').first
|
||||||
|
self.md5 = OpenSSL::Digest::MD5.new(origin.to_der).to_s if crt
|
||||||
|
self.interface = crt ? API : REGISTRAR
|
||||||
|
end
|
||||||
|
|
||||||
def create_tempfile(filename, content = '')
|
def create_tempfile(filename, content = '')
|
||||||
tempfile = Tempfile.new(filename)
|
tempfile = Tempfile.new(filename)
|
||||||
tempfile.write(content)
|
tempfile.write(content)
|
||||||
|
|
27
app/models/concerns/certificate/certificate_concern.rb
Normal file
27
app/models/concerns/certificate/certificate_concern.rb
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# app/models/concerns/certificate_concern.rb
|
||||||
|
module Certificate::CertificateConcern
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
class_methods do
|
||||||
|
def tostdout(message)
|
||||||
|
time = Time.zone.now.utc
|
||||||
|
$stdout << "#{time} - #{message}\n" unless Rails.env.test?
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_crl
|
||||||
|
tostdout('Running crlupdater')
|
||||||
|
system('/bin/bash', ENV['crl_updater_path'].to_s)
|
||||||
|
tostdout('Finished running crlupdater')
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_md_from_string(crt)
|
||||||
|
return if crt.blank?
|
||||||
|
|
||||||
|
crt = crt.split(' ').join("\n")
|
||||||
|
crt.gsub!("-----BEGIN\nCERTIFICATE-----\n", "-----BEGIN CERTIFICATE-----\n")
|
||||||
|
crt.gsub!("\n-----END\nCERTIFICATE-----", "\n-----END CERTIFICATE-----")
|
||||||
|
cert = OpenSSL::X509::Certificate.new(crt)
|
||||||
|
OpenSSL::Digest::MD5.new(cert.to_der).to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue