mirror of
https://github.com/internetee/registry.git
synced 2025-07-30 14:36:22 +02:00
feat: improve certificate download extensions
Update certificate download functionality to use appropriate file extensions: - Use .p12 extension for PKCS#12 files - Keep .pem extension for PEM-encoded files (CSR, CRT, private key) This change ensures that downloaded certificate files have the correct extension based on their format, making it easier for users to identify and use the files correctly.
This commit is contained in:
parent
51035d1ddf
commit
5355397025
15 changed files with 281 additions and 262 deletions
|
@ -8,16 +8,38 @@ module Serializers
|
|||
end
|
||||
|
||||
def to_json(obj = certificate)
|
||||
json = obj.as_json.except('csr', 'crt')
|
||||
json = obj.as_json.except('csr', 'crt', 'private_key', 'p12')
|
||||
csr = obj.parsed_csr
|
||||
crt = obj.parsed_crt
|
||||
p12 = obj.parsed_p12
|
||||
private_key = obj.parsed_private_key
|
||||
|
||||
json[:private_key] = private_key_data(private_key) if private_key
|
||||
json[:p12] = p12_data(obj) if obj.p12.present?
|
||||
json[:expires_at] = obj.expires_at if obj.expires_at.present?
|
||||
|
||||
json[:csr] = csr_data(csr) if csr
|
||||
json[:crt] = crt_data(crt) if crt
|
||||
|
||||
json
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def private_key_data(key)
|
||||
{
|
||||
body: key.to_pem,
|
||||
type: 'RSA PRIVATE KEY'
|
||||
}
|
||||
end
|
||||
|
||||
def p12_data(obj)
|
||||
{
|
||||
body: obj.p12,
|
||||
type: 'PKCS12'
|
||||
}
|
||||
end
|
||||
|
||||
def csr_data(csr)
|
||||
{
|
||||
version: csr.version,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue