Added endpoints for creating and downloading api user certificates

This commit is contained in:
Sergei Tsoganov 2023-06-28 15:48:40 +03:00
parent b558c80e83
commit 47b6a1b87a
18 changed files with 377 additions and 102 deletions

View file

@ -0,0 +1,43 @@
module Serializers
module Repp
class Certificate
attr_reader :certificate
def initialize(certificate)
@certificate = certificate
end
def to_json(obj = certificate)
json = obj.as_json.except('csr', 'crt')
csr = obj.parsed_csr
crt = obj.parsed_crt
json[:csr] = csr_data(csr) if csr
json[:crt] = crt_data(crt) if crt
json
end
private
def csr_data(csr)
{
version: csr.version,
subject: csr.subject.to_s,
alg: csr.signature_algorithm.to_s,
}
end
def crt_data(crt)
{
version: crt.version,
serial: crt.serial.to_s,
alg: crt.signature_algorithm.to_s,
issuer: crt.issuer.to_s,
not_before: crt.not_before,
not_after: crt.not_after,
subject: crt.subject.to_s,
extensions: crt.extensions.map(&:to_s),
}
end
end
end
end