mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Revert back to CSR / CRT upload
This commit is contained in:
parent
8292951c9c
commit
0aa5399265
12 changed files with 214 additions and 103 deletions
|
@ -1,19 +1,21 @@
|
|||
class Admin::CertificatesController < AdminController
|
||||
load_and_authorize_resource
|
||||
before_action :set_api_user, only: [:new, :show, :destroy, :edit, :update]
|
||||
before_action :set_certificate, :set_api_user, only: [:sign, :show, :download_csr, :download_crt, :revoke, :destroy]
|
||||
|
||||
def show; end
|
||||
|
||||
def edit; end
|
||||
|
||||
def new
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
@certificate = Certificate.new(api_user: @api_user)
|
||||
end
|
||||
|
||||
def create
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
|
||||
@certificate = @api_user.certificates.build(certificate_params)
|
||||
crt = certificate_params[:crt].open.read if certificate_params[:crt]
|
||||
csr = certificate_params[:csr].open.read if certificate_params[:csr]
|
||||
|
||||
@certificate = @api_user.certificates.build(csr: csr, crt: crt)
|
||||
if @api_user.save
|
||||
flash[:notice] = I18n.t('record_created')
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
|
@ -23,16 +25,6 @@ class Admin::CertificatesController < AdminController
|
|||
end
|
||||
end
|
||||
|
||||
def update
|
||||
if @certificate.update(certificate_params)
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @certificate.destroy
|
||||
flash[:notice] = I18n.t('record_deleted')
|
||||
|
@ -43,48 +35,50 @@ class Admin::CertificatesController < AdminController
|
|||
end
|
||||
end
|
||||
|
||||
# DEPRECATED FOR NOW
|
||||
# def sign
|
||||
# if @certificate.sign!
|
||||
# flash[:notice] = I18n.t('record_updated')
|
||||
# redirect_to [:admin, @api_user, @certificate]
|
||||
# else
|
||||
# flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
# render 'show'
|
||||
# end
|
||||
# end
|
||||
def sign
|
||||
if @certificate.sign!
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
else
|
||||
flash.now[:alert] = I18n.t('failed_to_update_record')
|
||||
render 'show'
|
||||
end
|
||||
end
|
||||
|
||||
# def revoke
|
||||
# if @certificate.revoke!
|
||||
# flash[:notice] = I18n.t('record_updated')
|
||||
# else
|
||||
# flash[:alert] = I18n.t('failed_to_update_record')
|
||||
# end
|
||||
# redirect_to [:admin, @api_user, @certificate]
|
||||
# end
|
||||
def revoke
|
||||
if @certificate.revoke!
|
||||
flash[:notice] = I18n.t('record_updated')
|
||||
else
|
||||
flash[:alert] = I18n.t('failed_to_update_record')
|
||||
end
|
||||
redirect_to [:admin, @api_user, @certificate]
|
||||
end
|
||||
|
||||
# def download_csr
|
||||
# send_data @certificate.csr, filename: "#{@api_user.username}.csr.pem"
|
||||
# end
|
||||
def download_csr
|
||||
send_data @certificate.csr, filename: "#{@api_user.username}.csr.pem"
|
||||
end
|
||||
|
||||
# def download_crt
|
||||
# send_data @certificate.crt, filename: "#{@api_user.username}.crt.pem"
|
||||
# end
|
||||
def download_crt
|
||||
send_data @certificate.crt, filename: "#{@api_user.username}.crt.pem"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# DEPRECATED FOR NOW
|
||||
# def set_certificate
|
||||
# @certificate = Certificate.find(params[:id])
|
||||
# @csr = OpenSSL::X509::Request.new(@certificate.csr) if @certificate.csr
|
||||
# @crt = OpenSSL::X509::Certificate.new(@certificate.crt) if @certificate.crt
|
||||
# end
|
||||
def set_certificate
|
||||
@certificate = Certificate.find(params[:id])
|
||||
@csr = OpenSSL::X509::Request.new(@certificate.csr) if @certificate.csr
|
||||
@crt = OpenSSL::X509::Certificate.new(@certificate.crt) if @certificate.crt
|
||||
end
|
||||
|
||||
def set_api_user
|
||||
@api_user = ApiUser.find(params[:api_user_id])
|
||||
end
|
||||
|
||||
def certificate_params
|
||||
params.require(:certificate).permit(:common_name, :md5, :interface)
|
||||
if params[:certificate]
|
||||
params.require(:certificate).permit(:crt, :csr)
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue