Rename primitive PublicKeyPrivateKey to PrivateKey
This commit is contained in:
parent
c35db37542
commit
a8d666a5f1
5 changed files with 21 additions and 22 deletions
|
@ -7,8 +7,7 @@ class Staffs::X509Certificates::PrivateKeysController < ApplicationController
|
||||||
|
|
||||||
# GET /staff/x509_certificates/:x509_certificate_id/private_key
|
# GET /staff/x509_certificates/:x509_certificate_id/private_key
|
||||||
def show
|
def show
|
||||||
authorize [:staff, X509Certificate,
|
authorize [:staff, X509Certificate, PrivateKey.new(@asymmetric_key)]
|
||||||
PublicKeyPrivateKey.new(@asymmetric_key)]
|
|
||||||
|
|
||||||
@asymmetric_key.decrypt_private_key_pem
|
@asymmetric_key.decrypt_private_key_pem
|
||||||
|
|
||||||
|
|
18
app/primitives/private_key.rb
Normal file
18
app/primitives/private_key.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class PrivateKey
|
||||||
|
attr_reader :asymmetric_key
|
||||||
|
|
||||||
|
def self.policy_class
|
||||||
|
'PrivateKeyPolicy'
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(asymmetric_key)
|
||||||
|
@asymmetric_key = asymmetric_key or raise
|
||||||
|
end
|
||||||
|
|
||||||
|
def exist?
|
||||||
|
asymmetric_key.private_key_pem_iv.present? &&
|
||||||
|
asymmetric_key.private_key_pem_ciphertext.present?
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,18 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class PublicKeyPrivateKey
|
|
||||||
attr_reader :public_key
|
|
||||||
|
|
||||||
def self.policy_class
|
|
||||||
'PrivateKeyPolicy'
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize(public_key)
|
|
||||||
@public_key = public_key or raise
|
|
||||||
end
|
|
||||||
|
|
||||||
def exist?
|
|
||||||
public_key.private_key_pem_iv.present? &&
|
|
||||||
public_key.private_key_pem_ciphertext.present?
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -69,7 +69,7 @@
|
||||||
<% if policy([
|
<% if policy([
|
||||||
:staff,
|
:staff,
|
||||||
X509Certificate,
|
X509Certificate,
|
||||||
PublicKeyPrivateKey.new(@x509_certificate.asymmetric_key),
|
PrivateKey.new(@x509_certificate.asymmetric_key),
|
||||||
]).show? %>
|
]).show? %>
|
||||||
|
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe PublicKeyPrivateKey, type: :model do
|
RSpec.describe PrivateKey, type: :model do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
end
|
end
|
Reference in a new issue