-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added user certificate REPP endpoint and mailer
- Loading branch information
Sergei Tsoganov
authored and
Sergei Tsoganov
committed
Jun 8, 2023
1 parent
61c7b59
commit 0e9808d
Showing
7 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/views/mailers/certificate_mailer/new_certificate_signing_request.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
10 changes: 10 additions & 0 deletions
10
app/views/mailers/certificate_mailer/new_certificate_signing_request.text.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters