internetee-registry/db/migrate/20150525075550_update_certs_add_cn_from_csr.rb
Martin Lensment f6c7dd48db Typo fix
2015-05-25 11:04:53 +03:00

12 lines
331 B
Ruby

class UpdateCertsAddCnFromCsr < ActiveRecord::Migration
def change
Certificate.all.each do |x|
if x.crt.blank? && x.csr.present?
pc = x.parsed_csr.try(:subject).try(:to_s) || ''
cn = pc.scan(/\/CN=(.+)/).flatten.first
x.common_name = cn.split('/').first
end
x.save
end
end
end