From d8ab710f10410f93bda6ed866ec4f0e9cd1f9b38 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Mon, 25 May 2015 11:00:56 +0300 Subject: [PATCH] Take CN from CSRs as well --- .../20150525075550_update_certs_add_cn_from_csr.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/migrate/20150525075550_update_certs_add_cn_from_csr.rb diff --git a/db/migrate/20150525075550_update_certs_add_cn_from_csr.rb b/db/migrate/20150525075550_update_certs_add_cn_from_csr.rb new file mode 100644 index 000000000..505d475b9 --- /dev/null +++ b/db/migrate/20150525075550_update_certs_add_cn_from_csr.rb @@ -0,0 +1,12 @@ +class UpdateCertsAddCnFromCsr < ActiveRecord::Migration + def change + Certificate.all.each do |x| + if x.crt.blank? && x.csr.present? + pc = x.parsed_crt.try(:subject).try(:to_s) || '' + cn = pc.scan(/\/CN=(.+)/).flatten.first + x.common_name = cn.split('/').first + end + x.save + end + end +end