mirror of
https://github.com/internetee/registry.git
synced 2025-07-31 06:56:23 +02:00
Added user certificate REPP endpoint and mailer
This commit is contained in:
parent
a63dc448c3
commit
b558c80e83
7 changed files with 84 additions and 0 deletions
51
app/controllers/repp/v1/certificates_controller.rb
Normal file
51
app/controllers/repp/v1/certificates_controller.rb
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
module Repp
|
||||||
|
module V1
|
||||||
|
class CertificatesController < BaseController
|
||||||
|
THROTTLED_ACTIONS = %i[create].freeze
|
||||||
|
include Shunter::Integration::Throttle
|
||||||
|
|
||||||
|
api :POST, '/repp/v1/certificates'
|
||||||
|
desc 'Submit a new api user certificate signing request'
|
||||||
|
def create
|
||||||
|
authorize! :create, Certificate
|
||||||
|
@api_user = current_user.registrar.api_users.find(cert_params[:api_user_id])
|
||||||
|
|
||||||
|
csr = decode_cert_params(cert_params[:csr])
|
||||||
|
|
||||||
|
@certificate = @api_user.certificates.build(csr: csr)
|
||||||
|
unless @certificate.save
|
||||||
|
handle_non_epp_errors(@certificate)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
notify_admins
|
||||||
|
render_success(data: { api_user: { id: @api_user.id } })
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def cert_params
|
||||||
|
params.require(:certificate).permit(:api_user_id, csr: %i[body type])
|
||||||
|
end
|
||||||
|
|
||||||
|
def decode_cert_params(csr_params)
|
||||||
|
return if csr_params.blank?
|
||||||
|
|
||||||
|
Base64.decode64(csr_params[:body])
|
||||||
|
end
|
||||||
|
|
||||||
|
def notify_admins
|
||||||
|
admin_users_emails = User.all.select { |u| u.roles.include? 'admin' }.pluck(:email)
|
||||||
|
|
||||||
|
return if admin_users_emails.empty?
|
||||||
|
|
||||||
|
admin_users_emails.each do |email|
|
||||||
|
CertificateMailer.new_certificate_signing_request(email: email,
|
||||||
|
api_user: @api_user,
|
||||||
|
csr: @certificate)
|
||||||
|
.deliver_now
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
8
app/mailers/certificate_mailer.rb
Normal file
8
app/mailers/certificate_mailer.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class CertificateMailer < ApplicationMailer
|
||||||
|
def new_certificate_signing_request(email:, api_user:, csr:)
|
||||||
|
@certificate = csr
|
||||||
|
@api_user = api_user
|
||||||
|
subject = 'New Certificate Signing Request Received'
|
||||||
|
mail(to: email, subject: subject)
|
||||||
|
end
|
||||||
|
end
|
|
@ -30,6 +30,7 @@ class Ability
|
||||||
billing
|
billing
|
||||||
can :manage, ApiUser
|
can :manage, ApiUser
|
||||||
can :manage, WhiteIp
|
can :manage, WhiteIp
|
||||||
|
can :create, Certificate
|
||||||
end
|
end
|
||||||
|
|
||||||
def epp # Registrar/api_user dynamic role
|
def epp # Registrar/api_user dynamic role
|
||||||
|
|
|
@ -36,6 +36,8 @@ class Certificate < ApplicationRecord
|
||||||
validate :assign_metadata, on: :create
|
validate :assign_metadata, on: :create
|
||||||
|
|
||||||
def assign_metadata
|
def assign_metadata
|
||||||
|
return if errors.any?
|
||||||
|
|
||||||
origin = crt ? parsed_crt : parsed_csr
|
origin = crt ? parsed_crt : parsed_csr
|
||||||
parse_metadata(origin)
|
parse_metadata(origin)
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<p>New certificate signing request (CSR) has been received. Please review the details below:</p>
|
||||||
|
|
||||||
|
<h3>CSR Details:</h3>
|
||||||
|
<ul>
|
||||||
|
<li>Subject: <%= link_to(@certificate.parsed_csr.try(:subject),
|
||||||
|
admin_api_user_certificate_url(@api_user, @certificate)) %></li>
|
||||||
|
<li>Requested By: <%= @certificate.creator_str %></li>
|
||||||
|
<li>Requested Date: <%= l(@certificate.created_at) %></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>Please take the necessary steps to process the certificate signing request.</p>
|
|
@ -0,0 +1,10 @@
|
||||||
|
New certificate signing request (CSR) has been received. Please review the details below:
|
||||||
|
|
||||||
|
CSR Details:
|
||||||
|
|
||||||
|
Subject: <%= link_to(@certificate.parsed_csr.try(:subject),
|
||||||
|
admin_api_user_certificate_url(@api_user, @certificate)) %>
|
||||||
|
Requested By: <%= @certificate.creator_str %>
|
||||||
|
Requested Date: <%= l(@certificate.created_at) %>
|
||||||
|
|
||||||
|
Please take the necessary steps to process the certificate signing request.
|
|
@ -110,6 +110,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
resources :api_users, only: %i[index show update create destroy]
|
resources :api_users, only: %i[index show update create destroy]
|
||||||
resources :white_ips, only: %i[index show update create destroy]
|
resources :white_ips, only: %i[index show update create destroy]
|
||||||
|
resources :certificates, only: %i[create]
|
||||||
namespace :registrar do
|
namespace :registrar do
|
||||||
resources :notifications, only: %i[index show update] do
|
resources :notifications, only: %i[index show update] do
|
||||||
collection do
|
collection do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue