mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Get rid of old code
This commit is contained in:
parent
1b60853bc8
commit
c3560fd19f
3 changed files with 4 additions and 40 deletions
|
@ -12,10 +12,7 @@ class Admin::ApiUsersController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
app = api_user_params
|
@api_user = ApiUser.new(api_user_params)
|
||||||
app[:csr] = params[:api_user][:csr].open.read if params[:api_user][:csr]
|
|
||||||
|
|
||||||
@api_user = ApiUser.new(app)
|
|
||||||
|
|
||||||
if @api_user.save
|
if @api_user.save
|
||||||
flash[:notice] = I18n.t('record_created')
|
flash[:notice] = I18n.t('record_created')
|
||||||
|
@ -31,10 +28,7 @@ class Admin::ApiUsersController < AdminController
|
||||||
def edit; end
|
def edit; end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
app = api_user_params
|
if @api_user.update(api_user_params)
|
||||||
app[:csr] = params[:api_user][:csr].open.read if params[:api_user][:csr]
|
|
||||||
|
|
||||||
if @api_user.update(app)
|
|
||||||
flash[:notice] = I18n.t('record_updated')
|
flash[:notice] = I18n.t('record_updated')
|
||||||
redirect_to [:admin, @api_user]
|
redirect_to [:admin, @api_user]
|
||||||
else
|
else
|
||||||
|
@ -60,6 +54,6 @@ class Admin::ApiUsersController < AdminController
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_user_params
|
def api_user_params
|
||||||
params.require(:api_user).permit(:username, :password, :csr, :active, :registrar_id, :registrar_typeahead)
|
params.require(:api_user).permit(:username, :password, :active, :registrar_id, :registrar_typeahead)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,8 +10,6 @@ class ApiUser < User
|
||||||
validates :username, :password, :registrar, presence: true
|
validates :username, :password, :registrar, presence: true
|
||||||
validates :username, uniqueness: true
|
validates :username, uniqueness: true
|
||||||
|
|
||||||
before_save :create_crt, if: -> (au) { au.csr_changed? }
|
|
||||||
|
|
||||||
attr_accessor :registrar_typeahead
|
attr_accessor :registrar_typeahead
|
||||||
|
|
||||||
def ability
|
def ability
|
||||||
|
@ -30,28 +28,5 @@ class ApiUser < User
|
||||||
def queued_messages
|
def queued_messages
|
||||||
registrar.messages.queued
|
registrar.messages.queued
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_crt
|
|
||||||
csr_file = Tempfile.new('client_csr')
|
|
||||||
csr_file.write(csr)
|
|
||||||
csr_file.rewind
|
|
||||||
|
|
||||||
crt_file = Tempfile.new('client_crt')
|
|
||||||
_out, err, _st = Open3.capture3("openssl ca -keyfile #{APP_CONFIG['ca_key_path']} \
|
|
||||||
-cert #{APP_CONFIG['ca_cert_path']} \
|
|
||||||
-extensions usr_cert -notext -md sha256 \
|
|
||||||
-in #{csr_file.path} -out #{crt_file.path} -key '#{APP_CONFIG['ca_key_password']}' -batch")
|
|
||||||
|
|
||||||
if err.match(/Data Base Updated/)
|
|
||||||
crt_file.rewind
|
|
||||||
self.crt = crt_file.read
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
errors.add(:base, I18n.t('failed_to_create_certificate'))
|
|
||||||
logger.error('FAILED TO CREATE CLIENT CERTIFICATE')
|
|
||||||
logger.error(err)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
# rubocop: enable Metrics/ClassLength
|
# rubocop: enable Metrics/ClassLength
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
%hr
|
%hr
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-12
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :username
|
= f.label :username
|
||||||
= f.text_field(:username, class: 'form-control')
|
= f.text_field(:username, class: 'form-control')
|
||||||
|
@ -26,11 +26,6 @@
|
||||||
%label{for: 'api_user_active'}
|
%label{for: 'api_user_active'}
|
||||||
= f.check_box(:active)
|
= f.check_box(:active)
|
||||||
= t('active')
|
= t('active')
|
||||||
|
|
||||||
.col-md-6.text-left
|
|
||||||
.form-group
|
|
||||||
= f.label :csr, t('certificate_signing_req')
|
|
||||||
= f.file_field :csr
|
|
||||||
%hr
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-12.text-right
|
.col-md-12.text-right
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue