From 864195980e18bf2e0311222d7d150b41818c108d Mon Sep 17 00:00:00 2001 From: robcolbert Date: Thu, 4 Jul 2019 16:25:06 -0400 Subject: [PATCH] generates RSA key pairs for migrated accounts --- lib/tasks/fix_key_pairs.rake | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/tasks/fix_key_pairs.rake diff --git a/lib/tasks/fix_key_pairs.rake b/lib/tasks/fix_key_pairs.rake new file mode 100644 index 00000000..fa72b67a --- /dev/null +++ b/lib/tasks/fix_key_pairs.rake @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +task fix_key_pairs: 'gabsocial:fix_key_pairs' + +namespace :gabsocial do + desc 'Generates key pairs for migrated accounts' + task :fix_key_pairs => :environment do + Account.select(:id, :username, :private_key, :public_key).all.each do |a| + if a.public_key == "tobefilled" + keypair = OpenSSL::PKey::RSA.new(2048) + private_key = keypair.to_pem + public_key = keypair.public_key.to_pem + a.update_columns private_key: private_key, public_key: public_key + end + end + end +end