mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 09:43:36 +02:00
Better error handling
This commit is contained in:
parent
03267f90c7
commit
f4f77fefc7
2 changed files with 16 additions and 5 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
require 'open3'
|
||||||
|
|
||||||
# rubocop: disable Metrics/ClassLength
|
# rubocop: disable Metrics/ClassLength
|
||||||
class ApiUser < ActiveRecord::Base
|
class ApiUser < ActiveRecord::Base
|
||||||
include Versions # version/api_user_version.rb
|
include Versions # version/api_user_version.rb
|
||||||
|
@ -30,13 +32,21 @@ class ApiUser < ActiveRecord::Base
|
||||||
csr_file.rewind
|
csr_file.rewind
|
||||||
|
|
||||||
crt_file = Tempfile.new('client_crt')
|
crt_file = Tempfile.new('client_crt')
|
||||||
|
_out, err, _st = Open3.capture3("openssl ca -keyfile #{APP_CONFIG['ca_key_path']} \
|
||||||
`openssl ca -keyfile #{APP_CONFIG['ca_key_path']} -cert #{APP_CONFIG['ca_cert_path']} \
|
-cert #{APP_CONFIG['ca_cert_path']} \
|
||||||
-extensions usr_cert -notext -md sha256 \
|
-extensions usr_cert -notext -md sha256 \
|
||||||
-in #{csr_file.path} -out #{crt_file.path} -key '#{APP_CONFIG['ca_key_password']}' -batch`
|
-in #{csr_file.path} -out #{crt_file.path} -key '#{APP_CONFIG['ca_key_password']}' -batch")
|
||||||
|
|
||||||
|
if err.present?
|
||||||
|
errors.add(:base, I18n.t('failed_to_create_certificate'))
|
||||||
|
logger.error('FAILED TO CREATE CLIENT CERTIFICATE')
|
||||||
|
logger.error(err)
|
||||||
|
return false
|
||||||
|
else
|
||||||
crt_file.rewind
|
crt_file.rewind
|
||||||
self.crt = crt_file.read
|
self.crt = crt_file.read
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# rubocop: enable Metrics/ClassLength
|
# rubocop: enable Metrics/ClassLength
|
||||||
|
|
|
@ -500,3 +500,4 @@ en:
|
||||||
contact_email: 'Contact e-mail'
|
contact_email: 'Contact e-mail'
|
||||||
address_help: 'Street name, house no - apartment no, city, county, country, zip'
|
address_help: 'Street name, house no - apartment no, city, county, country, zip'
|
||||||
download: 'Download'
|
download: 'Download'
|
||||||
|
failed_to_create_certificate: 'Failed to create certificate!'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue