1
0
Fork 0

Rename primitive PublicKeyPrivateKey to PrivateKey

This commit is contained in:
Alex Kotov 2019-09-13 23:58:30 +05:00
parent c35db37542
commit a8d666a5f1
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
5 changed files with 21 additions and 22 deletions

View File

@ -7,8 +7,7 @@ class Staffs::X509Certificates::PrivateKeysController < ApplicationController
# GET /staff/x509_certificates/:x509_certificate_id/private_key
def show
authorize [:staff, X509Certificate,
PublicKeyPrivateKey.new(@asymmetric_key)]
authorize [:staff, X509Certificate, PrivateKey.new(@asymmetric_key)]
@asymmetric_key.decrypt_private_key_pem

View 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

View File

@ -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

View File

@ -69,7 +69,7 @@
<% if policy([
:staff,
X509Certificate,
PublicKeyPrivateKey.new(@x509_certificate.asymmetric_key),
PrivateKey.new(@x509_certificate.asymmetric_key),
]).show? %>
<div class="alert alert-warning" role="alert">

View File

@ -2,6 +2,6 @@
require 'rails_helper'
RSpec.describe PublicKeyPrivateKey, type: :model do
RSpec.describe PrivateKey, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end